Route logs to stderr in MCP mode - #5
Draft
MadTinker wants to merge 1 commit into
Draft
Conversation
This was referenced Aug 22, 2026
MadTinker
force-pushed
the
claude/mcp-stdout-logging-fix
branch
from
August 22, 2026 18:46
0fb2ec7 to
cbe0af3
Compare
MCP speaks JSON-RPC 2.0 over stdout, but the tracing subscriber defaulted to stdout too, so every log line was interleaved into the protocol stream. A client reading the first line for its initialize response got INFO ThreadId(01) tinker: src/main.rs:90: Starting Tinker Workshop... instead of JSON, and failed to parse. This affected any MCP client, including Claude Desktop using the configuration in the readme. Logging was also initialized before the arguments were parsed, so it could not know whether --mcp was set. Parse first, then point the subscriber at stderr when running as an MCP server. Non-MCP output is unchanged. The MCP write loop itself was already correct, and there are no other stdout writers in the tree, so the subscriber was the sole corruption source. This is why tests/mcp_tests.rs had three #[ignore]d tests. The attribute said they were skipped because they require building the binary, but they were failing on the corrupted stream. They pass now and are re-enabled, giving end-to-end protocol coverage that guards this regression. cargo test: 167 passed, 0 failed, 0 ignored (was 164 passed, 3 ignored). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Pg53xf5xcUV7oc5CkaiCpz
MadTinker
force-pushed
the
claude/mcp-stdout-logging-fix
branch
from
August 22, 2026 18:51
cbe0af3 to
28f7cf8
Compare
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.
The bug
MCP speaks JSON-RPC 2.0 over stdout. The tracing subscriber also defaulted to stdout, so every log line was interleaved into the protocol stream.
A client reading the first line for its
initializeresponse got this:instead of JSON, and failed to parse. This affected any MCP client, including Claude Desktop using the configuration in the readme.
Reproduced by discarding stderr and observing that log lines still arrive on stdout:
Two causes
tracing_subscriber::fmt()writes to stdout unless told otherwise.Args::parse()at line 93 — so it could not know whether--mcpwas set. Theinfo!on line 89 was the first line to corrupt the stream.The fix
Parse arguments first, then point the subscriber at stderr when running as an MCP server. Non-MCP output is unchanged — same destination, same format.
The MCP write loop was already correct (writes JSON, flushes) and there are no other
println!/print!calls anywhere insrc/, so the subscriber was the sole corruption source.The ignored tests were masking this
tests/mcp_tests.rshad three#[ignore]d tests whose comment read "Ignore by default since it requires building the binary." That wasn't why they were failing — they were failing on the corrupted stream, at the JSON parse on line 51.They pass now and are re-enabled. They spawn the real binary and speak JSON-RPC end to end, so they guard this exact regression.
Verification
Valid JSON, correct
id, correctprotocolVersion.Previously 164 passed with 3 ignored.
Generated by Claude Code