Skip to main content

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)

Metadata

Release files for awslabs.mcp-lambda-handler 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for awslabs.mcp-lambda-handler 0.1.2
File Size Uploaded Provenance Actions
awslabs_mcp_lambda_handler-0.1.2.tar.gz 61.2 kB With provenance Details for awslabs_mcp_lambda_handler-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for awslabs.mcp-lambda-handler 0.1.2
File Interpreter ABI Platform Actions
awslabs_mcp_lambda_handler-0.1.2-py3-none-any.whl Python 3 none any Details for awslabs_mcp_lambda_handler-0.1.2-py3-none-any.whl

Total release size: 75.5 kB

Release files / awslabs_mcp_lambda_handler-0.1.2.tar.gz

Download URL awslabs_mcp_lambda_handler-0.1.2.tar.gz
Size 61.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e05947f99cefd62609922aee1b1882da7b5f95f0d5ac0cb3a538fbe243d48acb
BLAKE2b-256 checksum
How to use checksums
eb5abf1a09449fdd4c93a44d9697cb5a40fca319fc18bad1872a173c9d15b9fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 May 23, 2025.

Transparency log

Release files / awslabs_mcp_lambda_handler-0.1.2-py3-none-any.whl

Download URL awslabs_mcp_lambda_handler-0.1.2-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3153f4d0ef1f27f5350e3946c82bfbd36480a2af57283760e6e0cc403c477aa1
BLAKE2b-256 checksum
How to use checksums
bf472eea323db1bd6f8199412d21609943b98c0b3756d7d7e9c9748891a730d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 May 23, 2025.

Transparency log

Security for awslabs.mcp-lambda-handler 0.1.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for awslabs_mcp_lambda_handler-0.1.2.tar.gz

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 May 23, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page