fix(mcp): route tracing output to stderr to prevent JSON-RPC stdio corruption (#470)

The ruvector-mcp binary initializes its tracing subscriber without
specifying a writer, defaulting to stdout. Under the stdio MCP
transport this contaminates the JSON-RPC frame stream with log lines,
causing every @modelcontextprotocol/sdk client to throw a Zod parse
error on the very first frame.

Add .with_writer(std::io::stderr) to both the debug and release
tracing subscriber builders in crates/ruvector-cli/src/mcp_server.rs.

Verified by stdio smoke test: first line of stdout is now a valid
JSON-RPC initialize response with serverInfo.name == "ruvector-mcp",
and tracing output appears exclusively on stderr as required by the
MCP stdio transport spec.
This commit is contained in:
Name cannot be blank 2026-05-22 06:30:56 +01:00 committed by GitHub
parent ca62a44c2c
commit 38105cf89b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,10 +48,12 @@ async fn main() -> Result<()> {
// Initialize logging
if cli.debug {
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter("ruvector=debug")
.init();
} else {
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_env_filter("ruvector=info")
.init();
}