Repository navigation
Conversation
The streamable servlet's GET handler set the SSE headers, started async, and then waited for the session to write something. The container only commits the response when the first event is written, so a client that waits for the response before it starts reading - Node's fetch/undici, mcp-remote - gave up on an idle server with UND_ERR_HEADERS_TIMEOUT, retried twice, and ended up with no listening stream at all. Flush the response right after startAsync so the status line and headers reach the client immediately, the same way HttpServletMcpTransport does for the stateless transport. Refs modelcontextprotocol#1155
This branch has not been deployed
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.
A GET to the streamable endpoint sets the SSE headers, starts async, and then waits for the session to write something. Nothing commits the response until that first event, so a client that waits for the response before reading blocks: Node's
fetch(undici) fails withUND_ERR_HEADERS_TIMEOUTafter its 300 s default,mcp-remoteretries twice and gives up, and the server is left without a listening stream, which also breaks server-initiated requests (Stream unavailable for session).response.flushBuffer()right afterstartAsync()commits the status line and headers. That is the same callHttpServletMcpTransportalready makes for the stateless transport.Verification (Windows, JDK 21):
HttpServletStreamableIntegrationTests#listeningStreamCommitsResponseBeforeFirstEventopens a listening stream against a provider without keep-alive, so nothing will ever be written to it. It asserts the client gets200plusContent-Type: text/event-streamwithin 5 s. Before the fix the same test times out insendAsync(...).get(...); with the flush it returns in ~2 s../mvnw -pl mcp-test -am test -Dtest='HttpServletStreamableIntegrationTests#listeningStreamCommitsResponseBeforeFirstEvent'passes.spring-javaformat:applywas run, the build'svalidatephase is clean.Fixes #1155