Skip to content

fix: send server discovery logs to stderr to avoid corrupting MCP stdout on Windows#222

Open
pntgoswami18 wants to merge 1 commit intoAgentDeskAI:mainfrom
pntgoswami18:fix/stdout-discovery-logs-windows
Open

fix: send server discovery logs to stderr to avoid corrupting MCP stdout on Windows#222
pntgoswami18 wants to merge 1 commit intoAgentDeskAI:mainfrom
pntgoswami18:fix/stdout-discovery-logs-windows

Conversation

@pntgoswami18
Copy link

Issue

On Windows (and in any setup where the MCP client expects only JSON-RPC on stdout), the server can fail during initialization with:

Error: calling "initialize": invalid character 'S' looking for beginning of value

The MCP protocol reserves stdout for JSON-RPC messages only. This codebase already patches process.stdout.write so that only JSON-like output is sent (see the block after new StdioServerTransport()). That patch is applied after discoverServer() runs. Meanwhile, discoverServer() uses console.log() for messages such as "Starting server discovery process" and "Successfully discovered server at...". Those go to stdout and are sent to the MCP client before the filter is active, so the client sees raw text (e.g. starting with S) instead of a JSON message and fails to parse.

Solution

Send all server-discovery logging to stderr instead of stdout by changing the console.log calls inside discoverServer() to console.error. Discovery messages remain visible for debugging but no longer corrupt the JSON-RPC channel. No wrapper script or new dependencies; the fix is confined to logging in discoverServer().

Other console.log calls in this file have been switched to console.error for consistency, so all diagnostic output uses stderr.

Testing

  • Run the MCP server with the browser-tools-server and Chrome extension; confirm initialization completes without "invalid character" errors.
  • On Windows, run the same flow and confirm the server starts and responds to tool calls.

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