Run existing Model Context Protocol (MCP) stdio-based servers in AWS Lambda functions
This project enables you to run Model Context Protocol stdio-based servers in AWS Lambda functions.
Currently, most implementations of MCP servers and clients are entirely local on a single machine. A desktop application such as an IDE or Claude Desktop initiates MCP servers locally as child processes and communicates with each of those servers over a long-running stdio stream.
flowchart LR
subgraph "Your Laptop"
Host["Desktop Application<br>with MCP Clients"]
S1["MCP Server A<br>(child process)"]
S2["MCP Server B<br>(child process)"]
Host <-->|"MCP Protocol<br>(over stdio stream)"| S1
Host <-->|"MCP Protocol<br>(over stdio stream)"| S2
end
This MCP server adapter for AWS Lambda helps you to wrap existing stdio MCP servers into Lambda functions. You can invoke these function-based MCP servers from your application using the MCP protocol over short-lived connections. Your application can then be a desktop-based app, a distributed system running in the cloud, or any other architecture. Your application must have access to invoke your Lambda functions, and use the custom MCP client transport that invokes the Lambda functions.
flowchart LR
subgraph "Distributed System"
App["Your Application<br>with MCP Clients"]
S3["MCP Server A<br>(Lambda function)"]
S4["MCP Server B<br>(Lambda function)"]
App <-->|"MCP Protocol<br>with custom transport<br>(invoke function)"| S3
App <-->|"MCP Protocol<br>with custom transport<br>(invoke function)"| S4
end
This project includes an example Python Lambda function that runs the simple MCP 'time' reference server. The Lambda function bundles the mcp-server-time package. On each function invocation, the Lambda function will manage the lifecycle of the bundled MCP server. It will:
import sys
from mcp.client.stdio import StdioServerParameters
from mcp_lambda import stdio_server_adapter
server_params = StdioServerParameters(
command=sys.executable,
args=[
"-m",
"mcp_server_time",
"--local-timezone",
"America/New_York",
],
)
def handler(event, context):
return stdio_server_adapter(server_params, event, context)
This project includes an example Node.js Lambda function that runs an OpenAPI MCP server to provide a single API from weather.gov as a tool. The Lambda function bundles the openapi-mcp-server package. On each function invocation, the Lambda function will manage the lifecycle of the bundled MCP server. It will:
import { Handler, Context } from "aws-lambda";
const serverParams = {
command: "npx",
args: ["--offline", "openapi-mcp-server", "./weather-alerts-openapi.json"],
};
export const handler: Handler = async (event, context: Context) => {
// Dynamically import ES module into CommonJS Lambda function
const { stdioServerAdapter } = await import(
"@aws/run-mcp-servers-with-aws-lambda"
);
return await stdioServerAdapter(serverParams, event, context);
};
This project includes an example Python MCP client that invokes the 'time' MCP server function from above. The client invokes a Lambda function named "mcp-server-time" with a payload that is compliant with the MCP protocol and returns the function's response to the caller.
from mcp import ClientSession
from mcp_lambda import LambdaFunctionParameters, lambda_function_client
server_params = LambdaFunctionParameters(
function_name="mcp-server-time",
region_name="us-east-2",
)
read, write = await lambda_function_client(server_params)
session = ClientSession(read, write)
await session.initialize()
This project includes an example Typescript MCP client that invokes the 'time' MCP server function from above. The client invokes a Lambda function named "mcp-server-time" with a payload that is compliant with the MCP protocol and returns the function's response to the caller.
import {
LambdaFunctionParameters,
LambdaFunctionClientTransport,
} from "@aws/run-mcp-servers-with-aws-lambda";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
const serverParams: LambdaFunctionParameters = {
functionName: "mcp-server-time",
regionName: "us-east-2",
};
const client = new Client(
{
name: "my-client",
version: "0.0.1",
},
{
capabilities: {
sampling: {},
},
}
);
const transport = new LambdaFunctionClientTransport(serverParams);
await client.connect(transport);
See the development guide for instructions to deploy and run the examples in this repository.
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.
{ "mcpServers": { "run-model-context-protocol-servers-with-aws-lambda": { "command": "npx", "args": [ "--offline", "openapi-mcp-server", "./weather-alerts-openapi.json" ] } } }
Related projects feature coming soon
Will recommend related projects based on sub-categories