Skip to main content
Glama

Deploy a Minimal MCP Server on AWS Lambda — Fast & Serverless

Written by on .

mcp

  1. Deploying MCP on AWS Lambda: A Minimal Serverless Guide
    1. Why AWS Lambda for MCP
      1. AWS MCP Architecture
        1. Project Structure
          1. MCP Logic (app.py)
            1. Dependencies (requirements.txt)
              1. AWS SAM Deployment Template (template.yaml)
                1. Deploying to AWS
                  1. Testing the Endpoint
                    1. Final Thoughts
                      1. Acknowledgements
                        1. References
                          1. 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

                            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 mcp

                            Install dependencies:

                            pip install -r requirements.txt

                            AWS 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: post

                            Deploying to AWS

                            Install the AWS SAM CLI2 and run the following:

                            sam build sam deploy --guided

                            This 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 Summit13, 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

                            Footnotes

                            1. MCP Summit Talk by Antje Barth – "Deploying and Scaling MCP with AWS Serverless Tools" 2 3

                            2. AWS SAM CLI Documentation – Deploying Serverless Applications

                            3. Antje Barth – LinkedIn

                            Written by Om-Shree-0709 (@Om-Shree-0709)