Skip to content

fix: buffer stdout in SimpleStdioMcpClient for split/batched JSON-RPC messages#277

Open
anuragg-saxenaa wants to merge 1 commit intoFellouAI:mainfrom
anuragg-saxenaa:fix/stdio-mcp-json-parse
Open

fix: buffer stdout in SimpleStdioMcpClient for split/batched JSON-RPC messages#277
anuragg-saxenaa wants to merge 1 commit intoFellouAI:mainfrom
anuragg-saxenaa:fix/stdio-mcp-json-parse

Conversation

@anuragg-saxenaa
Copy link
Copy Markdown

Fixes #276

What

Adds proper newline-delimited JSON buffering to stdout parsing, replacing the naive single-message-per-data-event assumption.

Why

Node.js stream events do not guarantee message boundaries. The previous implementation called directly on each raw event, which:

  1. Crashes when a JSON-RPC message is split across multiple events (partial JSON)
  2. Drops messages when multiple newline-delimited JSON messages arrive in a single event (only the first would be parsed)

This is a well-known pitfall with Node.js child process stdout handling and becomes more likely with larger payloads or rapid-fire MCP tool responses.

Changes

  • Added a stdoutBuffer field to accumulate incoming data across data events
  • Split buffered data on newlines, keeping the last (potentially incomplete) segment in the buffer
  • Parse each complete line individually with error handling (try/catch + Log.warn)
  • Reset buffer on reconnect to prevent stale data from a previous session

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.

[BUG] SimpleStdioMcpClient crashes on split or batched JSON-RPC messages from stdout

1 participant