Lambda MCP服务

基于AWS Lambda运行的MCP协议服务器,支持模型上下文协议交互的云原生解决方案。

  • by micci184
  • HCL
  • 本地部署
  • 更新于
在 GitHub 查看 micci184/aws-lambda-mcp

使用说明

AWS Lambda MCP服务器

使用AWS Lambda运行的MCP服务器 Awslabs/mcp lambda.

需求

  • 地形>=1.14
  • 码头工人
  • AWS-CLI

部署

备注:Lambda要求在创建之前存在ECR映像。这就产生了鸡和蛋的问题:

  • 必须首先通过Terraform创建ECR存储库
  • 必须先推送Docker镜像,然后才能创建Lambda
  • 因此,初始部署需要多个步骤(后续更新只需要 terraform apply)

1.创建ECR存储库

cd terraform
terraform init
terraform apply -target=module.lambda_mcp.aws_ecr_repository.lambda_mcp

2.构建并推送Docker镜像

ECR_REPO=$(terraform output -raw ecr_repository_url)
aws ecr get-login-password | docker login --username AWS --password-stdin ${ECR_REPO%/*}
docker build -t mcp-server ..
docker tag mcp-server ${ECR_REPO}:latest
docker push ${ECR_REPO}:latest

3.部署Lambda

terraform apply

后续更新

初始部署后,只需推送一个新映像并运行 terraform apply:

docker build -t mcp-server ..
docker tag mcp-server ${ECR_REPO}:latest
docker push ${ECR_REPO}:latest
terraform apply

安全

⚠️ 警告:此部署使用Lambda函数URL authorization_type = "NONE",这意味着端点是可公开访问的。对于生产使用,考虑启用IAM身份验证或添加其他安全措施。

MCP客户端配置

{
  "mcpServers": {
    "aws-api": {
      "url": "<terraform output function_url>"
    }
  }
}

卷曲测试

FUNCTION_URL=$(terraform output -raw function_url)

# Initialize
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2024-11-05",
      "capabilities": {},
      "clientInfo": {
        "name": "test-client",
        "version": "1.0.0"
      }
    }
  }'

# List available tools
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'

许可证

阿帕奇-2.0