[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
Draft
[v1.x] fix(stdio): strip a leading UTF-8 byte order mark before parsing a message#2796errmakov wants to merge 1 commit into
errmakov wants to merge 1 commit into
Conversation
…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 detectedLatest 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 |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aSyntaxError. The transport reports it ononerror, the message is lost, and the pending request waits for its timeout. Against@modelcontextprotocol/sdk@1.30.0with a 2 s timeout, the call fails withMCP 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 typecheckand the stdio tests pass. In the fullnpm testrun, the only failure wasprocessCleanup.test.tstiming 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.