mcp-slim-proxy

mcp-slim-proxy

A proxy that reduces context token waste by exposing meta-tools (search_tools, load_tool, unload_tool) so the agent loads only needed tool schemas instead of all upstream tools.

Category
访问服务器

README

mcp-slim-proxy

A client-agnostic Model Context Protocol proxy that slims the tool-definition context tax.

Every MCP tool call serializes the full tool schema into the model's context window. Wire up a dozen chatty servers and your agent spends most of its budget reading its own menu — one reported team burned 143k of a 200k token budget (72%) on tool definitions before doing any work.

mcp-slim-proxy sits between any MCP client (Claude Desktop, Cursor, a custom agent) and any number of upstream MCP servers. Instead of exposing all N servers' schemas, it exposes a handful of meta-tools:

meta-tool what it does
search_tools natural-language search over the aggregated catalog → names + one-line summaries (cheap)
load_tool pull specific tools' full schemas into the live tool list so they become callable (tools/list_changed)
unload_tool drop tools back out to reclaim context
load_bundle load a named, preconfigured group of tools at once
proxy_report live before/after token accounting

The agent searches in plain language, loads only the handful of tools it needs, and calls them — the proxy forwards each call to the owning upstream transparently. Everything else stays out of context.

The win scales with server count

The slimmed side stays ~flat (meta-tools + a small working set) while a naive aggregating proxy grows linearly. From scripts/benchmark.py (tiktoken counts):

servers tools baseline tokens slimmed tokens saved
1 10 1,384 951 31.3%
5 50 6,904 951 86.2%
10 100 13,804 951 93.1%
25 250 34,504 951 97.2%
100 1000 138,004 951 99.3%

Install

uv venv
uv pip install -e ".[tokens,http]"   # tokens = exact tiktoken counts; http = serve over HTTP

Extras: tokens (tiktoken), http (starlette+uvicorn), embeddings (sentence-transformers semantic ranker), dev (tests).

Configure

The config mirrors the familiar mcpServers block from Claude Desktop / Cursor. Both stdio and streamable-HTTP upstreams are supported.

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
    },
    "remote": {
      "url": "https://example.com/mcp",
      "headers": { "Authorization": "Bearer ${MY_MCP_TOKEN}" }
    }
  },
  "settings": {
    "compressDescriptions": true,
    "ranker": "bm25",
    "searchLimit": 8,
    "alwaysLoad": ["filesystem__read_file"],
    "bundles": { "files": ["filesystem__read_file", "filesystem__write_file"] },
    "lazyConnect": true,
    "cache": true,
    "cacheTtlSeconds": 86400
  }
}

${ENV_VAR} references are expanded so secrets stay in the environment. Add "enabled": false to keep a server in the file but skip it. The settings block is optional; every key shown is a default.

Run

As a stdio MCP server (the transport clients spawn):

mcp-slim-proxy --config config.json

Over HTTP instead (point an HTTP-capable client at http://host:port/mcp):

mcp-slim-proxy --config config.json --transport http --port 8848

Example Claude Desktop entry:

{
  "mcpServers": {
    "slim": { "command": "mcp-slim-proxy", "args": ["--config", "/abs/path/config.json"] }
  }
}

Measure the savings

Connect, print the before/after token report, and exit — no client needed:

mcp-slim-proxy --config examples/multi.config.json --report          # human
mcp-slim-proxy --config examples/multi.config.json --report --json   # for CI

The JSON report also lists connected/failed upstreams, always-loaded tools, and cross-server duplicate groups. Run the scaling table with python scripts/benchmark.py.

How it works

   client                 mcp-slim-proxy                upstream MCP servers
  ┌──────┐  stdio/http ┌──────────────────────┐  stdio/http   ┌───────────┐
  │agent │◀───────────▶│ search_tools         │◀─────────────▶│ filesystem│
  └──────┘  meta-tools │ load_tool / _bundle  │  (lazy conn)  ├───────────┤
            + loaded   │ unload_tool          │               │ gmail     │
            tools      │ proxy_report ─┐ BM25 │               ├───────────┤
                       └───────────────┴──────┘               │ remote…   │
                              catalog cache (disk)            └───────────┘
  • Aggregation — connects to every upstream as an MCP client and namespaces tools as <server>__<tool> to avoid collisions. A failed upstream is logged and skipped, not fatal.
  • Lexical search — a dependency-free BM25 index over each tool's name, description, and parameter names (camelCase / snake_case aware). Deterministic and trivially benchmarkable. An optional embeddings ranker is available via "ranker": "embeddings" + the embeddings extra.
  • Description compression — strips boilerplate ("Use this tool to…") and schema-duplicating Args:/Returns: blocks before a schema enters context. Applied only to exposed tools; the report baseline stays uncompressed so reported savings are honest.
  • Dedupe — near-identical tools across servers share a signature; search collapses them and --report --json lists the duplicate groups.
  • Lazy connect + cross-session cache — the aggregated catalog is cached to disk (keyed by the server set), so repeated sessions don't re-pay tool discovery; a server is only actually connected when one of its tools is first called. --refresh re-discovers; --clear-cache wipes it. Connection lifecycles are owned by a single host task so shutdown is clean under anyio.
  • Lazy schemas — full schemas enter context only when load_tool / load_bundle runs, which fires tools/list_changed so the client re-fetches.

Develop

uv pip install -e ".[dev,tokens,http]"
uv run pytest -q --timeout=60

Tests cover the catalog/BM25, compression, cache round-trips, config parsing, the token report, and full stdio and HTTP client loops against bundled demo servers (examples/demo_server.py, examples/db_server.py).

Roadmap

  • Embeddings ranker is wired but ships behind an extra; add a bundled small model.
  • Per-tool call metrics in the report.
  • Hot-reload of upstream tool lists on tools/list_changed from upstreams.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选