Skip to main content
Glama
README.md
<p align="center">
  <img src="assets/logo.svg" alt="MCP X-Ray Logo" width="96" height="96" />
</p>

<h1 align="center">MCP X-Ray</h1>

<p align="center">
  <strong>See the hidden token tax, startup latency, and tool-poisoning risks inside your MCP servers.</strong><br/>
  Multi-agent MCP Profiler, Security Auditor &amp; Interactive Context Diet Simulator for <strong>Antigravity</strong>, <strong>Claude Code</strong>, <strong>Cursor</strong>, and <strong>Codex</strong>.
</p>

<p align="center">
  <a href="https://github.com/oguzhan-yildirim/mcp-xray/actions"><img src="https://img.shields.io/badge/CI-passing-22c55e?style=flat-square" alt="CI Status" /></a>
  <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-06b6d4?style=flat-square" alt="MIT License" /></a>
  <img src="https://img.shields.io/badge/MCP_App-SEP--1865-6366f1?style=flat-square" alt="MCP App" />
  <img src="https://img.shields.io/badge/Node-%3E%3D20-34d399?style=flat-square" alt="Node 20+" />
</p>

---

## Why MCP X-Ray?

Every enabled MCP server silently injects its full JSON tool definitions into **every single LLM turn** — whether you call those tools or not. Installing 8–12 MCP servers across Antigravity, Claude Code, Cursor, or Codex can easily burn **15,000–40,000+ context tokens per turn**, slow down agent startup by seconds, introduce cross-server tool name shadowing, or expose your agent to **MCP Tool-Poisoning** prompt-injection attacks hidden inside tool descriptions and schema properties.

**MCP X-Ray** gives you instant X-ray vision across your entire local MCP stack:

- **Multi-Agent Config Discovery (Read-Only & Secret-Safe)** — Automatically discovers MCP configs across:
  - **Antigravity Global**: `~/.gemini/config/mcp_config.json`
  - **Antigravity Plugins**: `~/.gemini/config/plugins/*/mcp_config.json` (resolving `${PLUGIN_ROOT}` & `${PLUGIN_DATA}`)
  - **Claude Code**: `~/.claude.json` (global & per-project) and `~/.claude/settings.json`
  - **Cursor**: `~/.cursor/mcp.json`
  - **Codex**: `~/.codex/config.toml` (native parser for `[mcp_servers.<name>]` & nested env/header tables)
  - **Project / Custom**: `.mcp.json` or `--config=<path>`
  - Every `env` value, HTTP header value, and secret CLI flag/query param is **redacted to `••••`** in all outputs.
- **Live MCP Schema & Latency Prober** — Connects to local stdio MCP servers over `@modelcontextprotocol/sdk` (`StdioClientTransport`) with a strict **6-second timeout** (automatically skipping `mcp-xray` itself to guarantee zero recursion):
  - Measures exact startup + handshake + `listTools()` latency in milliseconds
  - Calls `listTools()` and `listResources()` and closes cleanly with zero orphan processes
  - Computes exact estimated token tax (`ceil(jsonBytes / 3.7)`) **per server** and **per individual tool** alongside full JSON Schema depth, property, enum, and description vs. schema token splits
  - Instant static/config-only mode for remote `http`/`sse` (`serverUrl`) servers and fast launches
- **Tool-Poisoning & Collision Security Scanner** — Deeply audits every tool's `name`, `description`, and nested `inputSchema` strings for:
  - **Hidden Prompt-Injection Directives**: `<IMPORTANT>`, `<SYSTEM>`, `ignore previous instructions`, `do not tell the user`, `before calling any other tool`, `silently send`, `exfiltrate`, `read ~/.ssh`, piped shell payloads
  - **Invisible Unicode Smuggling**: Zero-width characters (`U+200B`–`U+200D`, `U+FEFF`), Trojan Source bidirectional overrides (`U+202A`–`U+202E`), and Unicode Tag-Block invisible ASCII smuggling (`U+E0000`–`U+E007F`, decoded inline!)
  - **Cross-Server Tool Collisions & Shadowing**: Exact duplicate tool names (`read_file` in two servers), near-identical canonical names (`read_file` vs `readFile`), and 1-char lookalike shadowing
  - **Oversized Tool Schemas**: Flags any single tool exceeding **800 tokens**
- **Interactive Context Diet Simulator & Health Grade (`A`–`F`)** — Toggle servers on/off with live checkboxes inside the Antigravity MCP App UI to watch per-turn token savings, 20-turn session savings, 128k/200k context window percentage, and your projected **Health Grade (`A`–`F`)** update in real time.

---

## Architecture

```mermaid
flowchart LR
  Host["Antigravity / Claude / Cursor / Codex"] <-->|MCP stdio| Server["MCP X-Ray Server"]
  Host <-->|ui://mcp-xray/app.html| UI["Interactive React MCP App"]
  UI <-->|app.callServerTool| Server
  Server --> Discovery["Multi-Agent Discovery\n(JSONC + Codex TOML + Redaction)"]
  Server --> Prober["Live Stdio Prober\n(6s Timeout · Latency · Token Tax)"]
  Server --> Analyzer["Security & Diet Engine\n(Poisoning · Unicode · Collisions · Grade A–F)"]
  Discovery --> Configs["~/.gemini · ~/.claude · ~/.cursor · ~/.codex"]
  Prober <--> LocalMCP["Local Stdio MCP Servers"]
  Server <--> Cache["0600 Local Probe & Diet Cache"]
```

---

## Quick Start

### 1. Google Antigravity Plugin (Full Interactive MCP App UI)

```bash
git clone https://github.com/oguzhan-yildirim/mcp-xray.git
cd mcp-xray
npm install
npm run build
npm run install:antigravity
```

Antigravity automatically discovers the plugin under `~/.gemini/config/plugins/mcp-xray` — no restart needed:
- Open **MCP X-Ray** from the left **Sidebar** or side pane **`+`** menu.
- Or ask in chat: *"Open MCP X-Ray and show me which MCP servers are burning the most context tokens."*

### 2. Claude Code / Cursor / Codex (Universal MCP Server)

Add `mcp-xray` to your MCP config (`~/.claude.json`, `~/.cursor/mcp.json`, or `~/.gemini/config/mcp_config.json`):

```json
{
  "mcpServers": {
    "mcp-xray": {
      "command": "npx",
      "args": ["-y", "github:oguzhan-yildirim/mcp-xray"]
    }
  }
}
```

For **Codex** (`~/.codex/config.toml`):

```toml
[mcp_servers.mcp-xray]
command = "npx"
args = ["-y", "github:oguzhan-yildirim/mcp-xray"]
```

### 3. Standalone CLI

```bash
# Instant multi-agent config inventory (read-only, secrets redacted)
npx mcp-xray scan

# Scan + live-probe all eligible stdio MCP servers
npx mcp-xray scan --probe

# Live-probe a single server and inspect per-tool token tax & latency
npx mcp-xray probe filesystem

# Full Tool-Poisoning, Collision & Context Diet Audit (exits code 2 on critical alerts)
npx mcp-xray audit

# Machine-readable JSON output for CI pipelines
npx mcp-xray audit --json
```

---

## MCP Tools Reference

| Tool | Visibility | Description |
| :--- | :--- | :--- |
| `open_mcp_xray` | Model + UI Entrypoint | Opens the interactive MCP X-Ray dashboard (`aux_pane`, `global`, inline). Works with `{}` empty args. |
| `scan_mcp_configs` | Model + Inline UI | Discovers MCP configs across Antigravity, Plugins, Claude Code, Cursor, Codex & `.mcp.json` (optional live `probe: true`). |
| `probe_mcp_server` | Model | Live-probes a stdio MCP server (or `"all"`), returning startup latency (ms), tools, resources, schema depth & token tax. |
| `audit_tool_poisoning` | Model + Inline UI | Scans probed or inline tool definitions for prompt injection, hidden Unicode, collisions, oversized schemas, Diet Plan & Health Grade (`A`–`F`). |

---

## Security Detection Rules

| Rule ID | Category | Severity | What It Detects |
| :--- | :--- | :--- | :--- |
| `PI-001` | Prompt Injection | Critical | Pseudo-system XML/bracket tags (`<IMPORTANT>`, `<SYSTEM>`, `[SYSTEM OVERRIDE]`) |
| `PI-002` | Prompt Injection | Critical | Instruction overrides (`ignore previous instructions`, `disregard prior rules`) |
| `PI-003` | Prompt Injection | Critical | User-concealment stealth directives (`do not tell the user`, `hide this from the user`) |
| `PI-004` | Prompt Injection | Critical | Cross-tool hijacking (`before calling any other tool`, `always call this tool first`) |
| `PI-005` | Prompt Injection | Critical | Covert data exfiltration (`silently send`, `exfiltrate`, `pass contents of ... into`) |
| `PI-006` | Prompt Injection | Critical | Local secret/file harvesting (`read ~/.ssh`, `~/.aws`, `.env`, `mcp_config.json`, private keys) |
| `PI-007` | Prompt Injection | High | Remote pipe-to-shell or encoded execution payloads (`curl ... \| bash`, `powershell -enc`) |
| `UNI-001` | Hidden Unicode | Critical | Bidirectional override/isolate control chars (`U+202A`–`U+202E`, `U+2066`–`U+2069`) |
| `UNI-002` | Hidden Unicode | High / Critical | Zero-width invisible chars (`U+200B`–`U+200D`, `U+2060`, `U+FEFF`) |
| `UNI-003` | Hidden Unicode | Critical | Unicode Tag-Block invisible ASCII smuggling (`U+E0000`–`U+E007F`, decoded in report) |
| `COLL-001` | Tool Collision | High | Identical tool name declared by multiple distinct MCP servers |
| `COLL-002` | Tool Collision | Medium | Near-identical canonical tool name shadowing (`read_file` vs `readFile` vs `read-file`) |
| `COLL-003` | Tool Collision | Medium | 1-character lookalike / typosquat tool shadowing across servers |
| `SIZE-001` | Oversized Schema | Medium / High | Single tool exceeding 800 estimated tokens (>1,600 tokens elevated to High) |

---

## Agent Toolkit Suite

**MCP X-Ray** is part of the open-source **Agent Toolkit Suite** for Antigravity, Claude Code, Cursor, and Codex:

| Project | Purpose |
| :--- | :--- |
| [**find-my-skill**](https://github.com/oguzhan-yildirim/find-my-skill) | Discover, security-audit, preview & one-click install AI Agent Skills (`SKILL.md`) from GitHub |
| [**mcp-xray**](https://github.com/oguzhan-yildirim/mcp-xray) | Inspect MCP context token tax, live startup latency, tool-poisoning attacks & simulate a Context Diet |
| [**agent-blackbox**](https://github.com/oguzhan-yildirim/agent-blackbox) | Flight recorder, replay timeline & forensic debugger for AI coding agent trajectories |
| [**skill-doctor**](https://github.com/oguzhan-yildirim/skill-doctor) | Linter, trigger-collision analyzer & quality scorer for your local `SKILL.md` library |
| [**mcp-switchboard**](https://github.com/oguzhan-yildirim/mcp-switchboard) | Profile manager & one-click context switcher for enabling/disabling MCP server groups per task |

---

## Development

```bash
npm install
npm run typecheck           # Strict TypeScript check
npm run build               # Builds single-file dist/app.html + standalone dist/server.js
npm test                    # Unit tests (TOML, redaction, tokens, poisoning) + live MCP stdio E2E
npm run install:antigravity # Installs plugin bundle to ~/.gemini/config/plugins/mcp-xray
```

## License

MIT © 2026 [Oğuzhan Yıldırım](https://github.com/oguzhan-yildirim)