fix(mcp): SSE JSON-RPC decoding#58
Closed
hunner wants to merge 1 commit into
Closed
Conversation
Collaborator
Author
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.
Summary
This fixes how Atryum handles JSON-RPC responses from upstream MCP servers when those responses are delivered as
text/event-streaminstead of plainapplication/json.initializeand missing-session retry responses with focused MCP client tests.MCP Control Flow
There are two separate MCP legs involved:
The relevant response path is:
What Was Broken
Before this change, the upstream HTTP transport layer saw
Content-Type: text/event-stream, extracted the firstdata:frame immediately, changed the response internally to look likeapplication/json, and returned only that extracted JSON payload.That made some current request/response paths work, but it mixed transport handling with JSON-RPC parsing:
That is fragile because generic forwarding and future streaming/task work need to know what the upstream actually returned. It also meant retry and initialize paths could drift from normal response parsing.
How This PR Fixes It
This PR keeps transport and parsing responsibilities separate:
The new helper decodes JSON-RPC like this:
This keeps the existing one-response semantics for
initialize,tools/list, andtools/call, while making the lower-level transport representation honest. Full upstream streaming support is still a larger follow-up; this PR is the narrow correctness fix that makes the current behavior safer.Tests
go test ./...Added focused MCP client coverage for:
initialize.