MCP ToolGate
by ldxm666
README.md
<div align="center">
<img src="./assets/banner.svg" alt="MCP ToolGate Banner" width="100%" />
<br/>
[](https://github.com/ldxm666/mcp-tool-gate/releases/tag/v1.0.0)
[](https://nodejs.org)
[](#)
[](./LICENSE)
**English** · [简体中文](./README.zh-CN.md)
</div>
---
## Why MCP ToolGate?
Modern AI coding & reverse-engineering agents (DSH, Claude Code, Codex, Antigravity, Cursor, Cline, Windsurf, OpenCode) suffer from **severe MCP context bloat**: attaching large toolboxes like `rea` (207 tools ≈ 45K tokens), `ppt-mcp` (156 tools), `agent-desktop` (75 tools), `ida` (65 tools), or `android-root-mcp` (57 tools) injects **100K–250K tokens of tool schemas into every single turn** and spawns heavy JVM/Python/Node processes at startup — even when 98% of those tools aren't needed.
**MCP ToolGate** solves this for **any MCP-compatible agent** with a single ultra-lightweight gateway:
| Metric (Real 22-Server Benchmark) | Raw Direct MCPs | Via MCP ToolGate |
| :--- | :---: | :---: |
| Tools injected at startup | **828 tools** | **6 meta-tools** |
| Startup context overhead | **~134,744 tokens** (498 KB) | **~1,145 tokens (`-99.1%`)** |
| Backend processes spawned at boot | All 22 servers | **0** (lazy-spawn + idle reaper) |
| Active task (1–4 domain tools open) | 134,744 tokens | **~1.2K–1.8K tokens (`-98.6%`)** |
---
## How It Works
```mermaid
flowchart LR
A[Task Start] --> B[tool_search / tool_catalog<br/>Offline CN+EN BM25 <5ms]
B --> C[Analyze Minimal Tool Set]
C --> D["tool_open(replace=true)<br/>Open ONLY needed tools<br/>Close all others"]
D --> E[Execute Native Tools<br/>or tool_call Fallback]
E -->|Progress Stuck / New Layer| F[tool_search Blocker Keywords]
F --> G["tool_open(replace=false)<br/>Incrementally Add Tools"]
G --> E
E -->|Task Done / Topic Switch| H["tool_close(all=true)<br/>Reclaim Tokens & RAM"]
```
### Key Highlights
- **Universal & Zero-Dependency**: Pure Node.js ESM (`>= 18`) standard MCP stdio gateway supporting both **Stdio** and **Streamable HTTP** backends. Works out of the box with DSH, Claude Code, Codex, Antigravity, Cursor, Cline, and any custom MCP host.
- **Dual Mode (`dynamic` + `proxy`)**:
- `dynamic` *(default — best for DSH, Claude Code, Cursor, Cline)*: emits MCP `notifications/tools/list_changed` on `tool_open` / `tool_close` so hosts dynamically hot-swap native tools, while keeping `tool_call` as a universal fallback.
- `proxy` *(best for KV-cache lock, Antigravity, Codex)*: `tools/list` never mutates (always only 6 meta-tools = **100% KV-cache hit rate**); opened tools run cleanly through `tool_call`.
- **Smart Auto-Grouping & Bilingual Search**: Automatically splits giant 200-tool servers (like `rea`, `ida`, `burpsuite`, `android_root`, `agent_desktop`, `x64dbg`) into small 5–20 tool capability groups (`rea/native-static`, `rea/android-static`, `rea/frida-dynamic`, etc.) with offline Chinese + English BM25 + synonym expansion (`< 5ms`).
- **Automatic Prerequisite Injection**: Stops blind-call failure loops (e.g., opening `rea:procedure_pseudo_code` automatically pulls `rea:open_binary` & `rea:binary_session`; `dexkit` pulls `dexkit_open`; `dexsql` pulls `open_dataset`; `ida` pulls `idb_open`).
- **Built-in Provider Schema Sanitizer**: Automatically strips lone-surrogate regexes (such as `^[^\uD800-\uDFFF]*$` that trigger DeepSeek API `400 Invalid Schema`) and flattens nullable `anyOf`/`oneOf` unions from FastMCP/Pydantic servers.
- **One-Click Auto-Import, Safe Backup & Local Web UI**: Discovers existing MCP servers across DSH, Antigravity, Codex, Claude, and Cursor; includes a built-in zero-dependency Web Dashboard (`toolgate ui`) to inspect token savings, test search, and watch live sessions.
---
## The 6 Meta-Tools
| Tool | Purpose |
| :--- | :--- |
| `tool_catalog` | Browse servers, capability groups, tool counts, token costs, and currently open tools. |
| `tool_search` | Bilingual (CN + EN) offline BM25 search with domain synonyms & prerequisite hints. |
| `tool_open` | Open specific `tools`, `groups`, or `servers`. `replace=true` closes all others; `replace=false` expands mid-task. |
| `tool_close` | Close specific tools/groups/servers or `all=true` (optionally `stop_servers=true` to free RAM). |
| `tool_inspect` | Inspect full sanitized JSON schemas & prerequisites of specific tools without opening a whole server. |
| `tool_call` | Direct invocation proxy (`server:tool_name`) — primary executor in `proxy` mode and fallback in `dynamic` mode. |
---
## Quick Start
```bash
git clone https://github.com/ldxm666/mcp-tool-gate.git
cd mcp-tool-gate
# 1. Auto-import existing MCP configs (read-only) from DSH / Antigravity / Codex / Claude / Cursor
node bin/toolgate.mjs import all
# 2. Index all tool schemas offline into data/state/catalog.json
node bin/toolgate.mjs sync
node bin/toolgate.mjs stats
# 3. Test bilingual search offline
node bin/toolgate.mjs search "decompile binary pseudocode xrefs"
node bin/toolgate.mjs search "逆向安卓 APK 查类"
# 4. Launch local Web Dashboard (http://127.0.0.1:18923)
node bin/toolgate.mjs ui
```
> Or manually create `data/config/servers.json` from [`examples/servers.example.json`](./examples/servers.example.json).
---
## Connect to Any Agent
Print ready-to-paste snippets for every agent (plus a portable `AGENTS.md` / `CLAUDE.md` rule):
```bash
node bin/toolgate.mjs install --agent all
```
Install the portable `toolgate-router/SKILL.md` across your agents so models automatically follow the **Search → Minimal Open → Re-Search When Stuck** loop:
```bash
node bin/toolgate.mjs install --skill
```
Apply automatically with timestamped backup (and rollback anytime via `restore`):
```bash
# DSH (DeepSeek Harness) — Solo mode disables raw direct MCP servers & keeps ToolGate active
node bin/toolgate.mjs install --agent dsh-web --apply --solo --skill
# Antigravity / Codex (recommended with --mode proxy for 100% KV-cache stability)
node bin/toolgate.mjs install --agent antigravity --apply --solo --mode proxy
node bin/toolgate.mjs install --agent codex --apply --mode proxy
```
**Single-Server Wrapper Mode** (wrap just one huge MCP server such as `rea`):
```bash
node bin/toolgate.mjs serve --wrap rea
```
---
## CLI Reference
| Command | Description |
| :--- | :--- |
| `serve [--mode dynamic\|proxy] [--wrap <name>] [--strict]` | Run the MCP stdio gateway server. |
| `import [all\|dsh\|antigravity\|codex\|claude\|cursor] [--file <path>]` | Import backend MCP servers into `data/config/servers.json`. |
| `sync [--server <name>] [--concurrency 4] [--timeout 25000]` | Probe backends, sanitize schemas, auto-group, and cache `catalog.json`. |
| `stats [--server <name>]` | Show per-server tool counts, schema KB, token footprint & savings. |
| `search <query> [--server <name>] [--top 15]` | Test bilingual search and prerequisite resolution in CLI. |
| `install [--agent ...] [--mode ...] [--apply] [--solo] [--skill]` | Print or safely apply agent configs + install portable Skill. |
| `restore <backup-file> <target-file>` | Roll back any modified host config from `data/backups/`. |
| `ui [--port 18923]` | Start the local interactive Web Dashboard. |
| `doctor` | Verify runtime, catalog freshness, and server health. |
---
## Development & Tests
```bash
npm test
```
## License
[MIT](./LICENSE) © 2026 [ldxm666](https://github.com/ldxm666)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues