Hey devs 👋, after recent MCP's protocol update (26/03/2025) introducing stateless HTTP request/response transport, I’ve been exploring ways to host a Model Context Protocol (MCP)
server using AWS Lambda
, and I thought I'd share the result with the community.
This article is for anyone curious about deploying an MCP-compatible serverless endpoint
: whether you're just starting out with AWS or already using it and Serverless Framework
for other projects.
Here’s the GitHub repo if you want to dive in right away: 👉 serverless-mcp-server
🧩 What’s this about?
This project is a minimal implementation of an MCP server running entirely on AWS Lambda
, exposed via API Gateway
(V1 REST endpoints), and managed with Serverless Framework
.
It’s based on the awesome work from Frédéric Barthelet, who created middy-mcp, a convenient middleware, that makes developing MCP server with Lambda easy as pie. This middleware is based on middy, a middleware engine for AWS Lambda you should definitely know.
My goal is to give you a skeleton to spin up an MCP server that you can test locally and deploy easily in production, all in a few commands (that should be familiar if you are familiar with Node.js projects).
🛠️ Features
- Simple MCP server with just a few lines of code
- Runs in a single AWS Lambda function
- HTTP POST endpoint at /mcp
- Local development support with
serverless-offline
- Comes with a basic “add” tool (yeps, just adds two numbers via JSON-RPC: here you should put your endpoint logic!)
🧑💻 Quickstart
Let’s get it running locally first.
You should have Node installed (you may also use nvm or docker).
- Install dependencies:
npm install
- Install open source severless globally (if you haven't already installed):
npm install -g osls
- Run Locally with
serverless-offline
sls offline
🎉 Great! You’ll now have a local endpoint at:
POST
http://localhost:3000/dev/mcp
🧪 Try it Out (with curl)
List tools
curl --location 'http://localhost:3000/dev/mcp' \
--header 'content-type: application/json' \
--header 'accept: application/json' \
--header 'jsonrpc: 2.0' \
--data '{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 1
}'
➕ Use the add Tool
curl --location 'http://localhost:3000/dev/mcp' \
--header 'content-type: application/json' \
--header 'accept: application/json' \
--header 'jsonrpc: 2.0' \
--data '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {
"a": 5,
"b": 3
}
}
}'
You should get a response with the sum (8)
🧪 Test (with Jest)
There are some basic tests included in the __tests__
folder. You can run them with:
npm run test
🚀 Deploy to AWS
Once you’re happy with it locally, deploy to AWS with:
sls deploy
You should configure AWS credentials.
Serverless Framework
will handle the creation of the Lambda, API Gateway, and all the necessary wiring.
After deploy, you’ll get a live HTTP endpoint where you can run the same curl calls.
⚡ Serverless file
Required serverless file to deploy our serverless-mcp-server is very simple. We just use latest stable of Node on AWS Lambda nodejs22.x
and create a POST
endpoint on path /mcp
. That's all folks!
Be aware: you shouldn't go in production with this minimal setup! You should secure your api with best practices for authorization and security! If you are not familiar with those, please read this blog post
service: serverless-mcp-server
frameworkVersion: "3"
provider:
name: aws
runtime: nodejs22.x
timeout: 30
plugins:
- serverless-offline
functions:
mcpServer:
handler: src/index.handler
events:
- http:
path: mcp
method: post
🧵 Final Thoughts
I built this mainly as a starting point for experimenting with MCP in serverless environment, see the awesome work of Frédéric Barthelet in action and I hope it helps some of you do the same!
If you have ideas for improvements, feel free to open an issue or PR. Also, I’d love to hear what you're building with MCP and serverless.
⏭️ Next Step
I'm planning to continue this series giving an example with SAM and CDK. Let me know if this is needed by you in the comments!
🙋 Who am I
I'm D. De Sio and I work as a Head of Software Engineering in Eleva.
I'm currently (Apr 2025) an AWS Certified Solution Architect Professional and AWS Certified DevOps Engineer Professional, but also a User Group Leader (in Pavia), an AWS Community Builder and, last but not least, a #serverless enthusiast.
My work in this field is to advocate about serverless and help as more dev teams to adopt it, as well as customers break their monolith into API and micro-services using it.