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
- Install the package with development dependencies:
pip install -e .[dev]
- 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
/mcpendpoint. - Lambda Authorizer: Validates authentication tokens (e.g., bearer tokens in the
Authorizationheader). - MCP Server Lambda: Implements MCP tools and session logic using this library.
- DynamoDB: Stores session data (if using the DynamoDB session backend).
Development
- Clone the repository:
git clone https://github.com/awslabs/mcp.git
cd mcp/src/mcp-lambda-handler
- Install development dependencies:
pip install -e .[dev]
- 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)
Release files for awslabs.mcp-lambda-handler 0.1.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| awslabs_mcp_lambda_handler-0.1.15.tar.gz | 80.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| awslabs_mcp_lambda_handler-0.1.15-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 98.6 kB
Release files / awslabs_mcp_lambda_handler-0.1.15.tar.gz
| Download URL | awslabs_mcp_lambda_handler-0.1.15.tar.gz |
|---|---|
| Size | 80.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0edc8c9b0ee7561b4a4d220ac517446f3b2a264557d84dca97a9cc2796f93d2e
|
|
BLAKE2b-256 checksum How to use checksums |
a639cb6bf49f47ab7b80e68b036c611ad895a6cb8fffaf274f9ccebd6d1035ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.
Transparency logRelease files / awslabs_mcp_lambda_handler-0.1.15-py3-none-any.whl
| Download URL | awslabs_mcp_lambda_handler-0.1.15-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
279f60378b65f6966cc86df84a1b46c30f6ab73a60b7723ea3df0e2f46cc802d
|
|
BLAKE2b-256 checksum How to use checksums |
3441548660e8468a3ec82cc14f4b1067d083be0f4ffca960fd9b245d4801abad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.
Transparency log