Title: streamable_http client call_tool hangs when receiving invalid JSONRPCMessage · Issue #1144 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: streamable_http client call_tool hangs when receiving invalid JSONRPCMessage · Issue #1144 · modelcontextprotocol/python-sdk
X Title: streamable_http client call_tool hangs when receiving invalid JSONRPCMessage · Issue #1144 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description Issue Description: Dur...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/1144
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"streamable_http client call_tool hangs when receiving invalid JSONRPCMessage","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\nIssue Description:\nDuring testing, we encountered a critical issue in the Server-Sent Events (SSE) handling mechanism:\n\n1. Problem Trigger:\nTo some reason, the `_handle_sse_event` method received a truncated `sse.data` payload, causing:\nA JSON parsing exception `message = JSONRPCMessage.model_validate_json(sse.data)`\nThen the exception handle sent the exc and returned false\n2. Current Behavior Gap:\nDespite the failed processing:\n·No error propagation to the client occurs\n·No cleanup/retry mechanism is triggered\n·The client remains stuck in a perpetual wait state for a tool_call result until timeout\n3. Critical Impact: The server has already completed the tool_call workflow and moved to the final /done state, creating a state desynchronization between client and server\n4. Root Cause Hypothesis:\nIt appears that the client failed to detect the reception of invalid responses. The `await read_stream_writer.send(exc)` did not work during exception handling\n\nOr maybe I missed some configs such as the retry mechanism or other error handling methods?\n\n### Example Code\n\n```Python\nasync def _handle_sse_event(\n self,\n sse: ServerSentEvent,\n read_stream_writer: StreamWriter,\n original_request_id: RequestId | None = None,\n resumption_callback: Callable[[str], Awaitable[None]] | None = None,\n is_initialization: bool = False,\n) -\u003e bool:\n \"\"\"Handle an SSE event, returning True if the response is complete.\"\"\"\n if sse.event == \"message\":\n try:\n message = JSONRPCMessage.model_validate_json(sse.data) ##### threw the exception\n logger.debug(f\"SSE message: {message}\")\n\n # Extract protocol version from initialization response\n if is_initialization:\n self._maybe_extract_protocol_version_from_message(message)\n\n # If this is a response and we have original_request_id, replace it\n if original_request_id is not None and isinstance(message.root, JSONRPCResponse | JSONRPCError):\n message.root.id = original_request_id\n\n session_message = SessionMessage(message)\n await read_stream_writer.send(session_message)\n\n # Call resumption token callback if we have an ID\n if sse.id and resumption_callback:\n await resumption_callback(sse.id)\n\n # If this is a response or error return True indicating completion\n # Otherwise, return False to continue listening\n return isinstance(message.root, JSONRPCResponse | JSONRPCError)\n\n except Exception as exc:\n ##### handled exception but client did not receive ######\n logger.exception(\"Error parsing SSE message\")\n await read_stream_writer.send(exc)\n return False\n else:\n logger.warning(f\"Unknown SSE event: {sse.event}\")\n return False\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\npython == 3.12\nSDK == 1.11.0\n```","author":{"url":"https://github.com/Nuclear2","@type":"Person","name":"Nuclear2"},"datePublished":"2025-07-15T02:32:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/1144/python-sdk/issues/1144"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3acdecf9-cdb0-4c31-c415-58e6d6b50227 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE26:DD39B:1383FB3:1BE3BFC:6A634668 |
| html-safe-nonce | b12d7203300155149c18c7a672fc8bbe9a408e2528cf3c38c7812377ee58080b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTI2OkREMzlCOjEzODNGQjM6MUJFM0JGQzo2QTYzNDY2OCIsInZpc2l0b3JfaWQiOiI1NTAzMTM2NjY3NTI3MjM1MTc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1b6da07afb900046e2d562c55b624365d2e1e88eb6366b83249bf2dd238b2806 |
| hovercard-subject-tag | issue:3230553155 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/1144/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1f19f6d85a7691932289f6819dd18f15bd7b4929a394140985114ef183b68aa6/modelcontextprotocol/python-sdk/issues/1144 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f19f6d85a7691932289f6819dd18f15bd7b4929a394140985114ef183b68aa6/modelcontextprotocol/python-sdk/issues/1144 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Nuclear2 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59e55daad7174ca59d63c6974d58276ccb5477442e550bebb3c035e1bef11c94 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 990295d92a4cc7b63fbbd83a046217cd7d77d49c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width