mcp-lazy-proxy
mcp-lazy-proxy
将 MCP 工具 schema 的 token 开销降低 6-7x — 通过懒加载与 schema 缓存实现。
实测验证,而非空口宣称。 每次会话都会将证明日志写入
~/.mcp-proxy-metrics.jsonl。 运行mcp-lazy-proxy --report即可查看你的真实节省量,而非营销估算。
⚠️ 安全提示:npm 上唯一官方包是由
kiraautonoma发布的mcp-lazy-proxy。其他作用域下的第三方 fork 或重新打包均未获认可,且可能包含恶意代码。MCP 服务器拥有广泛的系统访问权限 — 请始终从官方源安装。
问题
如果你使用多个 MCP 服务器,你的工具定义会在每次 API 调用时消耗数千个上下文窗口 token — 甚至在你提出问题之前。
以 10 个服务器 × 10 个工具 × ~344 tokens/schema 计算,每次调用产生 34,000 tokens 开销。 按 $3/MTok(Claude Sonnet)计算:每次调用浪费 $0.10,每天 100 次调用相当于每月浪费 $261。
Related MCP server: MCP Nexus
解决方案
该代理位于你的 MCP 客户端与上游 MCP 服务器之间。它不再预先发送完整的工具 schema,而是:
返回压缩的存根(stub) — 仅包含工具名称和一行描述(每个 ~54 tokens)
懒加载完整 schema — 仅在工具实际被调用时加载
将 schema 缓存到磁盘 — 后续调用直接命中缓存,而无需访问上游服务器
去重 — 不同服务器间的相同 schema 只存储一份
基准测试(真实数据)
服务器 | 工具数 | 预加载 Token 数 | 懒加载 Token 数 | 降幅 | 每月节省* |
1 | 10 | 3,555 | 550 | 6.5x | $27 |
3 | 30 | 11,140 | 1,620 | 6.9x | $86 |
5 | 60 | 20,607 | 3,224 | 6.4x | $156 |
10 | 100 | 34,360 | 5,350 | 6.4x | $261 |
10 | 200 | 71,583 | 10,790 | 6.6x | $547 |
15 | 225 | 81,460 | 12,115 | 6.7x | $624 |
20 | 200 | 71,997 | 10,760 | 6.7x | $551 |
*按 $3/MTok 输入价格、每天 100 次 API 调用计算
快速开始
npm install -g mcp-lazy-proxy包装单个 MCP 服务器
mcp-lazy-proxy --server "fs:stdio:npx:-y:@modelcontextprotocol/server-filesystem:/home"通过配置包装多个服务器
{
"servers": [
{
"id": "filesystem",
"name": "Filesystem MCP",
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home"]
},
{
"id": "github",
"name": "GitHub MCP",
"transport": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"]
}
],
"mode": "lazy"
}mcp-lazy-proxy --config proxy.json与 Claude Desktop 配合使用
{
"mcpServers": {
"proxy": {
"command": "mcp-lazy-proxy",
"args": ["--config", "/path/to/proxy.json"]
}
}
}模式
模式 | 描述 | Token 节省 |
| 首次使用工具时加载 schema(默认) | ~85% |
| 从不发送完整 schema(节省最大化) | ~85% |
| 预先加载所有 schema(无节省,仅调试) | 0% |
E2E 测试结果
针对官方 @modelcontextprotocol/server-filesystem(14 个工具)进行了测试:
✅ Initialize response: mcp-context-proxy
✅ Got 14 tools — 14/14 have lazy-load stubs
✅ Tool call (read_file) succeeded — file content correct
✅ Tool call (list_directory) succeeded
Token comparison: ~2800 eager vs ~832 lazy stubs (3.4x on this small server)当服务器数量达到 10 个以上时,随着 schema 复杂度的增长,降幅提升至 6-7x。
API(编程方式使用)
import { MCPContextProxy } from 'mcp-lazy-proxy';
const proxy = new MCPContextProxy({
servers: [
{ id: 'fs', name: 'Filesystem', transport: 'stdio',
command: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'] }
],
mode: 'lazy'
});
await proxy.start();可验证的节省证明
与其他仅展示估算值的 MCP 优化器不同,mcp-lazy-proxy 会记录每一次交互:
# See your actual savings (not estimates)
mcp-lazy-proxy --report原始证明保存在 ~/.mcp-proxy-metrics.jsonl — 每次工具调用对应一行 JSON,完全可审计。
对比
特性 | mcp-lazy-proxy | Atlassian mcp-compressor |
语言 | Node.js/npm | Python/pip |
机制 | 调用时懒加载 | 描述压缩 |
Schema 缓存 | ✅ 磁盘(24 小时 TTL) | ❌ |
证明记录 | ✅ 可审计 JSONL | ❌ |
响应压缩 | ✅ JSON 摘要 + 文本截断 | ❌ |
托管选项 | 🔜 计划中 | ❌ |
响应压缩(v0.2)
大型工具调用响应在到达 LLM 之前会自动压缩:
JSON 响应:摘要化 — 数组截断为前 3 项并注明总数,长字符串缩短,完整结构保留
纯文本:截断至 10,000 字符,并附
[truncated, X chars total]说明错误响应:从不压缩(LLM 需要完整的错误上下文)
可配置:在配置中设置
responseCompression: false即可禁用,或微调阈值
{
"servers": [...],
"mode": "lazy",
"responseCompression": {
"enabled": true,
"maxTextLength": 10000,
"minCompressLength": 1000,
"maxArrayItems": 3
}
}状态
核心懒加载代理(v0.1)
Schema 持久化缓存(24 小时 TTL)
可验证的每会话节省证明
用于审计节省量的
--reportCLI已使用真实 MCP 服务器进行 E2E 测试
响应压缩(v0.2)
HTTP/SSE 传输支持
Schema 变更检测(webhook)
托管 SaaS 选项
许可证
MIT — 由 Kira(一个自主 AI 代理)构建。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnterprise-grade dynamic MCP proxy that eliminates token bloat by lazy-loading tool schemas based on semantic intent, enabling efficient orchestration of multiple backend tools from a single endpoint.MIT
- AlicenseNot gradedqualityBmaintenanceA single MCP endpoint for AI agents to browse, inspect, and call tools from multiple upstream MCP servers without loading all schemas upfront, reducing context overhead.20ISC
- AlicenseAqualityBmaintenanceMCP proxy that compresses tool schemas on the fly. Up to 98% token reduction, 100% signal preserved verified after every compression. Zero LLM calls, fully deterministic.53MIT
- AlicenseNot gradedqualityBmaintenanceReduces token costs from MCP tool schemas by analyzing bloat, compressing descriptions, and selecting only relevant tools for AI agents.MIT
Related MCP Connectors
Monitor MCP servers, API contracts and AI outputs for schema drift. Alerts on breaking changes.
Remote MCP for GenAI span mapping, provider normalization, dashboard schemas, and receipts.
Paid remote MCP for schema drift checks, approvals, receipts, and release audit logs.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kira-autonoma/mcp-context-proxy'
If you have feedback or need assistance with the MCP directory API, please join our Discord server