Skip to content

fix: redirect tracing logs from stdout to stderr#20

Open
oudeis01 wants to merge 1 commit into
Brainwires:mainfrom
oudeis01:fix/stderr-logging
Open

fix: redirect tracing logs from stdout to stderr#20
oudeis01 wants to merge 1 commit into
Brainwires:mainfrom
oudeis01:fix/stderr-logging

Conversation

@oudeis01

Copy link
Copy Markdown

Problem

tracing_subscriber::fmt::init() writes logs to stdout by default. When project-rag serve runs as an MCP stdio server, stdout is exclusively used for the JSON-RPC message stream. Log lines on stdout are not valid JSON-RPC and cause parse errors on the client side (e.g. JSONRPCMessage validation failures in Python MCP clients), making tool calls silently return empty results.

Fix

Redirect tracing output to stderr with .with_writer(std::io::stderr). Logs remain visible in the terminal without interfering with the MCP protocol stream.

Test plan

  • Start project-rag serve with RUST_LOG=info and confirm log lines appear on stderr, not stdout
  • Connect an MCP client and confirm tool calls return results normally

The MCP stdio transport uses stdout exclusively for JSON-RPC messages.
Tracing output on stdout is not valid JSON-RPC and causes parse errors
on the client side (e.g. pydantic JSONRPCMessage validation failures),
making tool calls silently return empty results.

Redirect to stderr with `.with_writer(std::io::stderr)` so logs remain
visible without interfering with the protocol stream.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant