云MCP AI智能体
一个全面的模型上下文协议(MCP)系统,通过专门的MCP服务器为AI助手提供访问AWS服务的途径。该项目包括用于AWS服务的MCP服务器以及一个智能客户端,该客户端能够自动将查询路由到相应的服务器。
🏗️ 建筑学
这个项目由三个主要部分组成:
- AWS IAM MCP 服务器 - 管理AWS身份和访问管理(IAM)操作
- AWS 账单与成本管理 MCP 服务器 - 负责AWS(亚马逊网络服务)的成本分析与优化
- 智能MCP客户端 - 使用层级选择将查询路由到适当的服务器
🚀 快速入门
先决条件
- Python 3.10及以上版本 - 使用以下方法安装 紫外线:
uv python install 3.10- AWS 凭据 - 使用以下方法之一进行配置:
# Option 1: AWS Profile (recommended)
export AWS_PROFILE=your-profile-name
# Option 2: Environment Variables
export AWS_ACCESS_KEY_ID=your-access-key
export AWS_SECRET_ACCESS_KEY=your-secret-key
export AWS_REGION=us-east-1- Cerebras API密钥 - 对于智能客户端:
export CEBRAS_API_KEY=your-cerebras-api-key安装
# Clone the repository
git clone
cd Cloud-MCP-AI-Agent
# Install dependencies
uv sync环境设置
创造 .env 将文件放在相应的目录中:
# Root directory .env (for client)
echo "CEBRAS_API_KEY=your-cerebras-api-key" > .env
# IAM server .env
echo "AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1" > iam-mcp-server/.env
# Billing server .env
echo "AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=us-east-1" > billing-cost-management-mcp-server/.env🖥️ 运行服务器
IAM MCP 服务器
# Start the IAM server
python run_iam_server.py
# Server will be available at: http://localhost:8051/sse/特点:
- 用户、角色、组和策略管理
- 访问密钥管理
- 政策模拟与验证
- 内联策略的创建、读取、更新和删除(CRUD)操作
- 实施安全最佳实践
计费与成本管理MCP服务器
# Start the billing server
python run_billing_server.py
# Server will be available at: http://localhost:8050/sse/特点:
- 成本探索器见解与分析
- 预算监控与提醒
- 成本优化建议
- 预留实例和节省计划分析
- 免费层级使用情况监控
- S3 存储镜像分析
- 成本异常检测
使用智能客户端🤖
智能客户端使用三级分层选择系统,自动将您的查询路由到相应的MCP服务器:
- 服务器选择 - 在IAM服务器或计费服务器之间进行选择
- 工具组选择 - 选择适当的工具类别
- 工具选择 - 选择特定的工具来执行
运行客户端
cd llm_client_server
python client.py客户端组件
client.py- 主客户端,具备智能路由功能server_selector.py- 处理服务器选择逻辑unified_hierarchical_agent.py- 管理工具组和工具选择hierarchical_agent.py- 遗留层级代理(向后兼容)server.py- 本地服务器实现
示例用法
from llm_client_server.client import MCPCerebrasClient
# Initialize client
client = MCPCerebrasClient()
# Connect to servers
await client.connect_to_server("http://localhost:8051/sse/") # IAM
await client.connect_to_server("http://localhost:8050/sse/") # Billing
# Query examples
await client.query("List all IAM users in my account")
await client.query("Show me my AWS costs for the last month")
await client.query("What are my cost optimization opportunities?")📁 项目结构
Cloud-MCP-AI-Agent/
├── README.md # This file
├── pyproject.toml # Project configuration
├── run_iam_server.py # IAM server launcher
├── run_billing_server.py # Billing server launcher
├── .gitignore # Git ignore rules
│
├── iam-mcp-server/ # AWS IAM MCP Server
│ ├── README.md # IAM server documentation
│ ├── pyproject.toml # IAM server config
│ ├── awslabs/iam_mcp_server/ # Server implementation
│ └── tests/ # IAM server tests
│
├── billing-cost-management-mcp-server/ # AWS Billing MCP Server
│ ├── README.md # Billing server documentation
│ ├── pyproject.toml # Billing server config
│ ├── awslabs/billing_cost_management_mcp_server/ # Server implementation
│ └── tests/ # Billing server tests
│
└── llm_client_server/ # Intelligent MCP Client
├── client.py # Main client implementation
├── server_selector.py # Server selection logic
├── unified_hierarchical_agent.py # Tool selection logic
├── hierarchical_agent.py # Legacy agent
├── server.py # Local server
└── data/ # Client data files🔧 配置
服务器配置
两台MCP服务器均支持多种配置选项:
IAM 服务器:
--read-only- 以只读模式运行(不进行修改)--region- AWS 区域(默认:us-east-1)
计费服务器:
--region- AWS 区域(默认:us-east-1)- 针对复杂查询的自定义SQL会话管理
客户端配置
客户端可以通过环境变量进行配置:
# Cerebras API settings
CEBRAS_API_KEY=your-api-key
# Server endpoints (if different from defaults)
IAM_SERVER_URL=http://localhost:8051/sse/
BILLING_SERVER_URL=http://localhost:8050/sse/🛡️ 安全
最佳实践
- 环境变量 - 所有敏感数据均从环境变量中加载
- AWS 凭据 - 使用 IAM 角色或配置文件,而不是硬编码的密钥
- 只读模式 - 为安全起见,以只读模式运行服务器
- 最小特权原则 - 授予AWS所需的最小权限
所需的AWS权限
对于IAM服务器:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:List*",
"iam:Get*",
"iam:Create*",
"iam:Delete*",
"iam:Attach*",
"iam:Detach*",
"iam:Put*",
"iam:Simulate*"
],
"Resource": "*"
}
]
}对于计费服务器:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ce:*",
"budgets:View*",
"compute-optimizer:Get*",
"compute-optimizer:Describe*",
"cost-optimization-hub:Get*",
"cost-optimization-hub:List*",
"s3:GetStorageLensConfiguration*",
"freetier:GetFreeTierUsage"
],
"Resource": "*"
}
]
}🧪 测试
运行测试
# Test IAM server
cd iam-mcp-server
python -m pytest tests/
# Test Billing server
cd billing-cost-management-mcp-server
python -m pytest tests/
# Test client components
cd llm_client_server
python -m pytest手动测试
# Test server connectivity
curl http://localhost:8051/sse/ # IAM server
curl http://localhost:8050/sse/ # Billing server📚 文档
🤝 贡献
- 为仓库创建分支(或“克隆仓库”)
- 创建一个特性分支
- 进行你的更改
- 为新功能添加测试
- 提交一个拉取请求
📄 许可证
此项目采用MIT许可证授权——请参阅各个服务器目录中的具体许可证文件。
🆘 故障排除
常见问题
- 服务器无法启动:
- 检查AWS凭据是否已配置 - 验证端口8050和8051是否可用 - 检查Python版本(需要3.10+)
- 客户端连接失败:
- 确保服务器正在运行 - 验证CEBRAS_API_KEY是否已设置 - 检查服务器URL是否正确
- AWS 权限错误:
- 验证IAM权限是否符合要求 - 检查AWS区域配置 - 确保凭据具有必要的访问权限
调试模式
启用调试日志记录:
export MCP_DEBUG=1
python run_iam_server.py🔄 更新
更新项目:
git pull origin main
uv sync # Update dependencies______________________________________________________________________
注: 此项目提供了强大的AWS管理功能。在生产环境中使用前,请务必在开发环境中进行测试,并遵循AWS安全最佳实践。
