This project demonstrates how to deploy a stateless MCP (Message Control Protocol) server on AWS Lambda using Python. The implementation uses AWS API Gateway for HTTP endpoints and AWS Lambda for serverless execution.
- AWS CLI configured with appropriate credentials
- Python 3.x
- Make
- AWS SAM CLI
- Docker Desktop or Podman for local builds
- MCP Inspector tool for testing
stateless-mcp-on-lambda-python/
├── build/ # Build artifacts
├── etc/ # Configuration files
├── sam/ # SAM template files
├── src/ # Source code
├── tmp/ # Temporary files
└── makefile # Build and deployment commands
Before deploying, you need to configure the environment variables in etc/environment.sh
:
-
AWS Configuration:
PROFILE
: Your AWS CLI profile nameBUCKET
: S3 bucket name for deployment artifactsREGION
: AWS region (default: us-east-1)
-
MCP Dependencies:
P_DESCRIPTION
: MCP package version (default: "mcp==1.8.0")O_LAYER_ARN
: This will be updated after creating the Lambda layer
-
API Gateway and Lambda Configuration:
P_API_STAGE
: API Gateway stage name (default: dev)P_FN_MEMORY
: Lambda function memory in MB (default: 128)P_FN_TIMEOUT
: Lambda function timeout in seconds (default: 15)
-
Create the Lambda Layer:
make layer
After execution, copy the
outLayer
value and update theO_LAYER_ARN
inetc/environment.sh
. -
Deploy the API Gateway and Lambda function:
make apigw
This will create the API Gateway and Lambda function, which will have the MCP dependencies layer attached.
- After deployment, you'll receive an
outApiEndpoint
value. - Use the MCP Inspector tool to test the endpoint:
- Enter the following URL in MCP Inspector:
${outApiEndpoint}/echo/mcp/
- Enter the following URL in MCP Inspector:
make layer
: Creates the Lambda layer with MCP dependenciesmake apigw
: Deploys the API Gateway and Lambda function
If you encounter any issues:
- Ensure all environment variables are properly set in
etc/environment.sh
- Verify AWS credentials are correctly configured
- Check AWS CloudWatch logs for Lambda function errors
- Ensure the S3 bucket specified in
BUCKET
exists and is accessible