gao-dennis/aws-lambda-mcp-server
If you are the rightful owner of aws-lambda-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project demonstrates the deployment of a stateless MCP server on AWS Lambda using Python, leveraging AWS API Gateway for HTTP endpoints and serverless execution.
Stateless MCP on AWS Lambda (Python)
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.
Prerequisites
- 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
Project Structure
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
Configuration
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)
Deployment Steps
-
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.
Testing
- 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 Commands
make layer
: Creates the Lambda layer with MCP dependenciesmake apigw
: Deploys the API Gateway and Lambda function
Troubleshooting
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