Repository navigation
fix(mcp): decode complete multiline SSE events - #8
Conversation
Balanov
left a comment
There was a problem hiding this comment.
Thank you for this, and for the framing in the issue: the SSE framing was wrong, not the transport.
Decoding each data: line as a whole JSON-RPC message was the bug. In SSE a data: field belongs to an event, and one event may carry several of them. Your fix collects the fields of a single event, joins them with newlines and decodes once at the terminating blank line, which is what the framing asks for.
Two details I checked:
- the response is decoded into a fresh value per event, so an ignored notification or an error for another request id cannot leave an error behind in the reply that eventually matters. The test with an unrelated error covers exactly that.
- request-id filtering, the transport limits and the JSON/stdio paths are untouched, and the single-line case still works, so this fixes the broken case rather than rewriting the client.
The seven cases in the table are the right set: multiline, CRLF, a notification before the response, an unrelated error, a multiline error, a single line, and two events that must not be joined.
Merging this. It ships in shim 0.1.2.
|
Fixed by pull request #8, which is merged and released in shim 0.1.2. The MCP HTTP client now collects the Thank you for the report and for the fix. |
Fixes #7.
The MCP HTTP client currently decodes each SSE
data:line as a whole JSON-RPC reply. Valid multi-line events therefore fail, including during initialization.Collect data fields within one event, join them with newlines, and decode only at the terminating blank line. Decode into a fresh response per event so ignored messages cannot leave an error in the eventual reply. Preserve request-ID filtering, the existing transport limits and the JSON/stdio paths. No new dependencies.
Validation on Windows x64 / Go1.25.14:
httptestcases: original5 fail/2 pass; fixed7 pass. Covers LF/CRLF, preceding notifications/comments/metadata, ignored-error isolation, multi-line errors, existing single-line replies and separate events not being joined.echo, and calls it successfully. No model/provider calls.go fmt ./...,go test ./... -count=1 -v,go vet ./..., andgo build -trimpath ./cmd/shimpass. The test command includes all packages; no exclusions or upstream configuration changes.References: SSE event parsing, MCP2025-03-26 transport.
AI assistance: Codex generated the patch/tests and ran these checks under curforever's authorization. Linux/macOS and real remote MCP servers were not locally tested; no personal human review or full SSE conformance is claimed.