Title: streamable HTTP: integer and string request ids with the same text share one response stream; a string id can displace the GET stream · Issue #3786 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: streamable HTTP: integer and string request ids with the same text share one response stream; a string id can displace the GET stream · Issue #3786 · modelcontextprotocol/python-sdk
X Title: streamable HTTP: integer and string request ids with the same text share one response stream; a string id can displace the GET stream · Issue #3786 · modelcontextprotocol/python-sdk
Description: Summary StreamableHTTPServerTransport keys its per-request response streams by str(request_id). JSON-RPC and MCP allow a request id to be an integer or a string, and an integer 77 and a string "77" are different ids. After str() they map...
Open Graph Description: Summary StreamableHTTPServerTransport keys its per-request response streams by str(request_id). JSON-RPC and MCP allow a request id to be an integer or a string, and an integer 77 and a string "77"...
X Description: Summary StreamableHTTPServerTransport keys its per-request response streams by str(request_id). JSON-RPC and MCP allow a request id to be an integer or a string, and an integer 77 and a string &quo...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3786
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"streamable HTTP: integer and string request ids with the same text share one response stream; a string id can displace the GET stream","articleBody":"### Summary\n\n`StreamableHTTPServerTransport` keys its per-request response streams by `str(request_id)`. JSON-RPC and MCP allow a request id to be an integer **or** a string, and an integer `77` and a string `\"77\"` are different ids. After `str()` they map to the same key, so two valid, distinct in-flight requests on one session share one response stream.\n\nThe same string namespace holds the standalone GET stream's sentinel key, `GET_STREAM_KEY = \"_GET_stream\"`. A request whose id is the string `\"_GET_stream\"` replaces the GET stream's registration.\n\nThis is distinct from #3060 / #2655 / #3137, which cover a client **reusing the same id**. Here the ids are different under the spec and still collide.\n\n### Where\n\n`src/mcp/server/streamable_http.py` on v1.30.0 and v2.3.0 (latest at time of writing):\n- v2.3.0: `request_id = str(message.id)` (~:642), `target_request_id = str(message.id)` (~:1066), `target_request_id = str(related_request_id)` (~:1083), and `GET_STREAM_KEY = \"_GET_stream\"` (:62);\n- v1.30.0: the same sites at ~:599, ~:1063 and ~:1076, and :63.\n\n### Reproduction\n\nUse the stateful streamable HTTP server, unmodified SDK, a real TCP client, and one protocol session.\n\n1. Send two concurrent requests with ids `77` (integer) and `\"77\"` (string), each to a slow tool.\n2. Cancel only the integer `77` (`notifications/cancelled` with `requestId: 77`).\n3. **Observed:** the HTTP stream of the **string** `\"77\"` request receives integer `77`'s cancellation response. The string request's own handler was not cancelled, but its response is lost or misdelivered.\n4. **Sentinel variant:** with a GET stream open, send a request with id `\"_GET_stream\"`. Its POST registration replaces the GET stream's. The next server notification is lost, and a second GET is accepted (200) instead of being refused (409).\n\n**Matrix (JSON and SSE response modes × normal completion and cancellation × 7 id patterns):**\n- All 12 collision cells misroute: integer/string in both orders, plus the zero case `0` and `\"0\"`.\n- All 16 controls deliver correctly: integer-only, string-only, distinct mixed ids, and strings that cannot collide.\n\n### Expected\n\nResponses route to the request with the exact same typed id. A string id never displaces the GET stream.\n\n### Proposed fix\n\nDerive the internal stream key with one stateless, injective request-id-to-key helper, used at all three conversion sites, and keep a separate namespace for the GET sentinel. Wire ids stay unchanged.\n\nPublic `close_sse_stream(request_id)` should keep accepting the raw request id. A private helper should close by derived key. Replacing `str()` with `json.dumps()` alone looks like a fix, but it breaks raw-id `close_sse_stream` for string ids.\n\n","author":{"url":"https://github.com/WingedGuardian","@type":"Person","name":"WingedGuardian"},"datePublished":"2026-10-29T19:43:17Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3786"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:820ff421-4b65-c344-dd68-3902540051ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B13C:C2718:CBCE:1096A:6B00B72C |
| html-safe-nonce | 9c966fe1f55553c0198ef75e94fa5e18bb43e7cc365b6fb08f7917f333d4542d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTNDOkMyNzE4OkNCQ0U6MTA5NkE6NkIwMEI3MkMiLCJ2aXNpdG9yX2lkIjoiNTUzMDYxOTE3MTEyNzIxMTgyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 24b0e07a0b6dfd9ad05fcc2b34ed3686c2014d3dcf472acb1e446bdfe90a9bc8 |
| hovercard-subject-tag | issue:6107244472 |
| 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/3786/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e73ad5e8c65d96d7bf24ff1f9059fb0c54b81a245da30084fd7e137e710f36f1/modelcontextprotocol/python-sdk/issues/3786 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e73ad5e8c65d96d7bf24ff1f9059fb0c54b81a245da30084fd7e137e710f36f1/modelcontextprotocol/python-sdk/issues/3786 |
| og:image:alt | Summary StreamableHTTPServerTransport keys its per-request response streams by str(request_id). JSON-RPC and MCP allow a request id to be an integer or a string, and an integer 77 and a string "77"... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | WingedGuardian |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d07c25977adfc5ff6acb0a962a9bc168c07afbda6fef765f9761c350c2ae4a2 |
| 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 | 5429cbfc6aca8c7b9a086a3c8f47400346f38cc9 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width