mcpField
🧠
🧠 sam-serverless-mcp-server

🧠 sam-serverless-mcp-server

Local
github.com/elevaCloud & Infra1Updated 79w ago

About 🧠 sam-serverless-mcp-server

A starter MCP server project deployed as an AWS Lambda function and exposed through Amazon API Gateway using AWS SAM. It is for developers building or locally testing an HTTP-based server, and includes a basic addition tool example.

Key features

  1. 01Minimal MCP server setup with the SDK
  2. 02Single AWS Lambda deployment
  3. 03HTTP POST endpoint at /mcp
  4. 04Local development with SAM
  5. 05Example add tool and JSON-RPC interaction
  6. 06Jest tests

Use cases

  1. 01Build a serverless MCP endpoint on AWS
  2. 02Test MCP requests locally with SAM
  3. 03Adapt the example tool for a custom server

MCP support

Implements an MCP server with an HTTP POST endpoint at /mcp exposed through Amazon API Gateway. The example provides an add tool and supports MCP JSON-RPC requests.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

🧠 sam-serverless-mcp-server

A super simple Model Context Protocol (MCP) server deployed on AWS Lambda and exposed via Amazon API Gateway, deployed with Serverless Application Model (SAM). 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 article of this series 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 SAM
  • πŸ§ͺ Includes a simple example tool (add) with JSON-RPC interaction

πŸ“¦ Project Structure

sam-serverless-mcp-server/
β”œβ”€β”€ __tests__/              # Jest tests
β”œβ”€β”€ src/                    # Source code
β”‚   └── index.js                # MCP server handler
β”œβ”€β”€ .gitignore              # Git ignore file
β”œβ”€β”€ buildspec.yml           # Buildspec file for AWS CodeBuild and CodePipeline (CI/CD)
β”œβ”€β”€ jest.config.mjs         # Jest config file
β”œβ”€β”€ package.json            # Project dependencies
β”œβ”€β”€ package-lock.json       # Project lock file
β”œβ”€β”€ README.md               # This documentation file
β”œβ”€β”€ samconfig.toml          # Serverless Application Model config
└── template.yml            # Serverless Application Model template

πŸ›  Prerequisites

πŸš€ Getting Started

  1. Install dependencies:
npm install
  1. Run Locally with SAM
sam local start-api

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

Switch to Api Gateway V2 (HTTP API)

If you want to use API Gateway V2, you can change the template.yml file to use HttpApi instead of Api 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.

Events:
  McpHttpApi:
    Type: HttpApi  # πŸ‘ˆ This switches to HTTP API (v2)
    Properties:
      Path: /mcp
      Method: POST

πŸ§ͺ Test with curl requests

List tools
curl --location 'http://localhost:3000/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/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:

sam build
sam deploy --guided

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

πŸ“˜ License

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

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.