基本能力
产品定位
MCP Lambda Server 是一个为 AWS Lambda 函数设计的 MCP 协议服务器,支持流式响应和实时数据传输。
核心功能
- 适配 MCP TypeScript SDK 以在 AWS Lambda 中工作
- 通过 Lambda 响应流支持 Server-Sent Events (SSE)
- 处理 CORS 和 HTTP 方法验证
- 支持 TypeScript
适用场景
- 需要在 AWS Lambda 中实现 MCP 协议的场景
- 需要实时数据传输的应用
- 使用 Server-Sent Events (SSE) 的流式响应场景
工具列表
summarize
: 用于文本摘要生成generate
: 用于基于提示生成内容
常见问题解答
- Lambda 响应流仅适用于 Function URLs,不支持 API Gateway 或 Application Load Balancer。
- 仅 Node.js 运行时官方支持响应流。
使用教程
使用依赖
确保已安装 Node.js 18.x 或更高版本。
安装教程
bash
npm install @markvp/mcp-lambda-layer
调试方式
创建 Lambda 函数并导入包,配置工具和提示处理程序后,导出处理程序进行调试。
```typescript
import { MCPHandlerFactory } from '@markvp/mcp-lambda-layer';
import { z } from 'zod';
const factory = new MCPHandlerFactory({
tools: {
summarize: {
params: {
text: z.string(),
},
handler: async ({ text }) => {
const summary = await yourSummarizeImplementation(text);
return {
content: [{ type: 'text', text: summary }],
};
},
},
},
prompts: {
generate: {
description: 'Generate content based on a prompt',
handler: async extra => {
const result = await yourGenerateImplementation(extra.prompt);
return {
content: [{ type: 'text', text: result }],
};
},
},
},
});
export const handler = factory.getHandler();
```
所需 Lambda 配置
- 运行时: Node.js 18.x 或更高版本
- 处理程序: index.handler
- 内存: 至少 128 MB
- 超时: 建议 120 秒
- Function URL: 必须启用响应流
- API Gateway/ALB: 不支持流式响应