我构建了一个 MCP 服务器,为 AI 代理提供实时 AWS 定价数据
发布: (2025年12月20日 GMT+8 11:44)
4 min read
原文: Dev.to
Source: Dev.to

问题
你正在构建一个用于配置云基础设施的 AI 代理。
用户说:“在最便宜的地区启动一个 t3.medium 实例。”
该代理不知道这会花费多少、哪个地区最便宜,或者预留实例是否能省钱。这导致无法回答最基本的问题:“这要花多少钱?”
解决方案:AWS 定价 MCP
我构建了一个兼容 MCP 的 API,实时返回 AWS 定价数据。该 API 已在 RapidAPI 上上线。
它的功能
- 查询 20 项 AWS 服务(EC2、RDS、Lambda、S3、DynamoDB、ECS、EKS 等)的定价
- 对比所有 18 个 AWS 区域的价格
- 提供按需实例与预留实例的细分
- 为多实例工作负载估算每月费用
工作原理
API遵循 MCP(模型上下文协议)约定,任何兼容 MCP 的 AI 客户端都可以直接使用它。
基本查询
curl -X GET "https://aws-pricing-mcp.p.rapidapi.com/ec2/pricing?instance_type=t3.medium®ion=us-east-1" \
-H "X-RapidAPI-Key: YOUR_KEY"
响应
{
"instance_type": "t3.medium",
"region": "us-east-1",
"prices": {
"on_demand_hourly": 0.0416,
"on_demand_monthly": 30.37,
"reserved_1yr_no_upfront_monthly": 24.82,
"reserved_1yr_all_upfront_monthly": 21.90,
"reserved_3yr_all_upfront_monthly": 14.60
},
"vcpu": 2,
"memory_gb": 4,
"potential_savings": {
"reserved_1yr_percent": 27.9,
"reserved_3yr_percent": 51.9
}
}
区域比较
查找任意实例类型的最便宜区域:
curl -X GET "https://aws-pricing-mcp.p.rapidapi.com/ec2/compare-regions?instance_type=m5.xlarge"
响应
{
"instance_type": "m5.xlarge",
"cheapest_region": "us-east-2",
"cheapest_price_monthly": 140.16,
"most_expensive_region": "ap-northeast-1",
"most_expensive_price_monthly": 185.04,
"potential_savings_percent": 24.2,
"all_regions": [
{"region": "us-east-2", "monthly": 140.16},
{"region": "us-east-1", "monthly": 142.08}
// …
]
}
多服务成本估算
为完整工作负载估算成本:
curl -X POST "https://aws-pricing-mcp.p.rapidapi.com/estimate" \
-H "Content-Type: application/json" \
-d '{
"region": "us-west-2",
"resources": [
{"service": "ec2", "instance_type": "t3.medium", "count": 3},
{"service": "rds", "instance_type": "db.t3.medium", "count": 1},
{"service": "s3", "storage_gb": 100}
]
}'
与 AI 代理的集成
如果你正在使用 Claude、GPT 或任何兼容 MCP 的系统进行构建,API 响应已结构化,便于解析——无需直接与 AWS 的定价 API 斗争。
示例用户提示:
“在 AWS 上运行一个包含受管数据库的 3 节点 Web 层,最便宜的方式是什么?“
支持的服务
| 服务 | 计费数据 |
|---|---|
| EC2 | 按需、预留(1 年/3 年)、Spot |
| RDS | 所有引擎,多可用区 |
| Lambda | 请求 + 持续时间 |
| S3 | 存储类别,传输 |
| DynamoDB | 按需 + 预置 |
| ECS/EKS | Fargate + EC2 启动类型 |
| ElastiCache | Redis + Memcached |
| OpenSearch | 实例 + 存储 |
| … | 共计20项服务 |
定价
| 级别 | 每月请求数 | 价格 |
|---|---|---|
| 免费 | 100 | $0 |
| 专业 | 5,000 | $49 |
| 超级 | 25,000 | $149 |
| 超大 | 100,000 | $299 |
免费层足以进行原型设计和测试。
为什么我构建了它
- AWS 的定价 API 很痛苦。 它需要复杂的过滤查询,并以针对 AWS 而非开发者优化的格式返回数据。
- AI 代理需要结构化数据。 干净的 JSON 以及可预测的模式是必不可少的——不需要 XML、HTML 抓取或“检查控制台”等变通方法。
试用
The API is live on RapidAPI:
免费套餐可用。开始无需信用卡。