mcp成本计算器
估计使用多个MCP服务器时的LLM令牌成本。
受启发于 @JThreeDot的见解 同时连接多个MCP服务器会增加LLM成本——每个工具定义都会在每个请求时注入上下文。
安装
npm install -g mcp-cost-calculator或者直接运行:
npx mcp-cost-calculator ./your-config.json用法
# Analyze your Claude Desktop config
mcp-cost ~/.claude/claude_desktop_config.json
# Or any MCP config file
mcp-cost ./mcp-config.json输出
╔══════════════════════════════════════════════════════════════╗
║ MCP Cost Calculator ║
╚══════════════════════════════════════════════════════════════╝
Config: claude_desktop_config.json
Servers: 5
┌─────────────────────────────────────────────────────────────┐
│ Server Overhead Breakdown │
├────────────────────────────┬──────────┬─────────────────────┤
│ Server │ Tools │ Est. Tokens │
├────────────────────────────┼──────────┼─────────────────────┤
│ filesystem │ 11 │ 3,400 │
│ github │ 25 │ 10,100 │
│ postgres │ 8 │ 3,300 │
│ brave-search │ 2 │ 700 │
│ memory │ 4 │ 1,100 │
└────────────────────────────┴──────────┴─────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Cost Per Request (MCP overhead only) │
├─────────────────────────┬───────────────┬───────────────────┤
│ Model │ Per Request │ Monthly (100/day) │
├─────────────────────────┼───────────────┼───────────────────┤
│ gpt-4o │ $0.0466 │ $139.80 │
│ claude-3.5-sonnet │ $0.0559 │ $167.76 │
│ claude-3-opus │ $0.2796 │ $838.80 │
└─────────────────────────┴───────────────┴───────────────────┘
💡 Tip: You have many MCP servers connected. Consider using a
proxy server pattern to reduce context overhead.运作原理
该工具分析您的MCP配置,并根据以下内容估算令牌开销:
- 每台服务器的工具数量
- 工具名称和描述长度
- 输入模式复杂性(属性、类型、必填字段)
对于没有明确工具定义的服务器,它使用基于已知MCP服务器模式的合理估计。
为何这很重要
每次请求时,每个MCP工具定义都会被注入到LLM上下文中。连接5-10台服务器后,您可以轻松添加15-30K的开销令牌——甚至在发送实际提示之前。
按照Claude Opus的费率(15美元/M输入),仅在MCP开销中,每个请求约为0.45美元。每天100个请求=每月1350美元的纯管理费用。
解决方案
- 使用更少的服务器 --仅连接当前任务所需的内容
- 代理服务器模式 --使用单个MCP服务器,按需代理其他服务器
- 动态加载 --根据对话上下文加载/卸载服务器
许可证
麻省理工学院
