Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 27, 2025

Problem

The stdio MCP server was failing with "Failed to parse initialize response from stdio MCP server" errors because log messages were being written to stdout, corrupting the JSON-RPC protocol stream.

In stdio transport mode, stdout must be reserved exclusively for MCP JSON-RPC messages, but the logging system was mixing log entries with protocol messages:

{"timestamp":"2025-09-27T04:08:40.326088Z","level":"INFO",...}  # Log message
{"jsonrpc":"2.0","method":"protocol","params":{"version":"2025-06-18"}}  # Protocol message
{"timestamp":"2025-09-27T04:08:40.326364Z","level":"INFO",...}  # Another log message

This caused MCP clients to fail parsing responses, breaking the initialization handshake.

Solution

Modified the logging system to redirect all log output to stderr in stdio mode while preserving stdout logging for web/websocket modes:

  1. Enhanced init_logging function to accept a use_stderr parameter that controls output destination
  2. Updated main.rs to use stderr logging specifically for stdio transport mode
  3. Maintained backward compatibility for web and websocket modes which can safely log to stdout

After Fix

The stdio transport now produces clean JSON-RPC protocol messages on stdout:

{"jsonrpc":"2.0","method":"protocol","params":{"version":"2025-06-18"}}
{"jsonrpc":"2.0","id":1,"result":{"capabilities":{"tools":{},"resources":{...}},"protocolVersion":"2025-06-18","serverInfo":{"name":"solana-mcp-server","version":"1.1.1"}}}

All log messages are properly redirected to stderr, ensuring MCP clients can successfully parse initialize responses and complete the handshake.

Testing

  • All unit tests pass
  • MCP initialization test passes
  • Manual validation confirms clean JSON-RPC protocol stream on stdout
  • Verified proper log redirection to stderr in stdio mode
Original prompt

This section details on the original issue you should resolve

<issue_title>Failed to parse initialize response from stdio MCP server</issue_title>
<issue_description>➜ osvm-cli git:(copilot/fix-61ce1f52-d43c-4fc5-8502-1813e5b2f744) ✗ ./target/release/osvm mcp tools solana-mcp-server
🔄 Fetching tools from MCP server 'solana-mcp-server'...
❌ Failed to fetch tools from MCP server 'solana-mcp-server': Failed to parse initialize response from stdio MCP server
➜ osvm-cli git:(copilot/fix-61ce1f52-d43c-4fc5-8502-1813e5b2f744) ✗ </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #39

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@devloai
Copy link

devloai bot commented Sep 27, 2025

Unable to perform a code review. You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

Copilot AI changed the title [WIP] Failed to parse initialize response from stdio MCP server Fix stdio MCP server: redirect logging to stderr to prevent protocol corruption Sep 27, 2025
Copilot finished work on behalf of 0xrinegade September 27, 2025 04:25
Copilot AI requested a review from 0xrinegade September 27, 2025 04:25
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.

Failed to parse initialize response from stdio MCP server

2 participants