DEV Community

Davide De Sio for AWS Community Builders

Posted on • Edited on

24 1 2

⚡ Deploy a minimal MCP Server on AWS Lambda with Serverless Framework ⚡

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).

  1. Install dependencies:
npm install
Enter fullscreen mode Exit fullscreen mode
  1. Install open source severless globally (if you haven't already installed):
npm install -g osls
Enter fullscreen mode Exit fullscreen mode
  1. Run Locally with serverless-offline
sls offline
Enter fullscreen mode Exit fullscreen mode

🎉 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
}'
Enter fullscreen mode Exit fullscreen mode

➕ 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
    }
  }
}'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

🚀 Deploy to AWS

Once you’re happy with it locally, deploy to AWS with:

sls deploy
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

🧵 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.

Heroku

Tired of jumping between terminals, dashboards, and code?

Check out this demo showcasing how tools like Cursor can connect to Heroku through the MCP, letting you trigger actions like deployments, scaling, or provisioning—all without leaving your editor.

Learn More

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

[Workshop] Building and Monitoring AI Agents and MCP servers

Building with AI is different. Sentry has built some tools to help. In this workshop, you’ll learn how to monitor your agents, debug your MCP servers and how to debug with Seer.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️