fix: treat omitted SSE event type as default 'message' in WebClientStreamableHttpTransport#5788
Open
anuragg-saxenaa wants to merge 1 commit intospring-projects:mainfrom
Conversation
Per the SSE specification, a frame that omits the `event:` field defaults to event type `message`. WebClientStreamableHttpTransport previously only accepted frames where event.event() was exactly "message", silently dropping frames where event.event() was null or empty. This caused MCP clients to miss valid JSON-RPC responses from servers that emit bare `data:`-only SSE frames, leading to initialization timeouts. Fixes spring-projects#5780 Signed-off-by: anuragg-saxenaa <anuragg.saxenaa@gmail.com>
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.
Problem
WebClientStreamableHttpTransport.parse()only processes SSE frames whereevent.event()equals"message". Per the SSE specification, omitting theevent:field means the event type defaults to"message". When Spring/WebFlux decodes such a frame,ServerSentEvent.event()returnsnull— so the frame was silently dropped.This caused MCP clients to miss valid JSON-RPC responses from servers that emit bare
data:-only SSE frames, resulting in initialization timeouts like:Client failed to initialize by explicit API callDid not observe any item or terminal signal within ...This is the Spring AI counterpart of
modelcontextprotocol/java-sdk#885/ PR#913, which fixed theHttpClientvariant but explicitly noted theWebClientvariant needed a separate fix here.Fix
Accept all three equivalent event types for SSE message frames:
event == null(field omitted)event == ""(field present but empty)event == "message"(explicit)Testing
Added
testSseFrameWithoutEventTypeIsAccepted()toWebClientStreamableHttpTransportErrorHandlingIT— spins up a local HTTP server that returns an SSE stream with only adata:line (noevent:line) and verifies the message handler receives the parsed JSON-RPC message.Closes #5780