Contents
▸ What it is
mcpspy wraps any stdio MCP server transparently, forwards JSON-RPC 2.0 frames byte-for-byte with sub-millisecond overhead, and records latency, token usage, errors, and redacted payload previews into a local SQLite database. It never writes diagnostics to stdout in proxy mode, so it is a drop-in replacement for an MCP server command in OpenCode, Claude Code, or Cursor.
✦ Feature map
| Area | What it covers |
|---|---|
| Transparent proxy | mcpspy wrap [--name LABEL] -- <CMD> [ARGS...] forwards stdin/stdout verbatim; malformed JSON is still passed through untouched. |
| Shared WAL telemetry store | rusqlite (bundled) with journal_mode=WAL and a 5s busy timeout, so multiple wrapped servers can log concurrently. |
| Token & latency accounting | Per-call duration, request/response token estimates, byte counts, average/p50/p95 latency, and error detection for both JSON-RPC error objects and result.isError. |
| Schema violation audit | Malformed version, invalid method/params/id, and contradictory responses recorded to a separate table; viewable with mcpspy tail --violations. |
| Secret redaction | Bearer tokens, sk-/ghp_/AKIA... keys, generic key=/password= values, and DB connection URLs scrubbed before previews hit disk. --no-payloads stores metadata only. |
| CLI analytics | Ranked stats tables (plus --json), recent-call tail, and prune. |
| Comparison reports | mcpspy compare --baseline A --optimized B quantifies token savings and p50/p95 changes between two telemetry databases, as a table or with --json. |
| Live TUI | mcpspy top shows per-server token-burn bars, per-tool averages, latency percentiles, and recent calls (q quit, c clear). |
| Self-inspecting MCP server | mcpspy mcp exposes get_mcp_stats and get_slow_calls over stdio so an agent can audit its own token burn. |
| Config auto-wrapping | mcpspy init <CONFIG_FILE> rewrites existing MCP server entries to run through the proxy, keeping a .bak backup. |
| Version flag | mcpspy --version (or -V) prints the crate version. |
⚡ Quick start
Or build from source:
Feature flags: tui (ratatui + crossterm) and mcp (rmcp) are enabled by default. Build without them via cargo build --no-default-features.
Wrap an MCP server
Auto-wrap an existing config
Inspect the telemetry
🏗 Architecture
src/
├── core/ # proxy, telemetry, redaction, schema audit
├── cli/ # commands, stats, tail, top, compare, prune, init
└── mcp/ # self-inspecting MCP server
See docs/architecture.md for modules, data flow, invariants, and schema. Usage details in docs/usage.md, MCP reference in docs/mcp.md, troubleshooting in docs/troubleshooting.md.
License
MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.