Deploy a Minimal MCP Server on AWS Lambda — Fast & Serverless
Written by Om-Shree-0709 on .
- Deploying MCP on AWS Lambda: A Minimal Serverless Guide
- Why AWS Lambda for MCP
- AWS MCP Architecture
- Project Structure
- MCP Logic (app.py)
- Dependencies (requirements.txt)
- AWS SAM Deployment Template (template.yaml)
- Deploying to AWS
- Testing the Endpoint
- Final Thoughts
- Acknowledgements
- References
- References
Deploying MCP on AWS Lambda: A Minimal Serverless Guide
If you have been experimenting with MCP (Model Context Protocol) locally and want to take it to the cloud, this guide explains how to deploy a minimal MCP server using AWS Lambda and Python. This setup allows for real-world tool hosting without managing dedicated infrastructure.1
Why AWS Lambda for MCP
Deploying your MCP server on AWS Lambda offers several advantages:
Scalable: Automatically handles incoming requests.
Cost-efficient: Pay only for usage.
Secure: Integrates with IAM and AWS authorization.
Interoperable: Easy integration with S3, DynamoDB, and other AWS services.1
AWS MCP Architecture
Project Structure
mcp-lambda-server/
├── app.py # MCP logic and tools
├── requirements.txt # Python dependencies
├── template.yaml # AWS SAM deployment config
└── event.json # Sample test input (optional)MCP Logic (app.py)
from aws_lambda_powertools.utilities.typing import LambdaContext
from mcp import MCPServer, tool
import json
server = MCPServer()
@tool
def hello_mcp(name: str) -> str:
return f"Hello, {name}! Welcome to your MCP Lambda server."
@tool
def add_numbers(a: int, b: int) -> int:
return a + b
@tool
def roll_dice() -> int:
import random
return random.randint(1, 6)
def lambda_handler(event: dict, context: LambdaContext) -> dict:
return server(event)Dependencies (requirements.txt)
aws-lambda-powertools
mcpInstall dependencies:
pip install -r requirements.txtAWS SAM Deployment Template (template.yaml)
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Minimal MCP Server on AWS Lambda
Resources:
MCPFunction:
Type: AWS::Serverless::Function
Properties:
Handler: app.lambda_handler
Runtime: python3.11
CodeUri: .
Timeout: 10
MemorySize: 128
Policies: AWSLambdaBasicExecutionRole
Events:
MCPAPI:
Type: Api
Properties:
Path: /mcp
Method: postDeploying to AWS
Install the AWS SAM CLI3 and run the following:
sam build
sam deploy --guidedThis setup provisions:
A Lambda function
An HTTP endpoint (via API Gateway)
IAM roles and security settings
Testing the Endpoint
Once deployed, test the endpoint using curl:
curl -X POST https://<your-api-id>.execute-api.<region>.amazonaws.com/mcp \
-H "Content-Type: application/json" \
-d '{"tool": "hello_mcp", "args": {"name": "User"}}'Expected Response:
{
"output": "Hello, User! Welcome to your MCP Lambda server."
}You may replace the tool name with add_numbers or roll_dice for additional tests.
Final Thoughts
With this setup, you now have a minimal, functional MCP server that:
Operates serverlessly on AWS
Automatically scales with demand
Is ready to integrate with LLMs, agents, and real-world data sources
Next steps may include:
Adding custom tools (search, weather APIs, etc.)
Connecting to LangChain or OpenAgents
Integrating real-time external data sources
Acknowledgements
This guide is based on Antje Barth’s insightful talk at the MCP Summit12, where she demonstrated how to deploy and scale MCP servers using AWS serverless technologies.
Special thanks to the AWS team and the broader MCP developer community for their continued efforts in making these tools available, scalable, and developer-friendly.
References
References
Written by Om-Shree-0709 (@Om-Shree-0709)