fix(client): unblock streamable HTTP calls on early SSE close#3052
Draft
Sehlani042 wants to merge 1 commit into
Draft
fix(client): unblock streamable HTTP calls on early SSE close#3052Sehlani042 wants to merge 1 commit into
Sehlani042 wants to merge 1 commit into
Conversation
d988475 to
194f0dc
Compare
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.
Summary
Fixes a streamable HTTP client hang when a POST request receives an SSE response that closes before sending a JSON-RPC response.
This targets #1577. It overlaps with the older #1578, but keeps the current-main patch narrow: preserve the existing reconnect behavior when a resumable event id is available, and only resolve the pending request with the existing SDK
CONNECTION_CLOSEDerror when there is no response and no resumable event to follow.Root Cause
_handle_sse_response()consumed the POST SSE stream and returned silently if the stream ended before a response and noLast-Event-IDhad been observed. Because noJSONRPCErroror transport exception was written to the read stream, the JSON-RPC dispatcher kept the correspondingcall_tool()waiter pending forever.Changes
JSONRPCError(CONNECTION_CLOSED)when a POST SSE response closes before a reply and cannot be resumed.CONNECTION_CLOSEDif reconnection attempts are exhausted.call_tool()raises instead of hanging.Validation
uv run --frozen pytest tests/client/test_notification_response.py::test_empty_post_sse_response_unblocks_pending_tool_call -quv run --frozen pytest tests/client/test_notification_response.py -quv run --frozen pytest tests/shared/test_streamable_http.py -quv run --frozen ruff format src/mcp/client/streamable_http.py tests/client/test_notification_response.py --checkuv run --frozen ruff check src/mcp/client/streamable_http.py tests/client/test_notification_response.pyuv run --frozen pyright src/mcp/client/streamable_http.py tests/client/test_notification_response.pyuv run --frozen coverage erase && uv run --frozen coverage run -m pytest tests/client/test_notification_response.py tests/shared/test_streamable_http.py && uv run --frozen coverage combine && uv run --frozen coverage report --include='src/mcp/client/streamable_http.py' --fail-under=0 && UV_FROZEN=1 uv run --frozen strict-no-cover