Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

serverless-mcp-server

MCP.Pizza Chef: eleva

serverless-mcp-server is a lightweight Model Context Protocol (MCP) server deployed as a single AWS Lambda function and exposed through Amazon API Gateway. It offers a minimal setup using the @modelcontextprotocol/sdk, supports local development with serverless-offline, and includes a simple example tool with JSON-RPC interaction. This server enables scalable, serverless MCP integration for real-time model context handling in cloud environments.

Use This MCP server To

Deploy scalable MCP servers without managing infrastructure Expose MCP endpoints via HTTP POST on AWS API Gateway Develop and test MCP servers locally with serverless-offline Integrate simple JSON-RPC tools within MCP server workflows Host MCP servers with minimal configuration using Serverless Framework

README

🧠 serverless-mcp-server

A super simple Model Context Protocol (MCP) server deployed on AWS Lambda and exposed via Amazon API Gateway, deployed with Serverless Framework. This skeleton is based on the awesome work of FrΓ©dΓ©ric Barthelet: which has developed a middy middleware for Model Context Protocol (MCP) server integration with AWS Lambda functions in this repo

Long story

πŸ“–Read the full article here on dev.to

πŸ›  Features

  • πŸͺ„ Minimal MCP server setup using @modelcontextprotocol/sdk
  • πŸš€ Deployed as a single AWS Lambda function
  • 🌐 HTTP POST endpoint exposed via API Gateway at /mcp
  • πŸ”„ Supports local development via serverless-offline
  • πŸ§ͺ Includes a simple example tool (add) with JSON-RPC interaction

πŸ“¦ Project Structure

serverless-mcp-server/
β”œβ”€β”€ src/                    # Source code
β”‚   └── index.js                # MCP server handler
β”œβ”€β”€ .gitignore              # Git ignore file
β”œβ”€β”€ package.json            # Project dependencies
β”œβ”€β”€ package-lock.json       # Project lock file
β”œβ”€β”€ README.md               # This documentation file
└── serverless.yml          # Serverless Framework config

πŸ›  Prerequisites

πŸš€ Getting Started

  1. Install dependencies:
npm install
  1. Install open source severless globally (if not already installed):
npm install -g osls
  1. Run Locally with serverless-offline
npm sls offline

Local endpoint will be available at: POST http://localhost:3000/dev/mcp

Note that the /dev/ stage is added by default when using serverless-offline, reflecting Api Gateway V1 (REST API) behavior.

Switch to Api Gateway V2 (HTTP API)

If you want to use API Gateway V2, you can change the serverless.yml file to use httpApi instead of http in the events section. This will allow you to use HTTP APIs instead of REST APIs. This will allow you to use HTTP APIs instead of REST APIs.

functions:
  mcpServer:
    handler: src/index.handler
    events:
      - httpApi:
          path: mcp
          method: post

Local endpoint will be available at: POST http://localhost:3000/mcp

Note that the /dev/ stage is not needed when using API Gateway V2. Note you should change test curl and postman requests accordingly.

πŸ§ͺ Test with curl requests

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
    }
  }
}'

πŸ§ͺ Test with jest

There are some basic tests included in the __tests__ folder. You can run them with:

npm run test

🧬 Code Breakdown

This code is based on the awesome work of FrΓ©dΓ©ric Barthelet: which has developed a middy middleware for Model Context Protocol (MCP) server integration with AWS Lambda functions in this repo

src/index.js

import middy from "@middy/core";
import httpErrorHandler from "@middy/http-error-handler";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import mcpMiddleware from "middy-mcp";

const server = new McpServer({
  name: "Lambda hosted MCP Server",
  version: "1.0.0",
});

server.tool("add", { a: z.number(), b: z.number() }, async ({ a, b }) => ({
  content: [{ type: "text", text: String(a + b) }],
}));

export const handler = middy()
  .use(mcpMiddleware({ server }))
  .use(httpErrorHandler());

πŸ“‘ Deploy to AWS

Just run:

sls deploy

After deployment, the MCP server will be live at the URL output by the command.

πŸ”– Quotes

This repository has been quoted in the following newsletters:

πŸ“˜ License

MIT β€” feel free to fork, tweak, and deploy your own version!

serverless-mcp-server FAQ

How do I deploy the serverless-mcp-server?
Use the Serverless Framework to deploy the MCP server as an AWS Lambda function with API Gateway.
Can I run the serverless-mcp-server locally?
Yes, it supports local development using the serverless-offline plugin for testing before deployment.
What protocol does serverless-mcp-server support for communication?
It supports JSON-RPC interaction for tool calls within the MCP framework.
Is the serverless-mcp-server scalable?
Yes, it leverages AWS Lambda's serverless architecture to scale automatically with demand.
What SDK does serverless-mcp-server use?
It uses the @modelcontextprotocol/sdk for minimal MCP server setup.
Can I add custom tools to the serverless-mcp-server?
Yes, you can extend it by adding custom JSON-RPC tools to handle specific MCP interactions.
What cloud services are required to run serverless-mcp-server?
AWS Lambda and Amazon API Gateway are required to host and expose the MCP server endpoint.
Does serverless-mcp-server support multiple MCP clients?
Yes, it can handle requests from multiple MCP clients via its HTTP endpoint.