Skip to main content
Glama

mcpfold — Fold MCP Schemas, 30k Outputs & 4 Turns Into 1

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 Node.js >= 20 Runtime Deps: 0 Clients Agent Skills

Quick Start · Live Demo · Benchmarks · Why Not Tool Search? · Clients · Architecture


🎯 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


Related MCP server: wasmagent-mcp-server

🎬 Live Terminal Demo

mcpfold Animated CLI Demo — audit, bench, eject


📊 Verified Benchmarks & Token-Burn Graph

Cumulative Session Token Burn Graph

mcpfold Verified Benchmark Card


⚖️ 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

  • 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:

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

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

| 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** |

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):

# 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)

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

{
  "mcpServers": {
    "mcpfold": {
      "command": "npx",
      "args": ["-y", "mcpfold", "serve", "--config", ".mcpfold/servers.json", "--pin", "read_file"]
    }
  }
}
npx mcpfold sync --config ~/.gemini/antigravity/mcp_config.json
npx mcpfold wrap --client antigravity
npx mcpfold sync --config .cursor/mcp.json
npx mcpfold wrap --client cursor

⚡ 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:

{
  "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: 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

git clone https://github.com/md1qamar/mcpfold.git
cd mcpfold
npm install
npm run typecheck
npm test
  • src/tokenizer.ts — Deterministic token estimator, identifier splitter (camelCase, snake_case, dots), developer synonym map, and BM25 tool search index.

  • src/compactor.ts — Dot-path fields projection, token-budget array slicing, base64 noise stripping, credential redactor, and prompt-injection/Unicode sanitizer.

  • src/pipeline.ts — Single-turn declarative ({{step.path}}) and isolated node:vm sandboxed pipeline executor (pipe_tools).

  • src/stdio-client.ts — Zero-dependency NDJSON-RPC 2.0 client + lazy downstream process pool.

  • src/compiler.ts — Standalone zero-dep MCP-to-CLI compiler + compact SKILL.md emitter (mcpfold eject).

  • src/proxy.ts — mcpfold serve stdio MCP proxy exposing the 4 folded meta-tools + --pin direct tools.

  • src/config.ts & src/audit.ts & src/visuals.ts — Claude Code / Antigravity / Cursor discovery, safe wrap/unwrap backups, terminal audit, SVG scorecards, and interactive HTML dashboard.


⭐ 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 © 2026 md1qamar

Available Tools

4 tools
call_toolC

Invoke a folded MCP tool with optional field projection, output token cap, and secret redaction.

Inputs: tool (required), args, fields, maxTokens.

inspect_toolA
Read-only

Get the exact JSON parameter schema for a folded tool before calling it.

Inputs: tool (required), server.

pipe_toolsB

Chain multiple MCP tool calls + filter/transform JSON locally in ONE turn inside a sandbox.

Inputs: steps, fields, script, maxTokens.

search_toolsA
Read-only

Search across all folded MCP tools by keyword or intent. Always run before call_tool.

Inputs: query (required), limit, server.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    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

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A lightweight Claude MCP gateway that dynamically loads tools only when needed, cutting MCP token clutter by up to 95% and keeping your context lean, fast, and focused.
      7
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Code-mode MCP server (docs_search + execute_code two-tool surface) backed by a unified capability manifest across three sandbox kernels (in-process node:vm, WASM via QuickJS / Pyodide / Wasmtime, and remote microVM via E2B / Cloudflare Sandbox). At N=30 tools the bootstrap-context cost drops to 13.6% of direct tool-use. Apache-2.0.
      2
      7
      Apache 2.0
    • A
      license
      A
      quality
      C
      maintenance
      MCP proxy that compresses tool schemas on the fly. Up to 98% token reduction, 100% signal preserved verified after every compression. Zero LLM calls, fully deterministic.
      5
      3
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Compresses multi-turn conversation history by stripping verbose boilerplate and filler tokens while preserving critical tool parameters and named entities, deterministically cutting inference costs by 40-60%. Runs as a zero-dependency Python MCP server or importable module, compatible with Claude Desktop, Cursor, and other MCP runtimes.
      7
      MIT