Skip to content

Parse SSE responses in the stdio bridge - #3

Open
MrTig-afk wants to merge 1 commit into
nitrosend:mainfrom
MrTig-afk:feat/bridge-sse-responses
Open

Parse SSE responses in the stdio bridge#3
MrTig-afk wants to merge 1 commit into
nitrosend:mainfrom
MrTig-afk:feat/bridge-sse-responses

Conversation

@MrTig-afk

Copy link
Copy Markdown

The bridge sends Accept: application/json, text/event-stream on 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 raw event:/data: framing to stdout, breaking JSON-RPC framing for every stdio client. The published npm artifact reproduces this.

Changes:

  • Responses with Content-Type: text/event-stream are parsed incrementally. Each event's data payload 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.
  • If the stream ends without a message carrying the request id, the bridge emits a JSON-RPC error instead of leaving the client waiting.
  • JSON responses are passed through unchanged.

Tests: two cases added to bridge-serialization-test.mjs in 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.

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