fix: redirect tracing logs from stdout to stderr#20
Open
oudeis01 wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
tracing_subscriber::fmt::init()writes logs to stdout by default. Whenproject-rag serveruns 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.JSONRPCMessagevalidation 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
project-rag servewithRUST_LOG=infoand confirm log lines appear on stderr, not stdout