Starting a production grade Serverless MCP can be overwhelming. You need to figure out many questions and challenges that have nothing to do with your business domain:
This project aims to reduce cognitive load and answer these questions for you by providing a skeleton Python Serverless service blueprint that implements best practices for AWS Lambda, Serverless CI/CD, and AWS CDK in one blueprint project.
This project is a blueprint for new Serverless MCP servers.
It provides two implementation options:
Choose the architecture that you see fit, each with its own pros and cons.
Option 1: Serverless Native Lambda MCP Server¶This project provides a working, open source based, AWS Lambda based Python MCP server implementation.
The MCP server uses JSON RPC over HTTP (non streamable) via API Gateway's body payload parameter. See integration tests and see how the test event is generated.
It contains an advanced implementation including IaC CDK code and a CI/CD pipeline, testing, observability and more (see Features section).
It's started based on AWS sample for MCP - but had major refactors since, combined with the AWS Lambda Handler cookbook template.
Better fitted for POCs or tool oriented MCPs. Can be secured with custom authentication code and WAF.
Option 2: Serverless Lambda Web Adapter & FastMCP¶Based on AWS Web Adapter and FastMCP.
Use an HTTP API GW and Lambda function. Can be used with a REST API GW with a custom domain too.
Better fitted for production-grade MCP servers as it upholds to the official MCP protocol and has native auth mechanism (OAuth).
Monitoring Design¶ Features¶The GitHub blueprint project can be found at https://github.com/ran-isenberg/aws-lambda-mcp-cookbook.
Serverless Best Practices¶The AWS Lambda handler will implement multiple best practice utilities.
Each utility is implemented when a new blog post is published about that utility.
The utilities cover multiple aspects of a production-ready service, including:
While the code examples are written in Python, the principles are valid to any supported AWS Lambda handler programming language.
Security¶For pure Lambda:
For FastMCP:
Pure Lambda:
service/handlers/mcp.py1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
from aws_lambda_env_modeler import init_environment_variables
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.metrics import MetricUnit
from aws_lambda_powertools.utilities.typing import LambdaContext
from service.handlers.models.env_vars import McpHandlerEnvVars
from service.handlers.utils.authentication import authenticate
from service.handlers.utils.mcp import mcp
from service.handlers.utils.observability import logger, metrics, tracer
from service.logic.tools.math import add_two_numbers
@mcp.tool()
def math(a: int, b: int) -> int:
"""Add two numbers together"""
# Uncomment the following line if you want to use session data
# session_data: Optional[SessionData] = mcp.get_session()
# call logic layer
result = add_two_numbers(a, b)
# save session data
mcp.set_session(data={'result': result})
metrics.add_metric(name='ValidMcpEvents', unit=MetricUnit.Count, value=1)
return result
@init_environment_variables(model=McpHandlerEnvVars)
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
@metrics.log_metrics
@tracer.capture_lambda_handler(capture_response=False)
def lambda_handler(event: dict, context: LambdaContext) -> dict:
authenticate(event, context)
return mcp.handle_request(event, context)
Handler is found at service/handlers/mcp.py
MCP engine found at service/mcp_lambda_handler folder
FastMCP Lambda:
service/mcp_server.py1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
from fastmcp import FastMCP
from service.handlers.utils.observability import logger
from service.logic.prompts.hld import hld_prompt
from service.logic.resources.profiles import get_profile_by_id
from service.logic.tools.math import add_two_numbers
mcp: FastMCP = FastMCP(name='mcp-lambda-server')
@mcp.tool
def math(a: int, b: int) -> int:
"""Add two numbers together"""
logger.info('using math tool', extra={'a': a, 'b': b})
return add_two_numbers(a, b)
# Dynamic resource template
@mcp.resource('users://{user_id}/profile')
def get_profile(user_id: int) -> dict[str, str]:
"""Fetch user profile by user ID."""
logger.info('fetching user profile', extra={'user_id': user_id})
return get_profile_by_id(user_id)
@mcp.prompt()
def generate_serverless_design_prompt(design_requirements: str) -> str:
"""Generate a serverless design prompt based on the provided design requirements."""
logger.info('generating serverless design prompt', extra={'design_requirements': design_requirements})
return hld_prompt(design_requirements)
app = mcp.http_app(transport='http', stateless_http=True, json_response=True)
Handler is found at service/mcp_server.py
License¶This library is licensed under the MIT License. See the LICENSE file.
2025-07-18RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4