middy
Middy middleware for Model Context Protocol server hosting on AWS Lambda
claude mcp add --transport stdio fredericbarthelet-middy-mcp npx -y middy-mcp \ --env MCP_HOST="Host for MCP server (if applicable)" \ --env MCP_PORT="Port to run MCP server on (if applicable)"
How to use
Middy MCP provides a convenient way to expose an MCP server inside AWS Lambda functions by leveraging the Middy middleware framework. The middleware handles Model Context Protocol (MCP) requests and responses, enabling Lambda-backed functions to serve MCP clients over API Gateway (REST API v1 and HTTP API v2) via proxy integrations, as well as through ALB. This approach lets you implement MCP tooling without managing a separate server process and keeps your Lambda handler clean by wrapping MCP logic in a Middy middleware chain. You can extend the server with custom tools, as shown in the example where a simple add tool is registered and invoked through MCP requests.
To use it, install the middy-mcp package in your Lambda project, create an MCP server instance, register any tools you need, and attach the mcp middleware to your Middy handler. Deploy the Lambda behind API Gateway (or ALB) as a proxy integration and you're ready to respond to MCP requests from MCP clients. Remember that this hosting approach is compatible with MCP clients using protocol version 2025-03-26 or newer.
Example usage involves creating a server, defining a tool, and wiring the middleware into your Lambda handler, so requests arriving from API Gateway or ALB are processed by your MCP server logic inside the Lambda context.
How to install
Prerequisites:
- Node.js v18.0.0 or newer
- npm, pnpm, or yarn as your package manager
- Install the package in your Lambda project:
pnpm add middy-mcp
or using npm
npm install middy-mcp
2) (Optional) If you plan to run this as a local test or via a script, ensure your environment is set up to invoke the MCP middleware within a Middy-enabled Lambda handler.
3) Ensure your Lambda deployment includes Middy (and its peer dependencies) as part of your package.json.
4) Deploy the Lambda behind API Gateway (REST API v1 or HTTP API v2) using the proxy integration, or behind an Application Load Balancer (ALB) as appropriate for your use case.
Additional notes
Tips and notes:
- The middleware is designed to work in conjunction with @middy/http-error-handler for convenient HTTP error responses.
- It supports API Gateway REST API (v1) and HTTP API (v2) via proxy integration, as well as ALB triggers.
- The MCP server in this setup runs inside a Lambda function; you are effectively hosting an MCP server in a serverless environment rather than a long-running process.
- Ensure you are using MCP protocol version 2025-03-26 or newer on clients interacting with your Lambda-hosted MCP endpoint.
- If you customize tools, you can define input schemas with zod (as shown in the example) to validate and coerce incoming MCP requests.
- Monitor Lambda cold starts and optimize initialization by keeping server setup lightweight and cached between invocations where possible.
Related MCP Servers
iterm
A Model Context Protocol server that executes commands in the current iTerm session - useful for REPL and CLI assistance
mcp
Octopus Deploy Official MCP Server
furi
CLI & API for MCP management
editor
MCP Server for Phaser Editor
DoorDash
MCP server from JordanDalton/DoorDash-MCP-Server
mcp
MCP сервер для автоматического создания и развертывания приложений в Timeweb Cloud