Skip to content

[v1.x] fix(stdio): strip a leading UTF-8 byte order mark before parsing a message - #2796

Draft
errmakov wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
errmakov:fix/stdio-bom-2775-v1.x
Draft

[v1.x] fix(stdio): strip a leading UTF-8 byte order mark before parsing a message#2796
errmakov wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
errmakov:fix/stdio-bom-2775-v1.x

Conversation

@errmakov

Copy link
Copy Markdown

Backport of #2790 to v1.x. Part of #2775 (the byte order mark case).

On v1.x, when a stdio peer prefixes a message with a UTF-8 BOM, ReadBuffer.readMessage() throws a SyntaxError. The transport reports it on onerror, the message is lost, and the pending request waits for its timeout. Against @modelcontextprotocol/sdk@1.30.0 with a 2 s timeout, the call fails with MCP error -32001: Request timed out.

Same change as on main: strip a leading U+FEFF from each line before parsing (RFC 8259 §8.1), and leave a U+FEFF inside a message alone.

Tests cover a BOM-prefixed message, a BOM split across chunks with a CRLF line ending, a U+FEFF inside a string, and a spawned server writing a BOM through StdioClientTransport. npm run lint, npm run build, npm run typecheck and the stdio tests pass. In the full npm test run, the only failure was processCleanup.test.ts timing out under load; it passes on its own.

Opened as a draft only because GitHub lets this account keep one non-draft PR here; the branch is complete and ready to merge after #2790.


AI disclosure: this PR was written with the help of Claude Code.

…ssage

When a peer prefixed a message with a UTF-8 BOM (as some Windows tools
and shell redirections do), JSON.parse rejected the line: the transport
reported a SyntaxError on onerror, the message was lost, and the pending
request waited for its timeout.

Strip a leading U+FEFF from each line before parsing, which RFC 8259
§8.1 allows. A U+FEFF inside the message is left alone.

Backport of the same fix on main. Refs modelcontextprotocol#2775

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8hmy9JVNHqYDYEX5KBYye
@changeset-bot

changeset-bot Bot commented Sep 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8786f75

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 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 8786f75

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