fix: log startup messages to stderr instead of stdout#4
Open
nazmulidris wants to merge 1 commit into
Open
Conversation
nazmulidris
added a commit
to r3bl-org/r3bl-open-core
that referenced
this pull request
Jun 2, 2026
Will remove this vendored crate if/when this PR is merged by the author here: dexwritescode/rust-mcp#4
nazmulidris
added a commit
to r3bl-org/r3bl-open-core
that referenced
this pull request
Jun 3, 2026
Will remove this vendored crate if/when this PR is merged by the author here: dexwritescode/rust-mcp#4
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
When configuring the
rust-refactorMCP server with an MCP client (in my case Antigravity CLIagyclient), the client fails to initialize and throws the following parser error:Cause
This occurs because the server prints non-JSON startup log messages directly to
stdout:stdiotransport protocol usesstdoutexclusively for JSON-RPC frame delivery, printing raw text tostdoutcorrupts the transport stream.Starting Rust MCP Serveras a JSON object, failing on the very first character ('S').Expected Behavior
The server should initialize and communicate with the client successfully without polluting
stdout. All startup info, telemetry, and debugging logs must be directed tostderr(usingeprintln!), leavingstdoutdedicated exclusively to raw JSON-RPC frames.Repro steps
agyin.agents/mcp_config.json) to execute therustmcpserver binary via the standardstdiotransport. For example:{ "mcpServers": { "rust-refactor": { "command": "/home/nazmul/.cargo/bin/rustmcp", "args": [] } }agy).initializerequest, but will immediately encounter a JSON parsing error (invalid character 'S' looking for beginning of value) upon reading the server'sstdout, causing the connection to abort.Fix
We changed the startup logs in
src/main.rsto write tostderrinstead ofstdoutby replacingprintln!witheprintln!:By redirecting these messages to
stderr, the JSON-RPC communication channel onstdoutremains completely clean, preventing stream corruption and allowing standardstdio-based MCP clients to successfully complete the handshake.