Sample Serverless MCP Servers logo

Sample Serverless MCP Servers

by aws-samples

This repository provides sample implementations of Model Context Protocol (MCP) Servers. It includes both stateful and stateless server implementations running on AWS Lambda, API Gateway, and ECS.

View on GitHub

Last updated: N/A

What is Sample Serverless MCP Servers?

This repository contains sample implementations of MCP Servers, demonstrating different approaches to handling state (stateful vs. stateless) and deployment environments (AWS Lambda, Amazon ECS). It provides practical examples for building MCP servers that adhere to the Streamable HTTP Transport specification.

How to use Sample Serverless MCP Servers?

Refer to each folder (stateless-mcp-on-lambda, stateless-mcp-on-ecs, stateful-mcp-on-ecs, lambda-ops-mcp-server) for specific instructions and deployment steps. The README files within each directory will guide you through the setup and configuration process for each sample server.

Key features of Sample Serverless MCP Servers

  • Stateless MCP server implementation on AWS Lambda and API Gateway

  • Stateless MCP server implementation on Amazon ECS with Application Load Balancer

  • Stateful MCP server implementation on Amazon ECS with Application Load Balancer

  • Local MCP Server for discovering and upgrading functions

  • Demonstrates Streamable HTTP Transport

  • Illustrates stateful vs. stateless server design patterns

Use cases of Sample Serverless MCP Servers

  • Building scalable MCP servers

  • Implementing real-time data streaming with MCP

  • Integrating MCP with serverless architectures

  • Managing long-lived connections with MCP

  • Deploying MCP servers on AWS

  • Discovering and upgrading functions on deprecated runtimes

FAQ from Sample Serverless MCP Servers

What is the difference between stateful and stateless MCP servers?

Stateful servers maintain session context between requests, while stateless servers do not. Stateful servers require session affinity for scaling, while stateless servers can scale horizontally without session affinity.

What is Streamable HTTP Transport?

Streamable HTTP Transport is a specification that allows clients to establish long-lived HTTP GET requests for persistent SSE connections, enabling servers to push data even when the client hasn’t sent a POST request.

How do I handle session management in a stateful MCP server?

Currently, the MCP SDKs do not support external session persistence. You can use session affinity (sticky sessions) at the load balancer level, but this may require manual cookie handling in the client.

When should I use a stateless MCP server?

Stateless MCP servers are suitable for environments where horizontal scaling and load distribution are critical. They are simpler to scale and do not require session management.

Where can I find deployment instructions for each sample server?

Refer to the README file within each folder (stateless-mcp-on-lambda, stateless-mcp-on-ecs, stateful-mcp-on-ecs, lambda-ops-mcp-server) for specific instructions and deployment steps.