Title: coerce_request_id() folds non-canonical numeric strings, conflating wire-distinct JSON-RPC ids · Issue #3432 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: coerce_request_id() folds non-canonical numeric strings, conflating wire-distinct JSON-RPC ids · Issue #3432 · modelcontextprotocol/python-sdk
X Title: coerce_request_id() folds non-canonical numeric strings, conflating wire-distinct JSON-RPC ids · Issue #3432 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before openi...
Open Graph Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex...
X Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/mod...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3432
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"coerce_request_id() folds non-canonical numeric strings, conflating wire-distinct JSON-RPC ids","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Release line\n\n2.x (current stable)\n\n### Description\n\nOn current `main`, `coerce_request_id()` in `src/mcp/shared/dispatcher.py` folds a stringified id to int with a bare `int(request_id)`. That accepts a lot more than a canonical integer string, so ids that are distinct on the JSON-RPC wire collapse onto one correlation key:\n\n```\ncoerce_request_id('007') -> 7\ncoerce_request_id('+7') -> 7\ncoerce_request_id('1_000') -> 1000\ncoerce_request_id(' 7 ') -> 7\ncoerce_request_id('٧') -> 7\n```\n\nThis shared key backs `_pending` (response correlation), `_in_flight` (cancellation), and progress-token routing. So a peer, or a caller using `CallOptions[\"request_id\"]`, that uses e.g. `10` and `\"1_0\"` as two ids has them merged. A `notifications/cancelled` for one hits the other, and the first can't be cancelled. It's the same cross-wiring class as #3060, but between ids that are genuinely different on the wire.\n\nJSON-RPC 2.0 treats String and Number ids as distinct value types, and the function's own intent (and its test, `\"7\" -> 7`) is the canonical \"peer stringified an int\" case. The forms above aren't that. They're an artifact of Python's `int()`. The docstring says \"matches the TS SDK\", but JS `Number(\"1_000\")` is `NaN` and `Number(\"0x10\")` is `16`, so today's behavior matches neither.\n\nThe narrow fix is to fold only when the string equals `str(int(s))`, which keeps the intended `\"7\" -> 7` and `\"-3\" -> -3` behavior and leaves every other string a distinct id. I have a patch and a regression test for it (both dispatchers share the function) and I'm happy to open a PR once this is triaged and assigned.\n\nDisclosure: I used an AI coding assistant to help explore the code and draft this. I verified the reproduction and understand the fix myself.\n\n### Example Code\n\n```python\nfrom mcp.shared.dispatcher import coerce_request_id\n\nfor raw in (\"007\", \"+7\", \"1_000\", \" 7 \", \"٧\"):\n print(repr(raw), \"->\", repr(coerce_request_id(raw)))\n# every line prints an int, so all five distinct wire ids share one key\n```\n\n### Python & MCP Python SDK\n\nPython 3.11.14, python-sdk `main` @ 5bc9e07, macOS\n","author":{"url":"https://github.com/2sumtech","@type":"Person","name":"2sumtech"},"datePublished":"2026-09-02T16:41:00Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3432"}
| 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:29441fcb-79c1-a132-bca6-2c1caa06ea66 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8EDC:3F8AB1:AFAEB:E9196:6B00B9A3 |
| html-safe-nonce | ba94d35f4d45b7a45e68b9f2a09f7c20f8eff2f807787d77ff338511a6a61b4b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RURDOjNGOEFCMTpBRkFFQjpFOTE5Njo2QjAwQjlBMyIsInZpc2l0b3JfaWQiOiIyMDc1MTk0ODg3NzMyNTA5MDkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3de426ff9e852e473beb093a4abfacb91ea2fa488d1579e37c32f229e148f942 |
| hovercard-subject-tag | issue:5326629895 |
| 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/3432/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c731a9cb126c555a314ddd87511ac27bfab0401d99dce52b7eff046e57a4b6a1/modelcontextprotocol/python-sdk/issues/3432 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c731a9cb126c555a314ddd87511ac27bfab0401d99dce52b7eff046e57a4b6a1/modelcontextprotocol/python-sdk/issues/3432 |
| og:image:alt | Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 2sumtech |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width