mcp审计——克劳德代码的mcp配置审计
检测并修复MCP服务器配置中的性能问题。由...建造 Gentic 人工智能.
为什么存在
我们发现ClaudeCode的MCP运行时在将工具发送到API之前不会对其进行确定性排序。MCP规范不保证 listTools() 订单。当工具顺序在两个回合之间发生变化时,它会破坏提示缓存——这会让你付出代价 API费用增加2-3倍 没有任何可见的错误。
此插件会审核您的整个MCP设置,并捕获此和其他性能杀手。
它检查什么
| 问题 | 严重性 | 影响 |
|---|---|---|
| 刀具订购不稳定 | 关键 | 每转一次提示缓存崩溃-API成本的2-3倍 |
| 重复的工具名称 | 严重 | 无声工具冲突--第二台服务器的工具被丢弃 |
| 工具数量高(>50/服务器) | 警告 | 上下文膨胀--每台服务器多出约10K个令牌 |
| 工具总数>100 | 警告 | 工具块中约有20K+个令牌--缓存和成本影响 |
| 服务器陈旧/断开连接 | 警告 | 工具调用失败,配置浪费 |
| stdio传输开销 | 信息 | 未修补版本中每轮生成的进程 |
安装
# From the Claude Code plugin marketplace
claude plugins install mcp-audit
# Or clone manually
git clone https://github.com/genticai/mcp-audit-plugin ~/.claude/plugins/installed/mcp-audit用法
快速审计
/mcp-audit生成一份健康报告,其中包含分数(0-100)、发现的问题、成本影响估计和优先修复。
应用修复程序
/mcp-fix备份您的配置,然后提供应用可自动修复的更改(禁用过时的服务器、删除重复项、减少冗余)。
深度诊断
这 mcp-health-checker 代理执行全面的连接测试、延迟测量和模式稳定性分析。当您需要更深入的调查时,它会自动可用。
自动监控
A. SessionStart 胡克每次都会进行一次快速的健康检查。只有当存在可操作的问题时,它才会发出声音——在干净的会议上没有噪音。
输出示例
## MCP Health Report
Score: 62/100 — DEGRADED
### Servers Detected
| Server | Tools | Transport | Status |
|--------|-------|-----------|--------|
| filesystem | 12 | stdio | Healthy |
| memory | 9 | stdio | Healthy |
| n8n-mcp | 34 | stdio | Healthy |
| plugin_playwright | 18 | stdio | Healthy |
| claude_ai_Supabase | 22 | sse | Healthy |
| plugin_stripe | 16 | sse | Healthy |
### Issues Found
🔴 CRITICAL: Tool ordering not deterministic
111 tools across 6 servers — ordering may change between turns.
Fix: Update Claude Code or apply the sort patch.
🟡 WARNING: Total tool count is 111 (>100)
Estimated tools block: ~22,200 tokens.
Fix: Use project-level .mcp.json to load only relevant servers.
🟡 WARNING: n8n-mcp has 34 tools
Consider splitting into domain-specific servers.
### Prompt Cache Impact
- Estimated waste per 20-turn session: ~421,800 tokens ($1.27)
- Monthly estimate (100 sessions/day): $3,800
- Fix tool ordering → saves $2,850/month
- Reduce to 50 tools → saves additional $570/month
### Recommendations
1. Apply tool sorting fix (or update Claude Code when patched)
2. Create project-level .mcp.json files to scope servers
3. Consider splitting n8n-mcp into smaller servers技术细节
提示缓存错误
createBundleMcpToolRuntime Claude Code通过以下方式收集工具 client.listTools() 无需排序。工具数组成为API请求的缓存键的一部分。当订单在轮次之间发生变化时,缓存会丢失,您需要为整个工具块支付全价。
修复 (一行):
tools: tools.toSorted((a, b) => a.name.localeCompare(b.name))会话范围优化
除了排序之外,每次都会重新创建运行时——生成stdio传输,调用listTools(),然后处理。在会话范围内缓存运行时(基于配置哈希)将完全消除这种开销。
由...建造
Gentic 人工智能 --为在自动化上运行的企业优化人工智能基础设施。
许可证
麻省理工学院
