
在AWS Lambda函数中运行现有的模型上下文协议(MCP)基于stdio的服务器
概览
该项目使你能够在AWS Lambda函数中运行基于模型上下文协议的标准服务器。 目前,大多数MCP服务器和客户端的实现完全本地运行在一台机器上。桌面应用程序如IDE或Claude Desktop在本地启动MCP服务器作为子进程,并通过长运行的stdio流与每台服务器通信。 该库帮助你将现有的标准 MCP 服务器打包到 Lambda 函数中。你可以通过短暂的 HTTPS 连接,使用 MCP 协议从应用调用这些基于函数的 MCP 服务器。你的应用可以是基于桌面的应用、运行在云中的分布式系统,或任何其他架构。 利用该库,Lambda函数将管理您的stdio MCP服务器生命周期。每次Lambda函数调用将: 1. 将stdio MCP服务器作为子进程启动 1.初始化MCP服务器1.将收到的请求转发到本地服务器1.
概述(AI 翻译)
该项目使你能够在AWS Lambda函数中运行基于模型上下文协议的标准服务器。
目前,大多数MCP服务器和客户端的实现完全本地运行在同一台机器上。 桌面应用程序,如 IDE 或 Claude Desktop,会作为子进程在本地启动 MCP 服务器 并通过长期运行的 Stdio 流与这些服务器通信。
这个库帮助你将现有的stdio MCP服务器打包到Lambda函数中。 您可以使用 MCP 协议,从应用程序调用这些基于函数的 MCP 服务器 通过短暂的HTTPS连接。 你的应用可以是基于桌面的应用,一个运行在云端的分布式系统, 或者任何其他建筑。
利用该库,Lambda函数将管理你stdio MCP服务器的生命周期。 每次Lambda函数调用将:
- 将stdio MCP服务器作为子进程启动
- 初始化MCP服务器
- 将收到的请求转发到本地服务器
- 返回服务器对函数调用者的响应
- 关闭MCP服务器子进程
该库支持通过四种方式连接基于Lambda的MCP服务器:
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
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 Applicationwith MCP Clients"]
S1["MCP Server A(child process)"]
S2["MCP Server B(child process)"]
Host |"MCP Protocol(over stdio stream)"| S1
Host |"MCP Protocol(over stdio stream)"| S2
end
This library 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 HTTPS connections. Your application can then be a desktop-based app, a distributed system running in the cloud, or any other architecture.
flowchart LR
subgraph "Distributed System"
App["Your Applicationwith MCP Clients"]
S3["MCP Server A(Lambda function)"]
S4["MCP Server B(Lambda function)"]
App |"MCP Protocol(over HTTPS connection)"| S3
App |"MCP Protocol(over HTTPS connection)"| S4
end
Using this library, the Lambda function will manage the lifecycle of your stdio MCP server. Each Lambda function invocation will:
- Start the stdio 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
This library supports connecting to Lambda-based MCP servers in four ways:
- The MCP Streamable HTTP transport, using Amazon API Gateway. Typically authenticated using OAuth.
- The MCP Streamable HTTP transport, using Amazon Bedrock AgentCore Gateway. Authenticated using OAuth.
- A custom Streamable HTTP transport with support for SigV4, using a Lambda function URL. Authenticated with AWS IAM.
- A custom Lambda invocation transport, using the Lambda Invoke API directly. Authenticated with AWS IAM.
Determine your server parameters
安装
npx --offline my-mcp-server-typescript-module --my-server-command-line-parameter some_value