Skip to content

Lambda MCP Server

Creates a simple MCP tool server with "streaming" HTTP.

Install

$pip install awslabs.mcp_lambda_handler

Install command taken from the project's README or registry entry. Always review code before running it.

Lambda MCP Server Demo (Streamable HTTP)

⚠️ IMPORTANT: The Lambda MCP Server module code IS maintained, just not in this repository. It is now hosted and maintained at awslabs/mcp-lambda-handler. This repository remains as sample code of how to use the module.

To use the Lambda MCP Server, install the package directly from PyPI:

pip install awslabs.mcp_lambda_handler
# or, if using uv:
uv add awslabs.mcp_lambda_handler

This server requires a client that supports Streamable HTTP (not SSE). There are a few MCP clients that currently support Streamable HTTP including the MCP Inspector. There is also as a Streamable HTTP client included in this repo, built Strands Agents.

This project demonstrates a powerful and developer-friendly way to create serverless MCP (Model Context Protocol) tools using AWS Lambda. It showcases how to build a stateless, serverless MCP server with minimal boilerplate and an excellent developer experience.

the_context()

In an episode of the_context, Tiffany Souterre and Mike discussed streamable HTTP for MCP as well as running (an older version of) this project:

Example

Here is the minimal code to get an MCP server running in an AWS Lambda function:

from awslabs.mcp_lambda_handler import MCPLambdaHandler

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

@mcp_server.tool()
def get_time() -> str:
    from datetime import datetime, UTC
    return datetime.now(UTC).isoformat()

def lambda_handler(event, context):
    return mcp_server.handle_request(event, context)

Session State Management

The Lambda MCP Server includes built-in session state management that persists across tool invocations within the same conversation. This is particularly useful for tools that need to maintain context or share data between calls.

Session data is stored in a DynamoDB table against a sessionId key. This is all managed for you.

Here's an example of how to use session state:

from lambda_mcp.lambda_mcp import LambdaMCPServer

session_table = os.environ.get('MCP_SESSION_TABLE', 'mcp_sessions')

mcp_server = LambdaMCPServer(name="mcp-lambda-server", version="1.0.0", session_store=session_table)

@mcp_server.tool()
def increment_counter() -> int:
    """Increment a session-based counter."""
    # Get the current counter value from session state, default to 0 if not set
    counter = mcp_server.session.get('counter', 0)
    
    # Increment the counter
    counter += 1
    
    # Store the new value in session state
    mcp_server.session['counter'] = counter
    
    return counter

@mcp_server.tool()
def get_counter() -> int:
    """Get the current counter value."""
    return mcp_server.session.get('counter', 0)

The session state is automatically managed per conversation and persists across multiple tool invocations. This allows you to maintain stateful information without needing additional external storage, while still keeping your Lambda function stateless.

Authentication

Similar plugs

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

Java 面试 & 后端通用面试指南,覆盖计算机基础、数据库、分布式、高并发、系统设计与 AI 应用开发

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype…

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io