fix(dispatcher): preserve non-canonical numeric strings in coerce_request_id (#3432) - #3454
Conversation
…uest_id Ensure coerce_request_id only folds canonical integer strings (str(int(s)) == s) so wire-distinct JSON-RPC ids like '007', '+7', '1_000', and ' 7 ' do not collide on a shared correlation key. Fixes modelcontextprotocol#3432.
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3432. If a maintainer assigns you to #3432, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Summary
Fixes #3432.
coerce_request_id()insrc/mcp/shared/dispatcher.pypreviously converted stringified IDs using a bareint(request_id). Because Python'sint()parses leading zeros ("007"), signs ("+7"), underscores ("1_000"), whitespace (" 7 "), and non-ASCII numerals ("٧"), distinct wire-level JSON-RPC IDs collapsed onto a single integer key.This shared key backs
_pending(response correlation),_in_flight(cancellation), and progress-token routing, creating unexpected cross-wiring when distinct string IDs share an integer representation.Changes
src/mcp/shared/dispatcher.py:str(parsed) == request_idbefore folding toint. Canonical integer representations ("7","-3","0") continue folding tointfor peer interop, while non-canonical strings ("007","+7","1_000"," 7 ","٧") are preserved verbatim as distinct strings.tests/shared/test_jsonrpc_dispatcher.py:test_coerce_request_id_does_not_fold_non_canonical_numeric_stringsvalidating both preservation of non-canonical strings and folding of canonical integer strings.Verification
uv run pytest tests/shared/test_jsonrpc_dispatcher.py: 80 passed in 1.13s.uv run ruff checkanduv run ruff format --check: 100% clean.