mcpspy 0.2.3

Zero-config stdio MCP proxy, latency profiler, and token usage auditor in Rust
Documentation

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

cargo install --path .
mcpspy --help
mcpspy --version

Or build from source:

cargo build --release
./target/release/mcpspy --help

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

mcpspy wrap --name treecut -- treecut mcp
mcpspy --db /tmp/telemetry.db wrap --name logcut --no-payloads -- logcut mcp

Auto-wrap an existing config

mcpspy init ~/.config/opencode/opencode.json
mcpspy init ~/.mcp.json
mcpspy init ~/.cursor/mcp.json

Inspect the telemetry

mcpspy stats
mcpspy stats --server treecut --since 7d --json
mcpspy tail -n 20 --errors-only
mcpspy top
mcpspy compare --baseline /tmp/raw.db --optimized /tmp/sliced.db --json
mcpspy prune --older-than 7d

🏗 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.