René's URL Explorer Experiment


Title: fix: never mint a request id already used by a completed caller-supplied id by ayaangazali · Pull Request #3127 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: fix: never mint a request id already used by a completed caller-supplied id by ayaangazali · Pull Request #3127 · modelcontextprotocol/python-sdk

X Title: fix: never mint a request id already used by a completed caller-supplied id by ayaangazali · Pull Request #3127 · modelcontextprotocol/python-sdk

Description: Summary Fixes #3126. When a caller supplies its own request id via CallOptions["request_id"], the dispatcher's minted-id sequence could later land on that same id once the supplied request completed, sending two different requests under one id in the same session. The spec says the requestor must never reuse a request id within a session, and the SDK pins the same rule as protocol:request-id:unique in tests/interaction/_requirements.py. Root cause Both mint loops only skipped ids still in flight: request_id = self._allocate_id() while request_id in self._pending: # entries are popped on completion request_id = self._allocate_id() The comment right above ("Mint past any key a supplied id occupies") shows the intent, but the guard stopped holding the moment the supplied request completed. Since coerce_request_id folds "2" and 2 into one key, numeric-string ids hit this too. DirectDispatcher had the same pattern with _in_flight_ids (discarded in a finally). Fix Accepting a supplied id now advances the mint counter past its coerced integer key: if isinstance(pending_key, int): self._next_id = max(self._next_id, pending_key) That makes the old skip loops provably unreachable (the counter is always past every supplied integer key and every previously minted id), so they are removed rather than left as dead branches the coverage gate would flag. Two deliberate scope notes: A caller re-supplying its own completed id stays allowed; that behavior is asserted by test_send_raw_request_with_in_flight_request_id_raises_and_frees_id_on_completion and this PR does not touch it. Only the dispatcher's own minting is constrained. Minted id values shift when a caller supplies integer ids (e.g. the pinned sequence in test_minted_ids_skip_a_caller_supplied_id_still_in_flight went from [1, 2, 4] to [4, 5, 6]). Ids are opaque per spec, so I did not treat this as a breaking change needing a migration entry; happy to add one if you see it differently. Tests New test_minted_ids_never_reuse_a_completed_supplied_id, parametrized over both dispatchers and both id spellings (2, "2"). Fails on current main with wire ids [2, 1, 2]; passes with the fix ([2, 3, 4]). Updated the pinned sequence in test_minted_ids_skip_a_caller_supplied_id_still_in_flight. CallOptions.request_id docstring extended with the new guarantee. Ran locally: ./scripts/test # 5448 passed, coverage 100.00%, strict-no-cover clean uv run --frozen ruff format . && uv run --frozen ruff check . uv run --frozen pyright # 0 errors AI disclosure, per CONTRIBUTING: Claude Code helped me find this and sanity-check the invariant reasoning; I wrote up the repro, ran everything locally, and I can defend each line here in my own words. First PR to this repo and I'm a freshman still learning the ropes, so if the counter-advance approach clashes with something I haven't seen, please say so and I'll rework it.

Open Graph Description: Summary Fixes #3126. When a caller supplies its own request id via CallOptions["request_id"], the dispatcher's minted-id sequence could later land on that same id once the supplied re...

X Description: Summary Fixes #3126. When a caller supplies its own request id via CallOptions["request_id"], the dispatcher's minted-id sequence could later land on that same id once the...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3127

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8044798d-ee1d-db49-9ab8-da1851219edc
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8CF0:3C6F7B:627EBCB:84003F2:6A5DF82B
html-safe-nonce2dcb2e39a4af44f73aad23d1b9472ef0ff7c50b928a1472cec538bc76e0d144b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0YwOjNDNkY3Qjo2MjdFQkNCOjg0MDAzRjI6NkE1REY4MkIiLCJ2aXNpdG9yX2lkIjoiNzIzMzk3MTk0MTkzODE2NTgwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac041efb39e05a47e88bf933a85859ce8e24ed9adfbb2e278872b57d24c7e81dc8
hovercard-subject-tagpull_request:4082098681
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/3127/files
twitter:imagehttps://avatars.githubusercontent.com/u/231403453?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/231403453?s=400&v=4
og:image:altSummary Fixes #3126. When a caller supplies its own request id via CallOptions["request_id"], the dispatcher's minted-id sequence could later land on that same id once the supplied re...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7f8603048a7a8270fc5b845c28ec71e80a9a899268387bcf65814ee1b51c0cc4
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee2a5561aeb049d0632a92906af784af5d414c603
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3127%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3127%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 263 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 309 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
ayaangazalihttps://github.com/ayaangazali
modelcontextprotocol:mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
ayaangazali:fix/minted-request-id-reusehttps://github.com/ayaangazali/python-sdk/tree/fix/minted-request-id-reuse
Conversation 1 https://github.com/modelcontextprotocol/python-sdk/pull/3127
Commits 1 https://github.com/modelcontextprotocol/python-sdk/pull/3127/commits
Checks 29 https://github.com/modelcontextprotocol/python-sdk/pull/3127/checks
Files changed 4 https://github.com/modelcontextprotocol/python-sdk/pull/3127/files
fix: never mint a request id already used by a completed caller-supplied id https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#top
Show all changes 1 commit https://github.com/modelcontextprotocol/python-sdk/pull/3127/files
64bfa61 fix: never mint a request id already used by a completed caller-suppl… ayaangazali Jul 18, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3127/commits/64bfa6112dd5354339c10f19be245f735aa5fe56
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/3127/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files
direct_dispatcher.py https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-6566b073a8d9286a5b17e0bb02d6e12e822eaedf2236c0d637dcd57992268076
dispatcher.py https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-13274512d72e2a34a599019a9226619b150fca24130936cee3dc7d5122934673
jsonrpc_dispatcher.py https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
test_dispatcher.py https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-490cfcfdfdaf03f631a5cc632ec5a47dee6aa063d13518834a7a1f1bb8493f3f
src/mcp/shared/direct_dispatcher.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-6566b073a8d9286a5b17e0bb02d6e12e822eaedf2236c0d637dcd57992268076
View file https://github.com/modelcontextprotocol/python-sdk/blob/64bfa6112dd5354339c10f19be245f735aa5fe56/src/mcp/shared/direct_dispatcher.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3127/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-6566b073a8d9286a5b17e0bb02d6e12e822eaedf2236c0d637dcd57992268076
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-6566b073a8d9286a5b17e0bb02d6e12e822eaedf2236c0d637dcd57992268076
src/mcp/shared/dispatcher.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-13274512d72e2a34a599019a9226619b150fca24130936cee3dc7d5122934673
View file https://github.com/modelcontextprotocol/python-sdk/blob/64bfa6112dd5354339c10f19be245f735aa5fe56/src/mcp/shared/dispatcher.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3127/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-13274512d72e2a34a599019a9226619b150fca24130936cee3dc7d5122934673
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-13274512d72e2a34a599019a9226619b150fca24130936cee3dc7d5122934673
src/mcp/shared/jsonrpc_dispatcher.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
View file https://github.com/modelcontextprotocol/python-sdk/blob/64bfa6112dd5354339c10f19be245f735aa5fe56/src/mcp/shared/jsonrpc_dispatcher.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3127/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-3d8fb73fa8b126691302c15bb63bbc44a3a0e9338a17f14b3b4ea1d97bb10c2c
tests/shared/test_dispatcher.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-490cfcfdfdaf03f631a5cc632ec5a47dee6aa063d13518834a7a1f1bb8493f3f
View file https://github.com/modelcontextprotocol/python-sdk/blob/64bfa6112dd5354339c10f19be245f735aa5fe56/tests/shared/test_dispatcher.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3127/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-490cfcfdfdaf03f631a5cc632ec5a47dee6aa063d13518834a7a1f1bb8493f3f
https://github.com/modelcontextprotocol/python-sdk/pull/3127/files#diff-490cfcfdfdaf03f631a5cc632ec5a47dee6aa063d13518834a7a1f1bb8493f3f
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3127/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.