Skip to content

Keep stdout for JSON-RPC in four stdio servers: print diagnostics to stderr - #79

Open
vishalhabib99 wants to merge 1 commit into
SalesforceAIResearch:mainfrom
vishalhabib99:fix/stdio-servers-print-to-stderr
Open

vishalhabib99 wants to merge 1 commit into
SalesforceAIResearch:mainfrom
vishalhabib99:fix/stdio-servers-print-to-stderr

Conversation

@vishalhabib99

Copy link
Copy Markdown

Problem

The bundled yfinance, google-sheets, jina_scrape_llm_summary and serper-search servers run over stdio by default (--transport defaults to stdio, and server_list.json starts them with python3 -m mcpuniverse.mcp.servers.<name>). On stdio, stdout is the JSON-RPC stream, but these servers report errors and progress with bare print(). For example yahoo_finance/server.py prints Company ticker {ticker} not found. whenever a tool gets an unknown ticker, which agents do often in the finance tasks.

Python buffers stdout on a pipe, so the printed text isn't visible at first. Once about 8 KB has built up, it flushes into the stream mid-frame, the client gets a line that isn't JSON-RPC, and that response is lost:

pydantic_core._pydantic_core.ValidationError: 1 validation error for JSONRPCMessage
  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='Company ticker BAD not f...nd."},"isError":false}}', input_type=str]

Change

In those four servers, every print(...) now passes file=sys.stderr (62 calls), and import sys is added where missing. The messages are unchanged and still visible (MCP clients show or log server stderr). No other changes. Three lines that would pass 120 characters put file=sys.stderr on its own line, so pylint mcpuniverse stays clean.

Checked

I reproduced it with a minimal FastMCP server written like yahoo_finance (a tool that prints Company ticker ... not found. and returns the same text), driven by the mcp stdio client, mcp 1.30.0:

400 calls with an unknown ticker
print(...) (main) call 274 fails: the flushed text lands inside a JSON-RPC frame (ValidationError ... json_invalid)
print(..., file=sys.stderr) (this branch) all 400 succeed

The four files still parse, and no print() without file= is left in them. I didn't run the servers against their live APIs (Yahoo Finance, Google Sheets, Jina, Serper).

@salesforce-cla

salesforce-cla Bot commented Nov 2, 2026

Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @vishalhabib99 to sign the Salesforce Inc. Contributor License Agreement.

@vishalhabib99

Copy link
Copy Markdown
Author

I've signed the Salesforce CLA; commenting so the check re-runs.

@vishalhabib99
vishalhabib99 force-pushed the fix/stdio-servers-print-to-stderr branch from 519bff3 to 61afddd Compare November 2, 2026 21:40
@vishalhabib99

Copy link
Copy Markdown
Author

Hi, just checking whether this one is on your radar. Four bundled stdio servers print() to stdout, which is the JSON-RPC stream. This sends those messages to stderr. The CLA check now passes. Happy to change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant