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

sample-serverless-mcp-servers

MCP.Pizza Chef: aws-samples

Sample-serverless-mcp-servers is a collection of example MCP Server implementations designed to run on AWS serverless infrastructure such as AWS Lambda and Amazon ECS. It includes stateless and stateful server examples using Node.js and Python runtimes, with infrastructure as code templates in Terraform and SAM. These samples showcase how to deploy scalable, remote MCP Servers leveraging AWS services like API Gateway and Application Load Balancers.

Use This MCP server To

Deploy stateless MCP Servers on AWS Lambda with API Gateway Run stateful MCP Servers on Amazon ECS with load balancing Use Terraform or SAM to provision MCP Server infrastructure Experiment with Node.js and Python MCP Server runtimes Build scalable remote MCP Servers on AWS serverless platforms

README

Sample Serverless MCP Servers

This repo contains a collection of sample implementations of MCP Servers.

Directory Runtime IaC Description
stateless-mcp-on-lambda Node.js Terraform A sample implementation of a remote stateless MCP Server running natively on AWS Lambda and Amazon API Gateway
stateless-mcp-on-lambda-python Python SAM A sample implementation of a remote stateless MCP Server running natively on AWS Lambda and Amazon API Gateway
stateless-mcp-on-ecs Node.js Terraform A sample implementation of a remote stateless MCP Server running natively on Amazon ECS with Application Load Balancer
stateful-mcp-on-ecs Node.js Terraform A sample implementation of a remote stateful MCP Server running natively on Amazon ECS with Application Load Balancer
lambda-ops-mcp-server Node.js Terraform A demo PoC of a local MCP Server that can be used for discovering and upgrading functions on deprecated runtimes

Stateful VS Stateless MCP Servers

When using Streamable HTTP Transport with MCP Servers/Clients, it’s important to understand the difference and trade-offs between stateful and stateless MCP server implementations. Each model has implications for scalability, connection handling, and session management.

Key Aspects

The Streamable HTTP Transport specification outlines two important capabilities. First, a client may initiate a long-lived HTTP GET request to establish a persistent SSE (Server-Sent Events) connection, allowing the server to push data even when the client hasn’t sent a POST request. Second, if the connection is interrupted, the client should be able to resume communication by reconnecting through another GET request. Both features imply that the server must be able to maintain a persistent session context and support long-lived connections. Read more about Streamable HTTP Transport session management here.

Stateful model challenges

In a stateful MCP server, this means maintaining session state in memory and keeping SSE connections alive over time. However, as of early May 2025, none of the official MCP SDKs support external session persistence (e.g. in Redis or DynamoDB). This limitation makes it difficult to scale stateful servers horizontally. For example, a client might establish a session with one server instance, but if subsequent requests are routed to a different instance, the session context will be lost and the connection will fail.

That said, it is still possible to scale stateful MCP servers if you're willing to configure session affinity, also known as sticky sessions, at the load balancer level. For example, cookie-based sticky sessions can ensure that a client is routed to the same server instance for the duration of a session. However, the TypeScript MCP Client SDK currently relies on the fetch API, which doesn’t natively support cookies. To work around this limitation, you'll need to implement manual cookie handling, as shown in the stateful-mcp-on-ecs example.

Stateless to the rescue

The MCP specification also allows for a stateless server mode. In this mode, the server doesn’t maintain session context between requests, and clients are not expected to resume dropped connections. Stateless mode enables seamless horizontal scaling and works well in environments where elasticity and load distribution are critical. This model is demonstrated in the stateless-mcp-on-lambda, stateless-mcp-on-ecs, and stateless-mcp-on-lambda-python samples included in this repository.

Refer to each folder separately for further instructions and deployment steps.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

sample-serverless-mcp-servers FAQ

How do I deploy these MCP Servers on AWS?
Use the provided Terraform or SAM infrastructure as code templates to deploy on AWS Lambda or ECS.
Can I run these MCP Servers with different runtimes?
Yes, sample implementations are available in both Node.js and Python.
Are these MCP Servers stateless or stateful?
The repo includes both stateless and stateful MCP Server examples.
What AWS services do these MCP Servers use?
They use AWS Lambda, Amazon ECS, API Gateway, and Application Load Balancers.
Is this suitable for production use?
These are sample implementations intended for learning and prototyping, not production-ready out of the box.
Can I extend these samples for custom MCP Server functionality?
Yes, the code is open and designed for customization and extension.
How do these MCP Servers integrate with MCP Clients?
They expose MCP Server APIs remotely, allowing MCP Clients to connect and interact with them.
What is the benefit of serverless MCP Servers?
Serverless MCP Servers offer scalable, cost-efficient, and managed infrastructure for MCP deployments.