DEV Community

Christian Frascogna
Christian Frascogna

Posted on Edited on

How to audit MCP tool schema token bloat and sync CLAUDE.md with AGENTS.md locally

 If you connect 4–5 MCP servers to Claude Code or OpenAI Codex (GitHub, Playwright, Postgres, Notion), their tools/list JSON schemas silently consume 15,000–35,000 tokens on every turn before you even type a prompt.

On top of that, repositories using both Claude Code (CLAUDE.md) and OpenAI Codex (AGENTS.md) or Cursor (.cursor/rules) quickly suffer from rule drift or accidentally include exposed keys / covert prompt injections inside third-party skills.

I just released CtxWise v1.0 (@framy2/ctxwise, Apache-2.0, 100% local, zero API calls, zero telemetry) to inspect and fix all three in <50ms:


text
$ npx @framy2/ctxwise mcp-xray --probe-stdio
CtxWise mcp-xray · 4 MCP servers · 24 tool schemas · ~18,420 tokens/turn
  [BLOATED] ~2,840 tok · github/create_or_update_pull_request (19 params)
  [BLOATED] ~1,920 tok · playwright/browser_snapshot_dom (15 params)
  -> Tree-shaking savings: ~4,760 tokens saved on every single turn

$ npx @framy2/ctxwise agents && npx @framy2/ctxwise sync --compress
CtxWise multi-agent · parity: synced · Claude ~410 tok · Codex ~410 tok
  Synced AGENTS.md <-> CLAUDE.md <-> .cursor/rules/ctxwise.mdc (-34% Token Diet)

$ npx @framy2/ctxwise shield --fail-on-risk
  [HIGH] .mcp.json:14 — Hardcoded Anthropic API Key (sk-ant-api03-REDACTED)
  [HIGH] .claude/skills/helper/SKILL.md:42 — Covert HTML comment prompt injection
![ ](https://dev-to-uploads.s3.us-east-2.amazonaws.com/uploads/articles/sz8s53ecr7mnxhhl2hz2.png)
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
abhinavs1920 profile image
Abhinav Sharma •

The per-turn part is what makes it expensive. A bloated schema is not a one-time cost, it is rent you pay on every message in the session.

Collapse
 
paul_irolla_6b5ae261d0224 profile image
Paul Irolla •

Schema cost is per turn, so a server you call once a session costs as much as one you call all day. Audit by usage.

Collapse
 
framy2 profile image
Christian Frascogna •

Spot on @paul_irolla_6b5ae261d0224 — that schema-tokens-per-invocation ratio is the single most revealing metric in a long coding session.

An MCP server exposing 4,000 tokens of tools/list JSON schema that gets called 0 or 1 times across a 40-turn session costs 160,000 input tokens per invocation (or pure dead weight if unused), whereas a core filesystem or test-runner tool called 30 times amortizes its schema footprint across actual work.

That is why we pair static/live schema profiling with usage-aware pruning and lazy discovery:

  1. Pre-session schema X-ray + allowlist pruning (ctxwise mcp-xray / ctxwise mcp-prune): Measure each server's exact tools/list token weight before the session starts and strip unused or one-off tools out of .mcp.json / .codex/config.toml per project (with .bak backup and mcp-restore).
  2. Session-level cost-per-call auditing (agent-wire-tap): Inspect actual JSON-RPC traffic across a session to see which declared tools had 0 invocations (tools/call) despite being resent in the prompt prefix on every turn.
  3. On-demand schema loading (mcp-diet): For servers you only need once in a session (like a ticket tracker, deployment trigger, or DB migration helper), wrapping them behind a lazy stdio proxy replaces dozens of upfront schemas with 2 lightweight meta-tools (~180 tokens total) and only hydrates the full inputSchema on the single turn you actually call it.