Skip to content

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

Description

@anuragg-saxenaa

Description

The in parses stdout data incorrectly. The event handler assumes each event contains exactly one complete JSON message:

this.process.stdout.on("data", (data) => {
    const response = data.toString().trim();
    if (!response.startsWith("{")) {
        return;
    }
    const message = JSON.parse(response);

Node.js streams do not guarantee message boundaries. A single event may contain:

  • A partial JSON message (split across events)
  • Multiple JSON messages concatenated together
  • A mix of both

This causes:

  1. JSON.parse throws on partial messages, crashing the client
  2. Messages are silently dropped when multiple arrive in one chunk (only the first is parsed)

Steps to Reproduce

  1. Use with any MCP server that sends responses rapidly or sends large responses
  2. The stdout buffer may deliver partial or batched messages
  3. crashes or only the first message is parsed

Expected Behavior

The client should buffer incoming data and correctly parse newline-delimited JSON messages, handling partial reads and batched data.

Environment

  • Package:
  • File:

Additional Context

The JSON-RPC over stdio protocol uses newline-delimited JSON. The fix should accumulate a buffer and split on newlines, parsing complete lines only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions