Skip to content

mcp: preserve SSE events buffered after the endpoint - #1270

Merged
guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
yyydddkkk:fix/sse-client-buffered-events
Sep 15, 2026
Merged

guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
yyydddkkk:fix/sse-client-buffered-events

Conversation

@yyydddkkk

Copy link
Copy Markdown
Contributor

SSEClientTransport.Connect creates one event scanner to read the endpoint event
and a second scanner to read subsequent messages. Each scanner owns a buffered
reader, so bytes read ahead by the first scanner are discarded when it is
abandoned. A message coalesced with the endpoint can therefore disappear while
the connection remains open.

Reuse the event scanner across the endpoint handshake and the message-reading
goroutine. This preserves unread bytes without changing the public API.

The regression test exercises Connect and Read with a controlled HTTP response
body, covering both a message coalesced with the endpoint and a message arriving
after Connect returns. On unmodified main, the separate-message control passes
and the coalesced case times out; both pass with the fix.

Validation on linux/amd64 with Go 1.26.8:

  • go test ./...
  • go test -race ./...
  • go vet ./...
  • staticcheck v0.6.1 ./...
  • gofmt and git diff --check

The HTTP response boundary is simulated; no third-party server or proxy was
used. This change concerns the legacy SSE transport. The Streamable HTTP
conformance suite was not run.

Reuse the event scanner across endpoint discovery and message reading so that events already buffered after the endpoint are retained. Add a regression test for coalesced events and a separate-delivery control.
@guglielmo-san

Copy link
Copy Markdown
Contributor

@yyydddkkk thank you for the contribution!

@guglielmo-san
guglielmo-san merged commit c1918e1 into modelcontextprotocol:main Sep 15, 2026
9 checks passed
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.

2 participants