
run-model-context-protocol-servers-with-aws-lambda
Exécuter des serveurs STDIO de contexte de modèle existant (MCP) dans les fonctions AWS Lambda
3 years
Works with Finder
79
Github Watches
5
Github Forks
79
Github Stars
Run Model Context Protocol (MCP) servers with AWS Lambda
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
Considerations
- If you are looking for a way to invoke existing Lambda functions as tools through MCP, see the AWS Lambda MCP Server project.
- This package currently requires using a custom MCP client transport to communicate with the MCP server by invoking the Lambda function. Existing applications with MCP support such as Amazon Q Developer CLI, Cline, etc do not have this custom transport, and cannot communicate with MCP servers adapted into Lambda functions. Note: with upcoming changes to the MCP protocol, we expect that this limitation will be removed in the future.
- This package currently supports MCP servers and clients written in Python and Typescript. Other languages such as Kotlin are not supported.
- The server adapters only adapt stdio MCP servers, not servers written for other protocols such as SSE.
- The server adapters do not maintain any MCP server state across Lambda function invocations. Only stateless MCP servers are a good fit for using this adapter. For example, MCP servers that invoke stateless tools like the time MCP server or make stateless web requests like the fetch MCP server. Stateful MCP servers are not a good fit, because they will lose their state on every request. For example, MCP servers that manage data on disk or in memory such as the sqlite MCP server, the filesystem MCP server, and the git MCP server.
- The server adapters ignore any MCP protocol notifications from the client to the server.
- The server adapters do not provide mechanisms for managing any secrets needed by the wrapped MCP server. For example, the GitHub MCP server and the Brave search MCP server require API keys to make requests to third-party APIs. You can configure these API keys as encrypted environment variables in the Lambda function's configuration. However, note that anyone with access to invoke the Lambda function will then have access to use your API key to call the third-party APIs by invoking the function. We recommend limiting access to the Lambda function using least-privilege IAM policies.
Examples
Python server example
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:
- start the 'time' MCP server as a child process
- initialize the MCP server
- forward the incoming request to the local server
- return the server's response to the function caller
- shut down the MCP server child process
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)
Typescript server example
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:
- start the 'openapi-mcp-server' MCP server as a child process
- initialize the MCP server
- forward the incoming request to the local server
- return the server's response to the function caller
- shut down the MCP server child process
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);
};
Python client example
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()
Typescript client example
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);
Deploy and run the examples
See the development guide for instructions to deploy and run the examples in this repository.
Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.
相关推荐
🔥 1Panel fournit une interface Web intuitive et un serveur MCP pour gérer des sites Web, des fichiers, des conteneurs, des bases de données et des LLM sur un serveur Linux.
🧑🚀 全世界最好的 LLM 资料总结 (数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Résumé des meilleures ressources LLM du monde.
PDF Traduction de papier scientifique avec formats conservés - 基于 AI 完整保留排版的 PDF 文档全文双语翻译 , 支持 Google / Deepl / Olllama / Openai 等服务 , 提供 CLI / GUI / MCP / DOCKER / ZOTERO
⛓️RULEGO est un cadre de moteur de règle d'orchestration des composants de nouvelle génération légère, intégrée, intégrée et de nouvelle génération pour GO.
Créez facilement des outils et des agents LLM à l'aide de fonctions Plain Bash / JavaScript / Python.
😎简单易用、🧩丰富生态 - 大模型原生即时通信机器人平台 | 适配 QQ / 微信 (企业微信、个人微信) / 飞书 / 钉钉 / Discord / Telegram / Slack 等平台 | 支持 Chatgpt 、 Deepseek 、 Dify 、 Claude 、 GEMINI 、 XAI 、 PPIO 、 OLLAMA 、 LM Studio 、阿里云百炼、火山方舟、 Siliconflow 、 Qwen 、 Moonshot 、 ChatGlm 、 Sillytraven 、 MCP 等 LLM 的机器人 / Agent | Plateforme de bots de messagerie instantanée basés sur LLM, prend en charge Discord, Telegram, WeChat, Lark, Dingtalk, QQ, Slack
Reviews

user_Bic8FNji
I recently started using run-model-context-protocol-servers-with-aws-lambda by awslabs and I am thoroughly impressed. This tool provides seamless integration and efficient server management using AWS Lambda. It truly simplifies the deployment process and boosts the overall performance of my applications. Highly recommended for anyone looking to enhance their server management with AWS solutions.

user_WeMuldwL
I recently started using "run-model-context-protocol-servers-with-aws-lambda" by awslabs and it's been a game changer! This product seamlessly integrates context protocols with AWS Lambda, making server management simpler and more efficient. The robust implementation has significantly improved my workflow, allowing for scalable and flexible server operations. Highly recommend for anyone looking to streamline their server processes with AWS Lambda.

user_jM56qtCr
As a dedicated user of run-model-context-protocol-servers-with-aws-lambda by awslabs, I am highly impressed by its seamless integration with AWS Lambda for efficient model serving. This tool has significantly improved my workflow, enabling rapid deployment and scaling without the need for extensive server management. Highly recommend for anyone looking to optimize their serverless architecture.

user_Nx8leAHq
I have been using the "run-model-context-protocol-servers-with-aws-lambda" by awslabs and I'm extremely impressed with its seamless integration capabilities. This product has significantly optimized our server management by leveraging AWS Lambda, reducing downtime and enhancing efficiency. Highly recommend it for anyone looking to streamline their server operations in a scalable and reliable manner.

user_nrTmrplf
run-model-context-protocol-servers-with-aws-lambda by awslabs is a remarkable tool for developers. It seamlessly integrates AWS Lambda, enabling the efficient management of protocol servers in a cloud context. Its user-friendly interface and robust functionality make it an essential resource for any cloud developer aiming to optimize their workflow. Highly recommended!

user_U1OWtCkR
As a dedicated user of the "run-model-context-protocol-servers-with-aws-lambda" by awslabs, I am truly impressed with its seamless integration and performance. This solution effectively simplifies the deployment of serverless applications, enabling robust, scalable, and flexible model serving. The documentation and support provided are top-notch, making it a valuable resource for developers looking to harness the power of AWS Lambda. Highly recommended for anyone looking to streamline their serverless workflows!

user_yIyvh3AV
I've had the pleasure of using the run-model-context-protocol-servers-with-aws-lambda by awslabs, and it's been a game-changer. This product seamlessly integrates AWS Lambda to run model context protocols efficiently. The setup is straightforward and the documentation is comprehensive. If you're looking to leverage AWS Lambda for your model context protocol servers, this tool is indispensable. Highly recommend!

user_gXikrbVJ
I've been using the run-model-context-protocol-servers-with-aws-lambda by awslabs and I am thoroughly impressed. This tool integrates seamlessly with AWS Lambda, facilitating efficient protocol server management and model context handling. The flawless functionality and ease of use make it an indispensable asset for cloud-based server operations. Highly recommended for anyone looking to streamline their AWS Lambda workflows!

user_mcEEHB8x
As a dedicated user of MCP applications, I am thoroughly impressed with the "run-model-context-protocol-servers-with-aws-lambda" by awslabs. This product offers seamless integration and extraordinary efficiency. Utilizing AWS Lambda for server management has significantly streamlined our operations. Highly recommend this for anyone looking to optimize their server protocols with minimal effort and maximum output!

user_L7xwEAH8
I've been using run-model-context-protocol-servers-with-aws-lambda by awslabs and I'm thoroughly impressed. This solution integrates seamlessly with AWS Lambda, providing a robust framework for maintaining model context in serverless environments. It simplifies deployment and scaling, making it a game-changer for cloud applications. Whether you're a seasoned developer or new to serverless, this tool is intuitive and highly efficient. Highly recommended for anyone looking to enhance their AWS Lambda experience!