mcpspy
A zero-config, local-first MCP Traffic Inspector, Latency Profiler & Token Auditor in a single Rust binary.
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.
Features
- Transparent proxy —
mcpspy wrap [--name LABEL] -- <CMD> [ARGS...]forwardsstdin/stdoutverbatim; malformed JSON is still passed through untouched. - Shared WAL telemetry store —
rusqlite(bundled) withjournal_mode=WALand 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
errorobjects andresult.isError. - Schema violation audit — malformed version, invalid method/params/id, and contradictory responses are recorded to a separate table and viewable with
mcpspy tail --violations, without ever blocking the forwarded frame. - Secret redaction — Bearer tokens,
sk-/ghp_/AKIA...keys, generickey=/password=values, and DB connection URLs are scrubbed before previews hit disk.--no-payloadsstores metadata only. - CLI analytics — ranked
statstables (plus--json), recent-calltail, andprune. - Live TUI —
mcpspy topshows per-server token-burn bars, per-tool averages, latency percentiles, and recent calls (qquit,cclear). - Self-inspecting MCP server —
mcpspy mcpexposesget_mcp_statsandget_slow_callsover 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.bakbackup.
Install
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.
Usage
1. Wrap an MCP server
# Direct use
# With a custom database and no stored payloads
Everything after -- is the child command and its arguments. stdout contains only the child's JSON-RPC lines; logs and warnings go to stderr/SQLite.
2. Auto-wrap an existing config
This turns each server entry from:
"treecut":
into:
"treecut":
Other fields (such as env) are preserved. Running init again is a no-op for already-wrapped servers. The original file is saved as <config>.bak.
3. Inspect the telemetry
# Ranked summary table, last 24 hours
# Machine-readable output, one server
# Recent calls, errors only
# Live dashboard
# Drop records older than a week and VACUUM
Durations accept ms, s, m, h, d, and w suffixes — either as a single value (30m, 24h, 7d) or compounded (1h30m, 2d12h, 1w2d3h4m5s). Segments may be separated by whitespace; overflow and malformed values are rejected.
4. Let an agent audit itself
Register mcpspy mcp as an MCP server and call:
get_mcp_stats— aggregated calls, tokens, avg/p95 latency, and errors per server/tool.get_slow_calls— the slowest recorded calls with token counts.
Benchmarking treecut and logcut token savings
A typical workflow measures how much context the agent consumes when using
treecut (codebase mapping) and
logcut (log/stacktrace slicing):
# 1. Wrap both servers so every tool call is recorded
# 2. Run a normal debugging session in your MCP host, then compare token burn
# 3. Drill into the heaviest tools
|
mcpspy stats reports REQ TOK and RESP TOK per server and per tool, so you can compare a session with raw tool output against one using treecut slice_symbol / logcut slice to see the reduction in tokens sent to the model. p95 and ERR columns highlight slow servers and failing calls that inflate context.
Telemetry schema
The SQLite database (~/.mcpspy/telemetry.db by default, override with --db) contains one rpc_calls table with session/server/rpc ids, method/tool name, timestamps, duration, byte and token counts, error status, and optionally redacted request/response previews. Indexes on (server_name, started_at_ms) and tool_name keep reporting fast.
Safety
- No logs, banners, or TUI output are ever written to
stdoutinwrapormcpmode. - Malformed JSON lines are forwarded immediately and never block the MCP session.
- Secret patterns are redacted before payload previews are persisted.
--no-payloadsstores metrics only — no request or response text is saved.
MCP Registry: mcp-name: io.github.bigwalkdoe/mcpspy
Documentation
- Usage guide — every command, flag, and duration syntax.
- MCP and agent reference — self-inspection tools and host registration.
- Architecture guide — modules, data flow, invariants, and schema.
- Troubleshooting — symptom-first fixes.
- SPEC.md, CHANGELOG.md, CONTRIBUTING.md.
License
MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.