Skip to content

fix(dispatcher): preserve non-canonical numeric strings in coerce_request_id (#3432) - #3454

Closed
amasen02 wants to merge 1 commit into
modelcontextprotocol:mainfrom
amasen02:fix/coerce-request-id-canonical-int-3432
Closed

fix(dispatcher): preserve non-canonical numeric strings in coerce_request_id (#3432)#3454
amasen02 wants to merge 1 commit into
modelcontextprotocol:mainfrom
amasen02:fix/coerce-request-id-canonical-int-3432

Conversation

@amasen02

@amasen02 amasen02 commented Sep 5, 2026

Copy link
Copy Markdown

Summary

Fixes #3432.

coerce_request_id() in src/mcp/shared/dispatcher.py previously converted stringified IDs using a bare int(request_id). Because Python's int() 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

  • In src/mcp/shared/dispatcher.py:
    • When parsing string request IDs, verify str(parsed) == request_id before folding to int. Canonical integer representations ("7", "-3", "0") continue folding to int for peer interop, while non-canonical strings ("007", "+7", "1_000", " 7 ", "٧") are preserved verbatim as distinct strings.
  • In tests/shared/test_jsonrpc_dispatcher.py:
    • Added test_coerce_request_id_does_not_fold_non_canonical_numeric_strings validating both preservation of non-canonical strings and folding of canonical integer strings.

Verification

  • Run uv run pytest tests/shared/test_jsonrpc_dispatcher.py: 80 passed in 1.13s.
  • Checked with uv run ruff check and uv run ruff format --check: 100% clean.

…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.
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coerce_request_id() folds non-canonical numeric strings, conflating wire-distinct JSON-RPC ids

1 participant