Skip to content

[v1.x] fix(stdio): skip non-JSON lines in ReadBuffer (backport of #1762) - #2872

Open
constantbourgois wants to merge 2 commits into
modelcontextprotocol:v1.xfrom
constantbourgois:fix/780-skip-non-json-lines-v1
Open

constantbourgois wants to merge 2 commits into
modelcontextprotocol:v1.xfrom
constantbourgois:fix/780-skip-non-json-lines-v1

Conversation

@constantbourgois

Copy link
Copy Markdown

Fixes #780 on v1.x.

Cause: ReadBuffer.readMessage() passes every stdout line to JSON.parse. When a stdio server prints a non-JSON line (e.g. Shutting down server... on close), a SyntaxError surfaces via onerror.

Fix: backport of #1762 from main: loop over buffered lines and skip those that throw SyntaxError. Valid JSON that fails schema validation still throws.

Repro (1.30.1): a stdio server that writes Shutting down server...\n to stdout when stdin ends; connect a Client with StdioClientTransport, then client.close() → onerror: Unexpected token 'S', "Shutting d"... is not valid JSON. With this patch: no error.

Tests: ported the non-JSON line filtering suite from main (8 tests; 5 fail without the fix). Full suite + lint pass.

@constantbourgois
constantbourgois requested a review from a team as a code owner September 25, 2026 09:18
@changeset-bot

changeset-bot Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cc28f01

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@2872

commit: cc28f01

@constantbourgois
constantbourgois marked this pull request as ready for review September 25, 2026 09:31
@claude claude Bot added the v1 Issues / PRs related to v1.x label Sep 26, 2026

This branch has not been deployed

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

Labels

v1 Issues / PRs related to v1.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant