
Context Firewall
io.github.Alepha188838884由 GitHub 帳號 Alepha188838884 發布v0.1.1更新於 Oct 24, 2026
Local MCP proxy: collapses N servers' tools into 4 meta-tools and compresses large tool outputs.
概覽
本機 MCP 代理:把多個下游 MCP 伺服器的工具收斂成 4 個中繼工具,並在工具輸出進入模型上下文前先行壓縮。
- 可以做什麼
- 檢視已連線的下游伺服器及其工具分類,並依需求搜尋下游工具以取得完整 schema,而非在啟動時全部載入(list_tool_categories、search_tools)。透過單一閘道呼叫任一下游工具,並在搜尋與呼叫時執行各伺服器的允許/拒絕策略(invoke_tool)。透過不透明代碼分頁取回任何被壓縮輸出的完整原文(read_more)。壓縮大型結果:剝除 base64、擷取 HTML 正文並轉為 Markdown、對 JSON 結構做摘要、依 token 預算截斷。結束時輸出本次工作階段的估算 token 節省報告,可選擇寫入 Markdown 檔案。
- 適用情境
- 當你設定了多個 MCP 伺服器,其工具定義總量與體積龐大的輸出(原始 HTML、base64 資料塊、大型 JSON)佔用上下文視窗時適用。它應取代你現有的伺服器項目,而非與之並列,因為工具收斂與壓縮效益只在其作為用戶端唯一 MCP 伺服器時才會發揮。
- 執行需求
- 透過 npx 以 stdio 程序在本機執行,需要 Node.js。需要一份 JSON 設定檔列出下游伺服器(stdio 指令或 Streamable HTTP 網址),並以 --config 參數傳入。下游伺服器可能需要各自的憑證,在設定中以環境變數名稱引用。選用的 LLM 摘要階段需要 OpenAI 相容端點與 API 金鑰。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Context Firewall,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Context Firewall
[npm] [CI] [license] [Glama score]
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
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 withread_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, onenpx -yline, 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"](sameenvblock; addGITHUB_TOOLSETSto 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:
Deny always wins over allow. When allowTools is set, only matching tools are permitted; everything else on that server is blocked. An empty allowTools: [] is treated the same as omitting it (allow everything), not "deny everything". Blocked tools are hidden from search_tools results, and invoke_tool rejects them before dispatching to the downstream server. Tool counts in list_tool_categories and in the meta-tool descriptions are unfiltered totals — the policy is only enforced at search_tools/invoke_tool time.
Client setup
Set Context Firewall as your only MCP server — move every downstream server you currently configure directly (filesystem, github, everything, ...) into context-firewall.json's downstreams block instead. Your agent then sees 4 tools instead of the sum of every downstream server's tool count; pointing the client at Context Firewall alongside your existing servers doesn't give you the tool-collapse or compression benefit.
Each client below takes the same server entry:
Claude Code
Project-scoped .mcp.json in your repo root (shown above), or via the CLI:
Claude Desktop
claude_desktop_config.json (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json; Windows: %APPDATA%\Claude\claude_desktop_config.json) — same mcpServers block as above.
Cursor
.cursor/mcp.json (project-scoped) or ~/.cursor/mcp.json (global) — same mcpServers block as above.
Cline
cline_mcp_settings.json (VS Code extension storage; macOS: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json) — same mcpServers block as above.
Compatibility status
* Verified via MCP protocol integration tests (236 automated tests, including full stdio protocol round-trips against real downstream servers, run in CI on every push). Real-client reports welcome.
Configuration
downstreams
Each entry is either a stdio server (same shape as mcpServers) or a Streamable HTTP server:
${VAR_NAME} in any string value is expanded from the environment; a missing variable fails config load with a readable error.
compression
Policy resolution order is default < perServer < perTool (later overrides earlier, field by field):
report
callToolTimeoutMs
Top-level (not nested under compression). Per-invoke_tool timeout in milliseconds passed to the downstream MCP SDK client; a downstream that hangs without responding causes invoke_tool to return an isError result once this elapses, instead of blocking. Defaults to the SDK's own default (60,000ms) when unset.
How it works
The client calls list_tool_categories() to see what's connected and what it's roughly capable of, search_tools(query) to pull the full input schema for candidate tools, invoke_tool(server, tool, args) to actually run one (compressed on the way back), and read_more(handle, offset, length) to page through anything that got compressed. Compression, when it runs, always applies in the same order: strip base64 → main-content extraction + HTML to Markdown → JSON structure summary → truncate to budget (if the opt-in LLM summarization stage below is enabled, it runs right before truncation). Content extraction is conservative by design: it only strips chrome when a semantic content region (<article>/<main>) is recognizable or the removal clearly isn't the page's actual content, and falls back to whole-page conversion otherwise — the full original is always retrievable via read_more either way. Security-relevant outputs (errors, permission/warning/confirmation messages) are never silently compressed - they pass straight through, only hard-capped at 50,000 characters to prevent a single runaway error dump from blowing out the caller's context.
LLM summarization (opt-in)
The deterministic pipeline can strip markup, collapse repetitive structure, and truncate - but it cannot semantically compress a long natural-language output (a log file, an article, a report): once the deterministic stages are done, anything still over budget just gets cut off. This optional stage fills that gap: it sends the over-budget text to a model of your choice for a factual summary (preserving IDs, paths, URLs, numbers, and error messages), appends a read_more pointer to the untouched full original, and leaves truncation in place as the final backstop. It is off by default and requires explicit opt-in at two separate layers: a top-level llm block and llmSummary: true in a compression policy. Any OpenAI-compatible /chat/completions endpoint works - pick a provider preset or point baseUrl at anything else.
provider is shorthand for a preset base URL plus a conventional API-key environment variable:
Any other OpenAI-compatible endpoint works via baseUrl instead (then apiKey is required):
Example with OrcaRouter - works well with free models (orcarouter/free is their difficulty-routed free tier; the API key is read from ORCAROUTER_API_KEY):
Runnable full examples: examples/config.llm-orcarouter.json and examples/config.llm-generic.json.
Failure mode: if the endpoint is down, unreachable, times out, or returns anything malformed, the stage silently no-ops and the output falls back to deterministic truncation - an unavailable endpoint never breaks your tools.
Privacy: enabling this sends over-budget, non-security-sensitive tool outputs to the endpoint you configure - and nothing else, nowhere else. Security-sensitive outputs (errors, permission denials, warnings, confirmations) bypass the compression pipeline before this stage exists and are never sent. Don't enable this if sending tool output content to that endpoint is not acceptable for your data.
Disclosure
Context Firewall participates in the OrcaRouter Open Source Program: if you choose OrcaRouter as your endpoint, this project receives 5% of the resulting usage revenue. This does not change your pricing, is entirely optional, and any OpenAI-compatible provider works identically.
Positioning
Context Firewall complements Anthropic's Tool Search Tool, it doesn't compete with it. Tool Search solves tool definition bloat at startup (the schemas loaded into context before any tool is even called), and is Claude-specific. Context Firewall compresses tool outputs at call time - the half of the problem Tool Search doesn't touch - and works with any MCP client and any model, not just Claude.
A note on token counts
Every token count in this project (truncation budgets, the session report) is estimated as chars / 3.5, never an exact model-specific count. By default, there is no code path that sends your tool output content to an external API - not for token counting, not for anything else. If you explicitly enable the optional LLM summarization stage, over-budget outputs are sent to the endpoint you configure - and nothing else, nowhere else; token counting stays local either way. The session report is always labeled "(estimated)" for this reason.
Safety
- Tool arguments and output content are never written to logs or the session report - only server/tool names and character/token counts.
- Security-relevant outputs (errors, permission denials, warnings, confirmations) are never silently compressed.
- By default, tool output content never leaves your machine (beyond the downstream servers you configured). The opt-in LLM summarization stage is the only code path that can send it anywhere else, it is off by default, and security-sensitive outputs never reach it.
- Downstream tool descriptions are treated as untrusted input and only ever displayed, never executed.
- Downstream tool descriptions are passed through verbatim, unsanitized -
search_toolsdoes not strip or filter prompt-injection text a malicious downstream might put there. The trust boundary is which downstream servers you choose to configure, not this gateway. - Progressive disclosure has a real tradeoff: tool descriptions arrive on demand, mid-session, right when the calling model actively asks for them via
search_tools- which is also when a model is least likely to scrutinize an embedded instruction, compared to tools all being presented up front at session start. As of v0.3.0 this is mitigated two ways:search_toolsresults are wrapped in<untrusted-tool-descriptions nonce="...">...</untrusted-tool-descriptions nonce="...">delimiters carrying a random nonce generated once per process at startup (crypto.randomBytes(8).toString('hex'), fixed for the process's whole lifetime), with a note telling the model that only a closing tag carrying the matching nonce ends the block; and the CLI prints a human-readable digest to stderr on startup (server names, tool counts, top categories) so an operator can see at a glance what actually got connected. The nonce specifically defeats the literal bypass where a downstream embeds its own</untrusted-tool-descriptions>string followed by forged "trusted system" instructions in its description - it can't predict the nonce, so it can't forge a matching closing tag. Residual risk: this is still a text-level convention, not a sandbox - it depends on the calling model actually reading the note and honoring the nonce match; nothing stops a model from ignoring the framing altogether. Neither mitigation sanitizes the description content itself - see the point above. The delimiter framing now costs about 80-85 tokens persearch_toolscall (~289 characters, at this project's chars/3.5 estimate). - The categories shown by
list_tool_categoriesare also derived from downstream-supplied data (tool names, via a crude verb-prefix heuristic inregistry.ts) - but a tool name is a far lower-bandwidth channel for smuggling instructions than a free-text description, and this output isn't wrapped in the delimiters above. Treat it as lower-risk thansearch_toolsoutput, not risk-free.
License
MIT
來源:README.md,提交 5c0f3fc
工具
0版本歷史
1- v0.1.1最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分