mcpspy 0.2.4

Zero-config stdio MCP proxy, latency profiler, and token usage auditor in Rust
Documentation
# Error/gotcha memories (scope: project)

### [error-solution] Double forwarding of every line (scope: project)

Early proxy wrote each request line twice to the child, producing duplicate responses, ID mismatches, and JSON parse errors in integration tests. Fix: exactly one `write_all` per line, placed after parsing/tracking. If duplicates reappear, check for nested `mcpspy wrap ... -- mcpspy wrap ...` in the MCP config.

### [error-solution] RUSTSEC-2026-0002 in lru via ratatui 0.29 (scope: project)

`lru 0.12` (pinned by ratatui 0.29) has a stacked-borrows soundness bug with no patch in that line. Fix: ratatui 0.30.2 + crossterm 0.29 → `ratatui-core` uses `lru 0.18.5` (patched). Spec manifest versions were updated; TUI API verified with a pty smoke test because `script` is unavailable on this host.

### [error-solution] Borrow checker with tokio::spawn (scope: project)

Spawning tasks that capture a borrowed `HashMap` fails with `'static` lifetime errors. Fix: `Arc<tokio::sync::Mutex<HashMap<...>>>` and clone the Arc per task. Also give each spawned task its own owned copy of `session_id`/`server_name` strings — `async move` captures them.

### [error-solution] Secrets in JSON-RPC error messages (scope: project)

Error text from `error.message` was initially stored raw, leaking `sk-...` keys. Fix: pass every error message through `Redactor::redact` before `RpcRecord` construction. Integration test `proxy_redacts_secrets_in_error_messages` guards this.

### [error-solution] req_bytes and violation prune gaps (scope: project)

`req_bytes` was hardcoded to 0 — now captured from the request line length. `prune` originally deleted only `rpc_calls`, so `schema_violations` accumulated forever — now deletes both and reports the combined count.

### [error-solution] Duration parser UTF-8 panic (scope: project)

Slicing `lower[..1]` on a non-ASCII unit like `1é` panicked at a non-char boundary. Fix: char-based `chars().next()` with an ASCII guard. Compound durations (`1h30m`, `2d12h`) use checked arithmetic and optional whitespace.

### [error-solution] Literal `~/` directory from unexpanded default DB path (scope: project)

Before `expand_tilde` was wired into `main.rs`, the default `~/.mcpspy/telemetry.db` created a literal `~` directory inside the repo. Removed; always keep tilde expansion before DB open.

### [error-solution] Stale phase/version comments in docs and code (scope: project)

The initial implementation left "Phase 2/3" markers in source headers, SPEC.md §4 at 0.1.0, and SPEC §5 describing an mpsc background SQLite writer that was never built (writes are direct and synchronous). Fixed in 0.2.2: headers describe shipped behavior, SPEC version matches the crate, the proxy contract and SQL schema match `TelemetryDb::record` / `record_violation` and `schema_violations`, and the issue-template placeholder shows the current version. `.phase3-ledger.md` is intentionally a historical record — don't "fix" it.

### [error-solution] Missing `--version` flag (scope: project)

The Clap `Cli` struct lacked `#[command(version)]`, so the installed 0.2.0 binary rejected `--version` and `-V` as unexpected arguments. Fixed in 0.2.1 by adding `version` to the `#[command(...)]` attribute in `src/main.rs`. Guard: `tests/cli_version_tests.rs` spawns the compiled binary and asserts both flags print `mcpspy <CARGO_PKG_VERSION>`.