I Turned My 1,587-Skill Context Audit Into a Zero-Dependency CLI (mcp-diet)

2026-11-29来源 dev.toEnglish

Two days ago I shared what happened when I inspected the startup context across my Claude Code, Antigravity/Gemini, and Codex CLI setups: 1,587 installed skills (~53,585 frontmatter tokens if loaded), 55 KB of global instruction files, and 3 browser MCP servers (chrome-devtools-mcp, playwright-mcp, and turbo-browser-mcp, totaling 69 tools) enabled at the same time.

Several people on dev.to and r/mcp asked for the script I used to measure the token tax across all three harnesses. The original 40-line Python script had hardcoded Windows paths, so I rewrote it into a standalone, zero-dependency Node.js CLI called mcp-diet (v0.1.0, MIT).

GitHub: https://github.com/Tthanh2k6/mcp-diet

Running mcp-diet

You can run it locally on Node 20+ without installing global packages:

npx github:Tthanh2k6/mcp-diet audit 

Or from a local clone:

git clone https://github.com/Tthanh2k6/mcp-diet.git cd mcp-diet node bin/mcp-diet.mjs audit 

Here is the real output on my machine after moving 1,521 unused skills to an archive and 60 specialized skills into an on-demand vault:

$ node bin/mcp-diet.mjs audit === 1. ACTIVE SKILLS (Target <= 16 per agent) === agents : 14 skills (~1265 frontmatter tokens ) [OK] [SEC NOTE] 1 executable script(s) inside agents skills: [systematic-debugging/find-polluter.sh] gemini : 14 skills (~1265 frontmatter tokens ) [OK] [SEC NOTE] 1 executable script(s) inside gemini skills: [systematic-debugging/find-polluter.sh] claude : 16 skills (~1289 frontmatter tokens ) [OK] [SEC NOTE] 9 executable script(s) inside claude skills: [systematic-debugging/find-polluter.sh, synced/contact_sheet.sh, synced/ref_frames.sh, synced/samples.sh, synced/style_board.sh] === 2. MCP SERVERS & CATEGORY OVERLAPS === antigravity: active=[turbo-browser, basic-memory] | disabled=[blender, chrome-devtools, n8n-mcp, playwright] claude : active=[workspace-mcp, turbo-browser, basic-memory] codex : active=[basic-memory] MCP Footprint: ~14382 est. active schema tokens (6 enabled, 4 disabled saving ~40700 tokens) === 3. ALWAYS-LOADED RULES FILES (Target <= 15 KB per file) === 16.5 KB [WARN: >15KB ] C:\Users\dev\.gemini\config\rules\huong-dan-toan-cuc-tu-claude.md (~4226 tokens) 7.8 KB [OK ] C:\Users\dev\.gemini\config\rules\model-effort-selection.md (~2004 tokens) 17.2 KB [WARN: >15KB ] C:\Users\dev\.claude\CLAUDE.md (~4407 tokens) TOTAL RULES: 41.5 KB (~10637 est. tokens if all loaded) === SUMMARY === Estimated session-start context footprint: ~28838 tokens Trust-boundary script notes: 3 provider(s) with executable scripts in skills [!] huong-dan-toan-cuc-tu-claude.md is 16.5 KB (exceeds 15 KB limit, ~4226 tokens) [!] CLAUDE.md is 17.2 KB (exceeds 15 KB limit, ~4407 tokens) 

Even after trimming active skills down to 14-16 per agent and disabling 4 idle MCP servers (saving ~40,700 schema tokens), mcp-diet caught two global rule files (CLAUDE.md at 17.2 KB and my global Gemini rule file at 16.5 KB) that had crept past the 15 KB threshold.

What mcp-diet checks under the hood

  1. Active skill frontmatter tokens across 4 config roots: It scans ~/.claude/skills, ~/.gemini/config/skills, ~/.agents/skills, and ~/.codex, parses each SKILL.md YAML frontmatter block (name, description), and estimates the session-start token cost against a configurable cap (--skills-max 16).
  2. Duplicate MCP category detection: It reads ~/.claude.json, ~/.gemini/config/mcp_config.json, and ~/.codex/config.toml (using an inline zero-dependency TOML parser for [mcp_servers.<name>]), classifies servers into functional buckets (browser, database, search, memory, git, desktop), and flags when multiple servers in the same category are active simultaneously.
  3. Always-loaded rule file budgets: It measures global and workspace instruction files (CLAUDE.md, GEMINI.md, and ~/.gemini/config/rules/*.md) in KB and estimated tokens, warning when any single file exceeds --rules-max-kb (default 15).
  4. Executable scripts inside skill folders: Community skill packs frequently bundle helper scripts. mcp-diet walks active skill directories and lists .ps1, .sh, .bat, .cmd, .exe, and .vbs files so you can review what an agent can invoke inside your workspace. Passing --fail-on-scripts turns script detections into strict failures.
  5. Automatic secret stripping: MCP config files often contain inline API keys, database URLs, or Personal Access Tokens. mcp-diet never executes MCP servers, drops all env values during parsing (recording only envKeyCount), and masks credential flags (--token, --api-key, postgres://user:pass@..., ghp_, sk-, eyJ...) as [REDACTED] in both terminal and --json output.

Preventing context drift in CI or pre-session hooks

Cleanup only lasts until you install another plugin pack or append a few more paragraphs to CLAUDE.md. You can enforce a hard ceiling in scripts or CI with --strict (which exits with code 1 on any warning):

npx github:Tthanh2k6/mcp-diet audit --strict --skills-max 16 --rules-max-kb 15 

Or export a structured JSON report for your own dashboard or dotfiles repo:

npx github:Tthanh2k6/mcp-diet audit --json --workspace-dir . 

The CLI uses only built-in Node.js modules (node:fs, node:path, node:os, node:url) and ships with 30 unit tests on Node 20+. If you use another agent harness with its own config layout (Cursor, Windsurf, Cline, or OpenCode) and want its paths added to the scanner, open an issue or PR on GitHub.

原文:https://www.a8q9.cn/en/article/i-turned-my-1-587-skill-context-audit-into-a-zero-dependency-cli-mcp-diet-bf2269.html

相关文章