René's URL Explorer Experiment


Title: fix(client/auth): discover AS metadata before cold-start token refresh, with issuer-binding check by claude[bot] · Pull Request #3263 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: fix(client/auth): discover AS metadata before cold-start token refresh, with issuer-binding check by claude[bot] · Pull Request #3263 · modelcontextprotocol/python-sdk

X Title: fix(client/auth): discover AS metadata before cold-start token refresh, with issuer-binding check by claude[bot] · Pull Request #3263 · modelcontextprotocol/python-sdk

Description: Requested by Felix Weinberger · Slack thread NoteAI disclosure: this PR was authored by Claude (an AI agent operated by the MCP maintainer team's triage workflow, at Felix Weinberger's request — see attribution above). Fixes #3240. Together with #3248 (which restores token expiry on load), resolves #3250. Problem On a cold start — a client restarting with a stored refresh token, before any 401 has triggered discovery — the eager pre-401 refresh in OAuthClientProvider.async_auth_flow builds its token URL from the urljoin(origin, "/token") fallback because context.oauth_metadata has not been discovered yet. Against servers whose token endpoint lives under a path (e.g. https://auth.example.com/oauth2/api/v1/token), the refresh POSTs to the wrong URL, gets a 404, _handle_refresh_response clears the stored tokens, and the client falls back to a full interactive re-auth on every process restart — which headless/gateway clients cannot perform (#3240, #3250). Fix Run OAuth discovery before the cold-start refresh, driven through the same httpx auth flow (no side-channel client): PRM discovery (SEP-985 well-known fallbacks; there is no 401 yet, so no WWW-Authenticate resource_metadata hint). ASM discovery (RFC 8414 fallbacks, SEP-2468 issuer validation) → the real token endpoint. Refresh, now targeting the discovered token endpoint. Because this discovery is unanchored (blind well-known probes — a co-hosted origin can legitimately serve some other resource's documents), its results are treated as best-effort and never destructive or fatal, unlike the 401 path's hint-anchored, authoritative discovery: A resource-mismatched PRM or an issuer-mismatched ASM counts as a failed discovery (skip, try the next URL) instead of raising out of the auth flow. On a SEP-2352 issuer-binding mismatch — the gap that led the author of #3241 to close it after cubic's P1 review comment — the eager refresh is skipped, so stored credentials are never presented to an unvalidated authorization server; the unanchored discovery results (including rejected ASM metadata) are discarded, and the credentials themselves are left for the anchored 401 path to judge — that path re-discovers with the server's hint and drops/re-registers only on a confirmed AS change. Servers publishing no metadata at all keep the exact previous behavior (refresh against {origin}/token), and the probes run only once per context (eager_discovery_attempted, recorded only when the probe sequence completes so an interrupted discovery is retried), so repeat in-process refreshes make no extra requests. When metadata is already known (normal in-process refresh), nothing changes — no extra requests. The inner refresh generator is driven under contextlib.aclosing, so it is finalized deterministically when httpx closes the auth flow mid-refresh. This follows the structure of #3241 (closed by its author) and addresses the issuer-binding concern it was missing, with strictly conservative semantics on the hint-less path. Tests Ten new anyio tests in tests/client/test_auth.py: cold-start refresh targets the discovered (pathful) token endpoint, then retries the original request with the refreshed bearer; legacy server with no metadata anywhere keeps the {origin}/token fallback, and a failed refresh still clears tokens; the discovery probes run only once per context — a second expiry refresh goes straight to the fallback; an interrupted probe sequence is not recorded as completed and is retried on the next refresh; a foreign (resource-mismatched) PRM from a blind probe is skipped as failed discovery; an issuer-mismatched ASM (SEP-2468) is skipped as failed discovery instead of failing the request; a non-4XX ASM discovery error stops the fallback chain (mirrors the 401 path); issuer-binding mismatch after PRM discovery skips the refresh while keeping credentials/tokens for the 401 path (cubic's P1 scenario, non-destructively); issuer-binding mismatch on the legacy no-PRM path discards the rejected ASM metadata (mirroring the 401 path's defensive clear); metadata already known → immediate refresh, no discovery requests. ruff format/ruff check clean, pyright strict 0 errors, full local test suite passes with 100% branch coverage on the changed files (tests/interaction/auth/test_lifecycle.py continues to cover the metadata-already-known refresh and failed-refresh paths).

Open Graph Description: Requested by Felix Weinberger · Slack thread NoteAI disclosure: this PR was authored by Claude (an AI agent operated by the MCP maintainer team's triage workflow, at Felix Weinberger's requ...

X Description: Requested by Felix Weinberger · Slack thread NoteAI disclosure: this PR was authored by Claude (an AI agent operated by the MCP maintainer team's triage workflow, at Felix Weinberger&#3...

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

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:a56007a8-066f-a851-2c55-2af2d695dee9
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE7F0:842EC:15BC5E0:1D01A7C:6B013963
html-safe-noncec6d67d714917b3bd3526533c3c68f4cb579b0aa8940496a8aab23193208fa636
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0YwOjg0MkVDOjE1QkM1RTA6MUQwMUE3Qzo2QjAxMzk2MyIsInZpc2l0b3JfaWQiOiIxODgxNDkxNzQ1Njk2MTM2NjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac012798b387c9af278f454ad3f55aa2e816b44c3346ada5ee5a74fcbb13d213a8
hovercard-subject-tagpull_request:4225906040
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/3263/files
twitter:imagehttps://avatars.githubusercontent.com/in/1236702?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/in/1236702?s=400&v=4
og:image:altRequested by Felix Weinberger · Slack thread NoteAI disclosure: this PR was authored by Claude (an AI agent operated by the MCP maintainer team's triage workflow, at Felix Weinberger's requ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3263%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F3263%2Ffiles
Sign uphttps://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/3263/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues315 (315)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
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
claudehttps://github.com/apps/claude
mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
fix/oauth-discovery-before-eager-refreshhttps://github.com/modelcontextprotocol/python-sdk/tree/fix/oauth-discovery-before-eager-refresh
Conversation 14 https://github.com/modelcontextprotocol/python-sdk/pull/3263
Commits 3 https://github.com/modelcontextprotocol/python-sdk/pull/3263/commits
Checks 35 https://github.com/modelcontextprotocol/python-sdk/pull/3263/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/3263/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
fix(client/auth): discover AS metadata before cold-start token refresh, with issuer-binding check https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#top
Show all changes 3 commits https://github.com/modelcontextprotocol/python-sdk/pull/3263/files
a80aae2 fix(client/auth): discover AS metadata before cold-start token refresh claude Aug 7, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3263/commits/a80aae2bb1e9ea7a78d64ed03058da499c7182e8
7e70eae fix(client/auth): make hint-less eager discovery best-effort, never d… claude Aug 7, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3263/commits/7e70eaec564464d5a1a4af4297358fe77e46f8fa
137de1f fix(client/auth): non-fatal SEP-2468 check on eager path; flag discov… claude Aug 7, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/3263/commits/137de1f9fe719289256046f9ecf2d64950a0ca5a
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/3263/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
oauth2.py https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
test_auth.py https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-f083d075f463e8b1ecfa6b931c33288c3d09b00ee3af3e5f74df16b7e75c3ab1
src/mcp/client/auth/oauth2.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
View file https://github.com/modelcontextprotocol/python-sdk/blob/137de1f9fe719289256046f9ecf2d64950a0ca5a/src/mcp/client/auth/oauth2.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/3263/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
https://github.com/modelcontextprotocol/python-sdk/pull/3263/files#diff-b7aaf2062da175cea9a532176d6eb78b659eaadb757cc48929f0bafccfdb8d98
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/3263/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.