Skip to main content

AWS Lambda MCP Server: A serverless HTTP handler for the Model Context Protocol (MCP) using AWS Lambda.

Project description

MCP Lambda Handler Module

A Python library for creating serverless HTTP handlers for the Model Context Protocol (MCP) using AWS Lambda. This library provides a minimal, extensible framework for building MCP HTTP endpoints with pluggable session management support.

Features

  • 🚀 Easy serverless MCP HTTP handler creation using AWS Lambda
  • 🔌 Pluggable session management system (NoOp or DynamoDB, or custom backends)

Quick Start

  1. Install the package with development dependencies:
pip install -e .[dev]
  1. Use the handler in your AWS Lambda function:

Basic Usage

from awslabs.mcp_lambda_handler import MCPLambdaHandler

mcp = MCPLambdaHandler(name="mcp-lambda-server", version="1.0.0")

@mcp.tool()
def add_two_numbers(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b

def lambda_handler(event, context):
    """AWS Lambda handler function."""
    return mcp.handle_request(event, context)

Session Management

The library provides flexible session management with built-in support for DynamoDB and the ability to create custom session backends. You can use the default stateless (NoOp) session store, or configure a DynamoDB-backed store for persistent sessions.

Example Architecture for Auth & Session Management

A typical serverless deployment using this library might look like:

  • API Gateway: Exposes the /mcp endpoint.
  • Lambda Authorizer: Validates authentication tokens (e.g., bearer tokens in the Authorization header).
  • MCP Server Lambda: Implements MCP tools and session logic using this library.
  • DynamoDB: Stores session data (if using the DynamoDB session backend).

Development

  1. Clone the repository:
git clone https://github.com/awslabs/mcp.git
cd mcp/src/mcp-lambda-handler
  1. Install development dependencies:
pip install -e .[dev]
  1. Run tests:
pytest

Contributing

Contributions are welcome! Please see the CONTRIBUTING.md in the monorepo root for guidelines.

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

Python Version Support

  • Python 3.10+

Dependencies

Core dependencies:

  • python-dateutil >= 2.8.2

Optional dependencies:

  • boto3 >= 1.38.1 (for AWS/DynamoDB support)
  • botocore >= 1.38.1 (for AWS/DynamoDB support)

Development dependencies:

  • pytest >= 8.0.0
  • black >= 24.2.0
  • isort >= 5.13.0
  • flake8 >= 7.0.0
  • moto >= 5.0.3 (for AWS mocking in tests)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

awslabs_mcp_lambda_handler-0.1.13.tar.gz (69.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

awslabs_mcp_lambda_handler-0.1.13-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file awslabs_mcp_lambda_handler-0.1.13.tar.gz.

File metadata

File hashes

Hashes for awslabs_mcp_lambda_handler-0.1.13.tar.gz
Algorithm Hash digest
SHA256 56e2471541732a360ad47b3a8ded3bc0a71595a74398208113d51a1db4b8cddc
MD5 d32b8853d21c54a474be0f6617941ab4
BLAKE2b-256 015ea3e0ea65e1436cb5e264377216e0cf94f57f649e245d9f736a87d33d7ff1

See more details on using hashes here.

Provenance

The following attestation bundles were made for awslabs_mcp_lambda_handler-0.1.13.tar.gz:

Publisher: release.yml on awslabs/mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file awslabs_mcp_lambda_handler-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for awslabs_mcp_lambda_handler-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 834ff53f4eb2386ebf41a41fe34c9ac3a9262e5013b3bf67c8d7cff73000f2d4
MD5 87d9502b25d663a1ee2337a5f096fa4b
BLAKE2b-256 29ee9a579bd78ada8217920d1b399b546337887fd299ffcc4b685249fc11f00c

See more details on using hashes here.

Provenance

The following attestation bundles were made for awslabs_mcp_lambda_handler-0.1.13-py3-none-any.whl:

Publisher: release.yml on awslabs/mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page