fix: send priming event in GET handler to prevent hang#1883
Open
wukai9203 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: send priming event in GET handler to prevent hang#1883wukai9203 wants to merge 1 commit intomodelcontextprotocol:mainfrom
wukai9203 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
The GET request handler in streamable_http.py was missing the priming event that the POST handler sends. This caused GET requests to /mcp endpoint to hang indefinitely while waiting for messages. Fix: - Send a priming event immediately after establishing the SSE connection in standalone_sse_writer() - When event_store is configured and protocol >= 2025-11-25, use the proper priming event with resumability support - Otherwise, send a simple "open" event to confirm connection is established - Add anyio.ClosedResourceError handling for clean shutdown - Store SSE writer reference for close_standalone_sse_stream() to work Related: jlowin/fastmcp#532
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
GET requests to
/mcpendpoint hang indefinitely when usingstreamable_http_app().Related issue in FastMCP: jlowin/fastmcp#532
Root Cause
The
_handle_get_requestmethod'sstandalone_sse_writerfunction doesn't send a priming event before entering the message loop, unlike the POST handler which calls_maybe_send_priming_event()at line 592.This causes the SSE writer to block waiting for messages that may never arrive, making the GET request appear to hang.
Solution
Send an event immediately after establishing the SSE connection in
standalone_sse_writer():_maybe_send_priming_event()(for SSE resumability support){"event": "open", "data": ""}event to confirm connection is establishedAdditional fixes:
anyio.ClosedResourceErrorhandling for clean shutdown whenclose_standalone_sse_stream()is calledclose_standalone_sse_stream()can properly close itTesting
test_get_request_receives_priming_event_with_event_storeto verify the fixChecklist