Parse SSE responses in the stdio bridge - #3
Open
MrTig-afk wants to merge 1 commit into
Open
Conversation
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.
The bridge sends
Accept: application/json, text/event-streamon every request but only parses JSON response bodies. The Streamable HTTP transport allows a server to answer any POST with an SSE stream, and the official TS SDK server transport does so by default. If the API ever responds with SSE, the bridge writes rawevent:/data:framing to stdout, breaking JSON-RPC framing for every stdio client. The published npm artifact reproduces this.Changes:
Content-Type: text/event-streamare parsed incrementally. Each event'sdatapayload is re-serialized before writing, so stdout stays one JSON-RPC message per line regardless of server framing, and embedded newlines cannot inject additional messages. Notifications are forwarded in arrival order.Tests: two cases added to
bridge-serialization-test.mjsin the existing style. An SSE response with a notification before the result yields two clean lines in order (CRLF and comment lines tolerated), and a stream that closes without a result yields an error with the request id preserved.npm run test:bridge: 5/5.Note for Windows: Node 24 crashes the spawned bridge with a libuv teardown assertion regardless of this change. Node 20/22 run the suite clean.