ECS MCP服务器示例
以下示例演示了如何使用AWS Fargate for Amazon ECS部署代理AI架构。使用 AWS CDK 部署架构组件。
高级体系结构
详情
该架构由以下组件组成:
- 应用程序负载平衡器:接收传入的API调用并将其转发到AI服务
- 人工智能服务:与两个MCP服务器连接以执行操作的简单AI代理
- MCP服务器二:它承载现有的MCP服务器(AWS API MCP服务器).为了这个例子,此MCP服务器的角色仅限于在您的帐户中列出AWS Bucket
AWS Fargate服务之间的服务到服务通信是使用 服务连接The 人工智能服务 利用自定义DNS名称连接到此示例中可用的MCP服务器。
该示例还生成了一个AWS Secret,用作 x-api-key 调用应用程序负载平衡器URL时使用header。
先决条件
入门
要在您的帐户中部署此示例,请按照以下说明操作:
# install dependencies
$ npm install
# login to the public ECR registry to allow download base images
$ aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
# bootstrap your AWS environment (in case you haven't done it yet)
$ npm run cdk bootstrap
# deploy the CDK Stack into your account
$ npm run cdk deploy测试
在您的帐户中完成部署后,您将从AWS CDK获得以下输出:
✅ EcsMcpServerSampleStack
✨ Deployment time: 362.32s
Outputs:
EcsMcpServerSampleStack.ALBLoadBalancerDNS6ED38D87 = [application-load-balancer-url]
EcsMcpServerSampleStack.AiServiceSecretARN2FB050DB = [secret-arn]在调用应用程序负载平衡器URL之前,您需要使用以下命令检索密钥值:
$ aws secretsmanager get-secret-value --secret-id [secret-arn]
# or use the following to directly get the value
$ aws secretsmanager get-secret-value --secret-id [secret-arn] --output json | jq -r '.SecretString'现在您已经掌握了所有信息,您可以调用应用程序负载均衡器URL来测试代理:
curl --location 'http://[ALB-URL]/chat' \
--header 'x-api-key: [secret-value]' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "what'\''s the command to list AWS Buckets"
}'{
"answer": "The command to list AWS S3 buckets is:\n\n```bash\naws s3 ls\n```\n\nThis command will display all S3 buckets in your AWS account, showing:\n- Creation date and time\n- Bucket name\n\nAs you can see from the output, it lists all the buckets with their creation timestamps and names. The command works across all regions and shows buckets from your entire AWS account.\n"
}或执行AWS CLI命令:
curl --location 'http://[ALB-URL]/chat' \
--header 'x-api-key: [secret-value]' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "list all my AWS Buckets"
}'{
"answer": "Here are all your S3 buckets: [omissis]"
}或者使用 自定义MCP服务器:
curl --location 'http://[ALB-URL]/chat' \
--header 'x-api-key: [secret-value]' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "what'\''s 2+2"
}'{
"answer": "2 + 2 = **4**\n"
}安全
看 贡献 了解更多信息。
许可证
此库根据MIT-0许可证获得许可。请参阅LICENSE文件。
