CloudFormation MCP服务器
基于人工智能的基础设施设计平台,将自然语言转化为具有专业架构图的生产就绪CloudFormation模板。
特性
- 🏗️ 自然语言到云形成 -从纯英语生成模板(Bedrock Converse API,Claude Haiku 4.5)
- 📋 架构概述 -快速第一步概述(无需扩展思维);然后生成完整模板
- 📊 专业架构图 -使用AWS官方图标自动生成可视化图表
- ✅ 模板验证 -使用可选的auto-fix根据AWS CloudFormation API进行验证
- 💰 成本优化 -基于人工智能的成本分析和建议
- 🏛️ 架构良好的审查 -自动6柱框架审查
- 🚀 堆栈配置 -将经过验证的模板直接部署到AWS
- ⏱️ 刀具计时 -UI(设计页面)中显示的每个工具的运行时间
- 🧠 扩展思维(CoT) -使用它的工具返回推理(例如成本、审查);登录浏览器控制台
- 🤖 DevOps代理 -带有AWS DevOps Agent链接的侧栏页面(独立和Salesforce UI)
建筑
┌─────────────────────────────────────────────────────────────────┐
│ User Interface │
│ (AWS Console-style Web UI) │
│ • Natural language input │
│ • Design Agent: Architecture Overview + CloudFormation Template │
│ • Deployment Agent: Provision / delete stacks │
│ • DevOps Agent: Links to AWS DevOps Agent │
│ • How-to Guide: Agentforce integration │
│ • Tool timings and progress over WebSocket │
└────────────────────────┬────────────────────────────────────────┘
│ WebSocket (WSS)
│ No timeout limits
│
┌────────────────────────▼────────────────────────────────────────┐
│ API Gateway (WebSocket API) │
│ • Endpoint: z832i481e5.execute-api.us-east-1.amazonaws.com │
│ • Protocol: WebSocket │
│ • Routes: $connect, $default, $disconnect │
│ • Real-time bidirectional communication │
└────────────────────────┬────────────────────────────────────────┘
│ Invokes
│
┌────────────────────────▼────────────────────────────────────────┐
│ Lambda Function (WebSocket Handler) │
│ • Name: cfn-builder-websocket │
│ • Runtime: Python 3.11 │
│ • Timeout: 600 seconds (10 minutes) │
│ • Memory: 512 MB │
│ • Security: NOT publicly accessible │
│ • Function: Async processing + AWS SigV4 signing │
│ • Returns immediately, processes in background thread │
└────────────────────────┬────────────────────────────────────────┘
│ HTTPS + SigV4
│ IAM Authentication
│
┌────────────────────────▼────────────────────────────────────────┐
│ AgentCore Runtime (MCP Server Container) │
│ • ARN: mcp_server-VpWbdyCLTH │
│ • Protocol: MCP (Model Context Protocol) │
│ • Transport: Streamable HTTP │
│ • Authentication: AWS IAM (SigV4) │
│ • Container: Python 3.13 + GraphViz │
│ • Session Management: Automatic │
│ • Observability: CloudWatch + X-Ray │
└────────────────────────┬────────────────────────────────────────┘
│
│ MCP Tools
│
┌────────────────────────▼────────────────────────────────────────┐
│ MCP Tools Layer │
│ (Bedrock via Converse API; default model: Claude Haiku 4.5) │
│ │
│ • generate_architecture_overview – Fast overview (no CoT) │
│ • build_cfn_template – CloudFormation YAML/JSON │
│ (no extended thinking for speed; validate + auto_fix as needed)│
│ • validate_cfn_template – Validate + optional auto-fix │
│ • provision_cfn_stack / delete_cfn_stack / get_cfn_stack_events │
└────────────────────────┬────────────────────────────────────────┘
│
│ boto3 SDK
│
┌────────────────────────▼────────────────────────────────────────┐
│ AWS Services │
│ • Amazon Bedrock (Converse API; Claude Haiku 4.5 default) │
│ • AWS CloudFormation │
└──────────────────────────────────────────────────────────────────┘关键架构优势
WebSocket设计
- ✅ 无超时限制 -浏览器与Lambda的连接保持打开状态
- ✅ 实时更新 -长时间操作期间的进度消息
- ✅ 双向 -服务器可以向客户端推送更新
- ✅ 异步处理 -Lambda立即返回,后台处理
安全模型
- ✅ Lambda未公开 -没有函数URL,只有API网关可以调用
- ✅ IAM身份验证 -AgentCore需要SigV4签名的请求
- ✅ 凭据服务器端 -浏览器永远看不到AWS凭据
- ✅ 最小特权 -整个过程中的最低IAM权限
可扩展性
- ✅ AgentCore自动秤 -无服务器容器平台
- ✅ Lambda并发 -处理多个连接
- ✅ WebSocket持久 -高效的连接重用
- ✅ Agent核心生命周期 -每个会话保持容器温暖(空闲超时~15分钟);看见
docs/COLD_START_AND_PREWARM.md用于调谐
快速开始
先决条件
- 已配置凭据的AWS帐户
- Python 3.10+
- GraphViz(用于本地图表生成)
安装
# Install GraphViz
brew install graphviz # macOS
sudo apt-get install graphviz # Linux
# Install Python dependencies
pip install -r requirements.txt本地运行
# Start MCP server
python mcp_server.py
# Test with client
python mcp_client.py部署
所有AWS部署都使用 aws-gaurav 轮廓。应用程序运行在 放大;推送到git会触发前端部署。
部署AgentCore(MCP服务器)
从项目根:
./deploy-agentcore.sh # Uses profile aws-gaurav部署前端(Amplify)
推送到您连接的Git存储库;Amplify自动构建和部署(请参阅 amplify.yml).
git add .
git commit -m "Your changes"
git push可选:部署WebSocket后端(Lambda+API网关)
如果使用WebSocket堆栈,请从项目根运行(脚本使用配置文件aws-gaurav):
./deploy-to-aws.sh # or your CloudFormation deploy部署状态
✅ 部署到AWS
- ARN探员:
arn:aws:bedrock-agentcore:us-east-1:905767016260:runtime/mcp_server-VpWbdyCLTH - Websocket API:
wss://197c9q4u8i.execute-api.us-east-1.amazonaws.com/prod - 部署类型:容器(带GraphViz)
- 区域:美国东部-1
- 个人资料:aws-gaurav用于AgentCore和CLI部署
可用工具
所有工具都是实时可用的:
- ✅
generate_architecture_overview-快速架构概述(无需扩展思维) - ✅
build_cfn_template-从自然语言生成CloudFormation(针对速度进行了优化) - ✅
validate_cfn_template-通过AWS API验证模板(带有可选的auto-fix) - ✅
provision_cfn_stack/delete_cfn_stack/get_cfn_stack_events-堆栈生命周期
用法
通过用户界面
# Start backend (local testing)
cd ui/backend_python
python server.py
# Open frontend
open ui/frontend/index.html
# Enter prompt:
"Create a serverless API with API Gateway, Lambda, and DynamoDB"
# Click Generate → View professional diagram in Canvas tab通过MCP客户端
import asyncio
from mcp import ClientSession
from streamable_http_sigv4 import streamablehttp_client_with_sigv4
async def main():
agent_arn = "arn:aws:bedrock-agentcore:us-east-1:905767016260:runtime/mcp_server-VpWbdyCLTH"
region = "us-east-1"
# Encode ARN
encoded_arn = agent_arn.replace(":", "%3A").replace("/", "%2F")
mcp_url = f"https://bedrock-agentcore.{region}.amazonaws.com/runtimes/{encoded_arn}/invocations?qualifier=DEFAULT"
async with create_streamable_http_transport_sigv4(
mcp_url, "bedrock-agentcore", region
) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize()
# Generate template
result = await session.call_tool(
"build_cfn_template",
{"prompt": "Create a serverless API", "format": "yaml"}
)
print(result)
asyncio.run(main())通过agentcore命令行界面
agentcore invoke '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "build_cfn_template",
"arguments": {
"prompt": "Create an S3 bucket with versioning",
"format": "yaml"
}
}
}'专业图表生成⭐ 新
运作原理
User Prompt
↓
build_cfn_template() → CloudFormation Template支持的AWS服务(20+)
- 计算:Lambda、EC2、ECS
- 网络:API网关、ALB、CloudFront、路由器53
- 数据库:DynamoDB、RDS、ElastiCache
- 存储:S3
- 安全:康尼托,IAM
- 整合:SNS、SQS、Step函数、EventBridge
- 分析:动脉炎
输出示例
对于带有API网关、Lambda和DynamoDB的无服务器API:
- ✅ 专业PNG图
- ✅ AWS官方服务图标
- ✅ 带连接的自动布局
- ✅ Base64编码(网络就绪)
- ✅ 2-5秒生成时间
仓库结构
cfn-mcp-server/
├── mcp_server.py # MCP server (Converse API, tools for CFn + cost + review)
├── mcp_client.py # Local test client
├── mcp_client_remote.py # Remote client with IAM auth
├── streamable_http_sigv4.py # SigV4 helper
├── requirements.txt # Python dependencies
├── Dockerfile # Container with GraphViz
├── .bedrock_agentcore.yaml # AgentCore config
├── deploy/
│ ├── infrastructure.yaml # Backend CloudFormation
│ ├── websocket-infrastructure.yaml
│ └── lambda_backend/
│ ├── handler.py # FastAPI handler
│ └── requirements.txt
├── ui/
│ ├── frontend/
│ │ └── index.html # Web UI
│ └── backend_python/
│ └── server.py # Local dev server
├── tests/
│ ├── test_diagram.py # Diagram generation test
│ └── test_nl_prompts.sh # Integration tests
└── docs/ # Documentation部署
部署MCP服务器
# Configure
agentcore configure -e mcp_server.py --protocol MCP --deployment-type container
# Deploy
agentcore launch
# Test
agentcore invoke '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'部署后端(WebSocket)
./deploy-to-aws.sh部署前端(放大)
- 推送到GitHub(已完成)
- 转到AWS Amplify控制台
- 连接存储库:
adhavle-aws/ict-mcp-server - 自动部署
监控
CloudWatch日志
# MCP Server
aws logs tail /aws/bedrock-agentcore/runtimes/mcp_server-VpWbdyCLTH-DEFAULT \
--log-stream-name-prefix "2026/01/30/[runtime-logs]" --follow
# Lambda Backend
aws logs tail /aws/lambda/cfn-builder-websocket --followGenAI观察性仪表板
https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#gen人工智能可观测性/智能体核心
X射线追踪
- ✅ 已为所有工具调用启用
- ✅ 跟踪延迟和错误
- ✅ AWS X-Ray控制台中的视图
安全
- ✅ IAM身份验证 -SigV4签名请求
- ✅ 无公共端点 -Lambda不可公开访问
- ✅ 最小特权 -最低IAM权限
- ✅ 加密 -HTTPS无处不在,加密日志
- ✅ 审计跟踪 -云观察+X射线+云追踪
成本估算
每月10000次请求:
- AgentCore运行时间:~5-10美元
- λ:约1美元
- API网关:约0.04美元
- 基岩(克劳德):约15-30美元
- 总计:约20-40美元/月
文档
docs/architecture.md-端到端架构和请求流docs/COLD_START_AND_PREWARM.md-冷启动缓解和延迟优化推理docs/PERFORMANCE_ANALYSIS.md-性能分解和优化策略deploy/TIMEOUT_FIX.md-API网关29s超时和异步Lambda模式DEPLOYMENT_SUCCESS.md-部署详细信息DIAGRAM_INTEGRATION.md-图表功能指南salesforce_ui/README.md-将AWS Architect AI部署为Visualforce页面
配置(可选)
BEDROCK_MODEL_ID–覆盖基岩模型(默认值:Claude Haiku 4.5)。例子:anthropic.claude-sonnet-4-5-20250929-v1:0BEDROCK_LATENCY_OPTIMIZED–设置为true当您的模型/地区支持时,请求延迟优化的推理(请参阅docs/COLD_START_AND_PREWARM.md).
支持
对于问题或疑问:
- 检查CloudWatch日志
- 验证GraphViz:
dot -V - 先在本地测试:
python mcp_client.py - 审查文档
docs/
许可证
麻省理工学院
______________________________________________________________________
状态: ✅ 已部署并投入运行。架构+模板流优化速度;UI/控制台中的工具计时和扩展思维(如果启用);支持Salesforce UI和DevOps Agent页面。
