DEV Community

Cover image for Why your MCP servers are secretly eating 30,000 tokens per turn (and how to tree-shake them)
Christian Frascogna
Christian Frascogna

Posted on

Why your MCP servers are secretly eating 30,000 tokens per turn (and how to tree-shake them)

If you use Claude Code, OpenAI Codex CLI, or Cursor with 4–5 MCP servers connected (GitHub, Playwright, Postgres, Notion, Linear), there is a hidden tax running on every single turn: MCP JSON tool schemas.

Before you even type a prompt, every connected MCP server dumps its full tools/list JSON schema into your context window. A single server with 20+ tools can consume 15,000 to 35,000 tokens per turn, degrading model reasoning and burning through your rate limits.

At the same time, multi-agent teams now have to maintain CLAUDE.md, hierarchical AGENTS.md (which OpenAI Codex CLI silently truncates at 32 KiB), and .cursor/rules/*.mdc — while making sure nobody accidentally commits an API key or a prompt-injection payload inside .mcp.json or .claude/skills.

To solve this locally with zero API keys and zero telemetry, I built CtxWise v1.0 (@framy2/ctxwise on npm, Apache-2.0).

What CtxWise v1.0 does in one CLI:

  1. Live MCP Schema X-Ray & Tree-Shaking (mcp-xray)
   npx @framy2/ctxwise mcp-xray --probe-stdio
Enter fullscreen mode Exit fullscreen mode

Queries your local MCP servers over stdio (tools/list), calculates the exact token cost of every individual tool schema, flags [BLOATED] tools, and lets you prune unused tools (mcp-prune) to cut startup context by 50–80%.

  1. Supply-Chain & Prompt-Injection Firewall (shield)
   npx @framy2/ctxwise shield --fail-on-risk
Enter fullscreen mode Exit fullscreen mode

Scans CLAUDE.md, AGENTS.md, .claude/skills, and .mcp.json for leaked credentials (sk-ant-..., sk-proj-..., AWS, GitHub PATs), prompt-injection overrides, and hidden Trojan Source Unicode characters.

  1. Multi-Agent Rule Sync + Lossless Token Diet (sync --compress)
   npx @framy2/ctxwise sync --compress
Enter fullscreen mode Exit fullscreen mode

Synchronizes CLAUDE.md <-> AGENTS.md <-> .cursor/rules/ctxwise.mdc and compresses comments, blank lines, and duplicate bullets (~18–30% token reduction) while keeping fenced code blocks intact.

  1. OpenAI Codex CLI 32 KiB Doctor (codex-doctor)
   npx @framy2/ctxwise codex-doctor
Enter fullscreen mode Exit fullscreen mode

Audits your directory chain of AGENTS.override.md and AGENTS.md against Codex CLI's 32,768-byte limit (project_doc_max_bytes) and validates .codex/config.toml.

  1. 1-Line GitHub Action (FramY2/ctxwise@v1) Drop uses: FramY2/ctxwise@v1 into .github/workflows/ci.yml to block secret leaks, prompt injections, and context bloat on every Pull Request with inline annotations and a Job Summary table.

Links:

Top comments (1)

Collapse
 
devdevdevss profile image
DEV VERIFY •

DEV-VERIFY
tr.ee/dev-to