When connecting an AI coding agent to 5–8 Model Context Protocol (MCP) servers, two invisible problems show up almost immediately:
-
Silent Context Window Drain: Before you type a single character of your prompt, verbose tool descriptions and deeply nested JSON Schemas (
default,examples, redundant descriptions on every nested property) can burn 12,000 to 35,000 tokens per turn. -
Tool-Poisoning & Invisible Unicode Smuggling: Because LLMs read raw
descriptionstrings intools/listas trusted instructions, a compromised third-party MCP server can embed zero-width characters, bidirectional overrides (U+202A–U+202E), Unicode Tags (U+E0000–U+E007F), or hidden<IMPORTANT>exfiltration instructions that look completely harmless in a terminal UI—or register a tool name that shadows an existing trusted server's tool.
To audit my own MCP configurations locally without sending sensitive config files to any cloud service, I built MCP Token X-Ray (v1.0.0, MIT, zero runtime dependencies).
- Live Browser Sandbox (100% client-side): https://huyvv533.github.io/mcp-token-xray/
- GitHub Repository (MIT): https://github.com/huyvv533/mcp-token-xray
What mcp-token-xray Catches (MCP-001 .. MCP-005)
The static firewall inspects every server's tool definitions, input schemas, and cross-server namespaces deterministically:
-
MCP-001— Invisible Unicode & Bidi Smuggling: Flags Unicode Tag blocks (U+E0000..U+E007F), zero-width joiners/spaces (U+200B..U+200F,U+FEFF), and bidirectional control characters used to hide instructions from human code review. -
MCP-002— Tool Description Prompt-Injection Directives: Detects coercive override blocks (ignore previous instructions,<IMPORTANT>,do not tell the user, covert file-read + outbound exfiltration chains) embedded inside tool metadata. -
MCP-003— Cross-Server Tool Shadowing: Alerts when two MCP servers expose colliding or near-homoglyph tool names that let a lower-trust server intercept tool invocations. -
MCP-004— Unbounded / Unconstrained Shell & Path Sinks: Flags string parameters accepting raw shell commands, arbitrary filesystem paths, or SSRF-prone URLs withoutenum,pattern, or length bounds. -
MCP-005— Context Budget Outliers: Highlights individual tools consuming disproportionate token budgets before inference even begins.
Lossless JSON Schema Slimming (30%–55% Token Reduction)
Most auto-generated Zod / Pydantic / OpenAPI schemas ship massive non-functional metadata inside inputSchema: multi-paragraph examples arrays, $comment blocks, redundant title fields duplicating property keys, and verbose prose where types + enum values already self-document the contract.
mcp-token-xray computes exact before/after token estimates and produces a slimmed schema representation that preserves 100% of structural validation constraints (type, properties, required, enum, anyOf, oneOf, pattern, minimum/maximum) while cutting per-turn context overhead by 30%–55%.
git clone https://github.com/huyvv533/mcp-token-xray.git
cd mcp-token-xray
npm test
Part of a Zero-Dependency Developer Tooling Suite
Alongside mcp-token-xray, I also open-sourced three companion zero-dependency TypeScript CLI + browser tools under MIT (v1.0.0):
-
EnvShield (Live Scanner) — Local-first
.env& config secret scanner with Shannon entropy analysis and OASIS SARIF 2.1.0 export for GitHub Code Scanning. - Gerber X-Ray Diff (Live PCB Viewer) — Pure TypeScript RS-274X PCB Gerber parser, micron-precision geometric board diff engine, and interactive dual-layer X-Ray SVG overlay.
- Mojibake Surgeon (Live Decoder) — Multi-hop byte-transcoding beam-search solver that repairs double-encoded UTF-8 / Windows-1252 / Latin-1 / CP1258 CSVs and SQL dumps.
If you're building with MCP servers or maintaining CI security pipelines, give the live browser auditor a try—and if you run into sneaky real-world schema patterns or false positives, issues and stars on GitHub are super welcome!
Top comments (0)