Skip to main content
Glama
README.md
<div align="center">

![mcpfold — Fold MCP Schemas, 30k Outputs & 4 Turns Into 1](./docs/images/hero-banner.jpg)

# mcpfold

**Native Tool Search only hides MCP schemas. `mcpfold` folds BOTH bloated schemas AND 30k-token JSON responses, chains multi-tool workflows into 1 turn, redacts leaked secrets, and compiles any MCP server into a standalone zero-dep CLI + `SKILL.md`.**

[![License: MIT](https://img.shields.io/badge/license-MIT-22C55E?style=flat-square&labelColor=0F172A)](./LICENSE)
[![Node.js >= 20](https://img.shields.io/badge/node-%3E%3D20-22C55E?style=flat-square&logo=node.js&logoColor=white&labelColor=0F172A)](https://nodejs.org/)
[![Runtime Deps: 0](https://img.shields.io/badge/runtime_deps-0-38BDF8?style=flat-square&labelColor=0F172A)](#architecture)
[![Clients](https://img.shields.io/badge/clients-Claude%20Code%20%C2%B7%20Antigravity%20%C2%B7%20Cursor-A855F7?style=flat-square&labelColor=0F172A)](#quickstart-by-client)
[![Agent Skills](https://img.shields.io/badge/Agent_Skills-SKILL.md-FACC15?style=flat-square&labelColor=0F172A)](./SKILL.md)

[Quick Start](#-30-second-quickstart) · [Live Demo](#-live-terminal-demo) · [Benchmarks](#-verified-benchmarks) · [Why Not Tool Search?](#-raw-mcp-vs-tool-search-vs-mcpfold) · [Clients](#-quickstart-by-client) · [Architecture](#-architecture)

</div>

---

## 🎯 Why `mcpfold`?

Developers keep running into the exact same wall with MCP: enabling GitHub, Playwright, Postgres, or Linear burns **35,000–60,000+ tokens** before you even type a prompt, and **even after Claude Code and Cursor added deferred Tool Search, 3 huge bottlenecks remain broken**:

1. **Tool Output Explosion:** A single `list_issues`, `query_rows`, or `browser_snapshot` call still dumps **10k–30k tokens of raw noisy JSON** back into your context window.
2. **Slow Multi-Turn Round-Trips:** Fetching a list, inspecting one record, reading comments, and summarizing wastes **4 separate slow LLM turns**, re-sending context every round-trip.
3. **Zero Output Security + Startup Lag:** Community MCP responses pass raw API tokens (`ghp_`, `sk-`) or hidden prompt injections straight to your model, while cold-starting multiple child servers eats seconds and RAM on every session.

**`mcpfold` fixes all of them locally in 0 dependencies (`MIT`, no paid API keys):**

| Metric (48-Tool Enterprise Fixture) | Raw MCP | With `mcpfold` | Savings |
| --- | ---: | ---: | ---: |
| Upfront schema tokens (`48` tools) | 13,889 | **609** | **-95.6%** |
| Compiled CLI + `SKILL.md` mode (`eject`) | 13,889 | **2,419** | **-82.6%** |
| 4-step workflow LLM round-trips (`pipe_tools`) | 4 turns | **1 turn** | **-75.0%** |
| Tool output payload tokens (`fields` + compactor) | 5,986 | **91** | **-98.5%** |
| **End-to-end 4-step session total** | **61,542** | **700** | **-98.9%** |
| Cold proxy startup (`sync` cached catalog) | Spawns all servers | **5.41 ms** | **0 startup spawns** |
| Security guard (secrets & prompt injections) | 0 caught | **3 secrets / 1 flagged** | **Protected** |

> Reproduce every single number on your own laptop in 3 seconds: `npx mcpfold bench`

---

## 🎬 Live Terminal Demo

<div align="center">

![mcpfold Animated CLI Demo — audit, bench, eject](./docs/images/mcpfold-demo.gif)

</div>

---

## 📊 Verified Benchmarks & Token-Burn Graph

<div align="center">

![Cumulative Session Token Burn Graph](./docs/images/token-graph.svg)

<br />

![mcpfold Verified Benchmark Card](./docs/images/benchmark-card.svg)

</div>

---

## ⚖️ Raw MCP vs. Native Tool Search vs. `mcpfold`

| Capability | Raw MCP | Native Tool Search | `mcpfold` |
| --- | :---: | :---: | :---: |
| Hides bloated input schemas (`-95.6%`) | ❌ | ✅ | ✅ |
| Works uniformly on **Claude Code, Antigravity & Cursor** | ✅ | Claude/select harnesses | ✅ |
| **1-turn sandboxed chaining (`pipe_tools`: 4 turns → 1)** | ❌ | ❌ | ✅ |
| **Dot-path `fields` projection + output token budget (`-98.5%`)** | ❌ | ❌ | ✅ |
| **Compile any MCP → standalone zero-dep CLI + `SKILL.md` (`eject`)** | ❌ | ❌ | ✅ |
| **Secret redaction (`ghp_`, `sk-`, `Bearer`, PEM) & injection shield** | ❌ | ❌ | ✅ |
| **`<10 ms` cached cold boot + lazy server spawning** | ❌ | Client-dependent | ✅ |
| **1-command multi-client X-Ray (`audit` SVG + HTML dashboard)** | ❌ | ❌ | ✅ |

---

## 🏗 Architecture

![mcpfold Two-Way Compiler and Execution Architecture](./docs/images/architecture.svg)

- **Cached Catalog (`sync`):** Probes downstream stdio servers once and caches schemas cleanly in `.mcpfold/catalog.json`. Proxy boot takes **~5.4 ms** with **0 spawned child processes** until a tool on that server is actually called.
- **BM25 + Developer Synonym Search:** Offline intent matcher splits `camelCase`/`snake_case` and resolves dev synonyms (`"create pr"` → `open_pull_request`, `"db query"` → `postgres.query_rows`).
- **Two Modes You Can Switch Anytime:**
  - **`mcpfold serve` (Folded MCP Router):** Exposes only 4 compact meta-tools (`search_tools`, `inspect_tool`, `call_tool`, `pipe_tools`) + optional `--pin` fast-path tools.
  - **`mcpfold eject` (MCP → CLI Compiler):** Emits an executable zero-dependency `.mjs` CLI + tiny `<server>.SKILL.md` cheat-sheet (`-82.6%` upfront tokens) for CLI-native workflows.

---

## 🚀 30-Second Quickstart

### 1. Audit your machine first (Read-Only X-Ray)

Scan **Claude Code**, **Google Antigravity**, and **Cursor** configs locally and generate a shareable dark-mode SVG scorecard + interactive HTML dashboard:

```bash
npx mcpfold audit --svg mcpfold-scorecard.svg --html mcpfold-report.html
```

Add `--live` to probe live `tools/list` schemas directly from configured servers.

<details>
<summary>Verified CLI output: Live `mcpfold bench` & `mcpfold sync` summary</summary>

```text
| Metric | Raw MCP | With `mcpfold` | Delta |
| --- | ---: | ---: | ---: |
| Upfront schema tokens (48 tools) | 13,889 | 609 | **-95.6%** |
| Compiled CLI + `SKILL.md` tokens | 13,889 | 2,419 | **-82.6%** |
| 4-step workflow LLM turns | 4 | 1 | **-75%** |
| Tool output payload tokens | 5,986 | 91 | **-98.5%** |
| Total session tokens (schemas + payloads) | 61,542 | 700 | **-98.9%** |
| Cold proxy boot (cached catalog) | — | 5.41 ms | **0 child spawns** |
| Leaked secrets redacted / injections flagged | 0 caught | 3 secrets / 1 flags | **Protected** |
```

</details>

---

### 2. Choose Your Mode

#### Option A — Folded Proxy + Safe Wrap (Claude Code, Google Antigravity, Cursor)

`mcpfold wrap` automatically saves a timestamped `.mcpfold-backup.json` before touching anything (`mcpfold unwrap` restores byte-for-byte anytime):

```bash
# Wrap all discovered clients (Claude Code, Antigravity, Cursor)
npx mcpfold wrap --client all

# Or target a single config file explicitly
npx mcpfold wrap --file ~/.gemini/antigravity/mcp_config.json

# Restore original config anytime
npx mcpfold unwrap --file ~/.gemini/antigravity/mcp_config.json
```

#### Option B — Compile MCP Into Zero-Bloat CLI + `SKILL.md` (`eject`)

```bash
npx mcpfold sync --config .mcp.json
npx mcpfold eject --config .mcp.json --out ./ejected-tools

# Agents call tools with plain CLI commands (~82-95% less upfront schema context)
node ./ejected-tools/enterprise-cli.mjs --list
node ./ejected-tools/enterprise-cli.mjs summarize_sprint_notes --issueNumber 42
```

---

## 💻 Quickstart by Client

<details open>
<summary><strong>Claude Code</strong> (<code>.mcp.json</code> or <code>~/.claude.json</code>)</summary>

```json
{
  "mcpServers": {
    "mcpfold": {
      "command": "npx",
      "args": ["-y", "mcpfold", "serve", "--config", ".mcpfold/servers.json", "--pin", "read_file"]
    }
  }
}
```

</details>

<details>
<summary><strong>Google Antigravity</strong> (<code>~/.gemini/antigravity/mcp_config.json</code>)</summary>

```bash
npx mcpfold sync --config ~/.gemini/antigravity/mcp_config.json
npx mcpfold wrap --client antigravity
```

</details>

<details>
<summary><strong>Cursor IDE</strong> (<code>.cursor/mcp.json</code> or <code>~/.cursor/mcp.json</code>)</summary>

```bash
npx mcpfold sync --config .cursor/mcp.json
npx mcpfold wrap --client cursor
```

</details>

---

## ⚡ One-Turn Pipeline Example (`pipe_tools`)

Instead of spending 4 separate slow LLM turns pulling issues, details, comments, and notes, chain everything in **1 turn** with field projection + automatic secret redaction:

```json
{
  "maxTokens": 320,
  "steps": [
    {
      "id": "list",
      "tool": "github.list_issues",
      "args": { "repo": "core" },
      "fields": ["number", "title"]
    },
    {
      "id": "detail",
      "tool": "github.get_issue",
      "args": { "issueNumber": "{{list.items[0].number}}" },
      "fields": ["number", "title", "user.login"]
    }
  ]
}
```

Or pass an isolated sandboxed `script` string using `await call("server.tool", args)` inside a hardened `node:vm` context with **zero** access to `process`, `fs`, `require`, or networking globals.

---

## 🛡️ Security Guard & Ecosystem

- **Credential Redaction:** Automatically scrubs `ghp_` / `gho_` / `github_pat_`, `sk-`, AWS `AKIA`, Google `AIza`, Slack `xox*`, `Bearer` tokens, PEM private keys, and credential JSON keys before downstream payloads ever enter model context.
- **Prompt-Injection & Steganography Sanitizer:** Strips zero-width / bidirectional control characters (`\u200B-\u200F`, `\u202A-\u202E`, `\uFEFF`) and flags suspicious instruction-hijack directives inside tool responses.
- **Pair with [`mcpprobe`](https://github.com/md1qamar/mcpprobe):** Use `mcpprobe` in CI to fuzz/audit your MCP server contracts, and `mcpfold` in daily coding sessions to fold schemas, outputs, and round-trips.

---

## 📋 CLI Reference

| Command | Purpose |
| --- | --- |
| `mcpfold audit [--config <f>] [--live] [--svg <out>] [--html <out>]` | Scan Claude Code, Antigravity & Cursor configs and export SVG/HTML X-Ray reports |
| `mcpfold sync --config <mcp.json> [--out <catalog.json>]` | Probe servers once and cache normalized tool catalog for `<6ms` cold boot |
| `mcpfold serve --config <mcp.json> [--pin a,b] [--max-output-tokens N]` | Start stdio folded MCP proxy (`search_tools`, `inspect_tool`, `call_tool`, `pipe_tools`) |
| `mcpfold eject --config <mcp.json> [--server <name>] [--out <dir>]` | Compile MCP servers into standalone zero-dep `.mjs` CLIs + compact `SKILL.md` |
| `mcpfold pipe --config <mcp.json> --steps '<json>' \| --script '<js>'` | Run a 1-turn local tool pipeline directly from CLI |
| `mcpfold wrap (--file <path> \| --client <claude\|antigravity\|cursor\|all>)` | Safely replace client `mcpServers` with `mcpfold` (saves timestamped backup) |
| `mcpfold unwrap --file <path>` | Restore exact original client config from backup |
| `mcpfold bench [--markdown] [--json] [--svg <out.svg>]` | Run deterministic 48-tool live benchmark fixture locally |

---

## 🛠 Development

```bash
git clone https://github.com/md1qamar/mcpfold.git
cd mcpfold
npm install
npm run typecheck
npm test
```

<details>
<summary>Repository Module Map</summary>

- [`src/tokenizer.ts`](./src/tokenizer.ts) — Deterministic token estimator, identifier splitter (`camelCase`, `snake_case`, dots), developer synonym map, and BM25 tool search index.
- [`src/compactor.ts`](./src/compactor.ts) — Dot-path `fields` projection, token-budget array slicing, base64 noise stripping, credential redactor, and prompt-injection/Unicode sanitizer.
- [`src/pipeline.ts`](./src/pipeline.ts) — Single-turn declarative (`{{step.path}}`) and isolated `node:vm` sandboxed pipeline executor (`pipe_tools`).
- [`src/stdio-client.ts`](./src/stdio-client.ts) — Zero-dependency NDJSON-RPC 2.0 client + lazy downstream process pool.
- [`src/compiler.ts`](./src/compiler.ts) — Standalone zero-dep MCP-to-CLI compiler + compact `SKILL.md` emitter (`mcpfold eject`).
- [`src/proxy.ts`](./src/proxy.ts) — `mcpfold serve` stdio MCP proxy exposing the 4 folded meta-tools + `--pin` direct tools.
- [`src/config.ts`](./src/config.ts) & [`src/audit.ts`](./src/audit.ts) & [`src/visuals.ts`](./src/visuals.ts) — Claude Code / Antigravity / Cursor discovery, safe `wrap`/`unwrap` backups, terminal audit, SVG scorecards, and interactive HTML dashboard.

</details>

---

## ⭐ Support & Contributing

- Found token waste with `npx mcpfold audit`? **Star this repo** and share your before/after `mcpfold-scorecard.svg`!
- PRs, new offline synonym packs, client discovery paths, and benchmark fixtures are welcome.

## License

[MIT](./LICENSE) © 2026 [md1qamar](https://github.com/md1qamar)

TDQS

A3.6/5.0

Scored across 4 tools

Disambiguation4/5

Each tool maps to a distinct step in a discover→inspect→invoke workflow, and the descriptions reinforce ordering ('Always run before call_tool'). The only mild overlap is between call_tool and pipe_tools, since both ultimately execute folded tools, but the chaining/sandbox framing of pipe_tools separates them adequately.

Naming Consistency5/5

All four names follow a strict snake_case verb_noun pattern (search_tools, inspect_tool, call_tool, pipe_tools) with a consistent plural/singular convention tied to whether the tool acts on one or many tools. No mixed styles or vague verbs.

Tool Count5/5

Four tools is exactly the right scope for a folding/proxy server: discovery, schema inspection, single invocation, and chained invocation. Nothing feels padded or missing at the structural level.

Completeness4/5

The surface covers the full lifecycle of finding, understanding, calling, and composing folded tools, including projection, token caps, and redaction for output control. The main gap is the absence of an explicit list/browse operation for all folded tools or servers, forcing agents to rely on keyword search.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues