MCP proxy that collapses 50+ tools into 4 meta-tools and compresses tool outputs by 60-95% (HTML, base64, huge JSON) - cut context-token costs for any MCP client, any model
Context Firewall
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
中文文档
**Shrink large MCP tool outputs by 60–95% before they reach your model's context window — and collapse 50+ tool definitions into 4.** Real HTML/JSON, measured — see benchmarks. Works with any MCP client, any model. Anything still over your configured token budget after compression is hard-truncated to that budget, with the full original always retrievable via read_more.
*The session report printed on shutdown — this one from a real 3-call session (two large file reads, one echo). Every number measured, none simulated.*
Context Firewall is a local MCP proxy that sits between your AI agent (Claude Code, Claude Desktop, Cursor, Cline, ...) and every downstream MCP server you've configured. Large tool outputs (raw HTML, base64 blobs, giant JSON) are compressed before they ever reach the model's context window, and the client sees exactly 4 tools no matter how many the downstream servers actually have.
Measured results
| Metric | Result |
| --- | --- |
| Output compression | **70–94%** on real HTML pages, **~97%** on large structured JSON (smart stages alone, before budget truncation) — e.g. a live Wikipedia page via the fetch tool: 232,391 → 6,907 chars (**97.0%**, measured); a GitHub issues JSON payload via the jsonSummary stage: 186,810 → 3,480 chars (**98.1%**, measured) |
| Tool collapse | **122 → 4** exposed meta-tools (5 real downstream servers incl. official GitHub github-mcp-server, 85 tools) |
| Tool-definition savings | **~28,600 tokens** *(estimated, chars ÷ 3.5)* — 102,158 raw definition chars vs. 2,146 exposed |
All figures measured against real downstream MCP servers, not synthetic data — full methodology and tables in docs/BENCHMARKS.md.
What it does
- **Progressive tool disclosure** — instead of loading every downstream tool's full schema at startup, the client sees 4 meta-tools (list_tool_categories, search_tools, invoke_tool, read_more) and only pays the token cost of a tool's full schema when it actually searches for it.
- **Output compression pipeline** — large tool results are run through base64 stripping, main-content extraction + HTML→Markdown conversion (page chrome — nav, site headers/footers — is stripped when the page has a recognizable content region, so your token budget goes to actual content instead of navigation links), JSON structure-aware summarization, and finally character-budget truncation, in that order, before being returned.
- **Full output retrievable via read_more** — nothing is silently thrown away. Every compressed output is stored in full (in memory, opaque handle) and can be paged back with read_more(handle, offset, length).
- **Session savings report** — on shutdown, prints a shareable terminal card (and optional Markdown file) showing tool-definition and output-token savings for the session, plus a breakdown of which tools saved the most.
Quickstart
Minimal context-firewall.json (the downstreams block mirrors the mcpServers format you already know):
(${GITHUB_TOKEN} above is just this example's environment variable *name* — pick whatever's already set in your shell; it gets expanded into GITHUB_PERSONAL_ACCESS_TOKEN, the env var name the downstream server itself actually reads.)
**Which GitHub server?** Two options, different tool counts:
- **@modelcontextprotocol/server-github** (used above) — the original npm package, 26 tools, one npx -y line, zero extra setup. Archived/no longer maintained upstream, but still functional.
- **github/github-mcp-server** — the actively-maintained official server, 44 tools (default toolset) to 85 (GITHUB_TOOLSETS=all). Ships as a Go binary or Docker image, not an npm package:
or, running a locally-built/downloaded binary directly: "command": "/path/to/github-mcp-server", "args": ["stdio"] (same env block; add GITHUB_TOOLSETS to scope which of the 85 tools are exposed).
**Per-tool allow/deny policy.** Add allowTools/denyTools (array of exact names or * globs) to any downstream entry to restrict which of its tools can be invoked: