Title: fix(client/auth): discard stored client registrations whose secret has expired by claude[bot] · Pull Request #3264 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(client/auth): discard stored client registrations whose secret has expired by claude[bot] · Pull Request #3264 · modelcontextprotocol/python-sdk
X Title: fix(client/auth): discard stored client registrations whose secret has expired by claude[bot] · Pull Request #3264 · 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 #3256. Problem OAuthClientProvider persists client_secret_expires_at (RFC 7591) through TokenStorage but never reads it back, and dynamic registration only happens when stored client info is absent. Once a dynamically registered secret lapses — e.g. against an AS issuing 30-day secrets, or an SDK server with ClientRegistrationOptions.client_secret_expiry_seconds set — every token-endpoint interaction fails with invalid_client, including the exchange after a fresh interactive authorization, so the client is permanently stuck ("I re-authenticated and nothing changed") until the application manually deletes the persisted client info. With no RFC 7592 rotation endpoint, re-registration is the only standard recovery path, and only the SDK client can perform it. Fix The minimal fix from the issue's "expected behavior" (1): a registration that authenticates with the minted secret (client_secret_post / client_secret_basic) and carries a non-zero, past client_secret_expires_at is treated as absent — in _initialize, when loading stored client info (restart case), and at the start of the 401 handler, re-checking the in-memory record (long-lived process whose secret lapses after load, so an interactive consent is never burned on an exchange doomed to fail invalid_client). The next 401 flow then re-registers (or resolves CIMD) and overwrites the dead record via the existing set_client_info call — no change to the TokenStorage contract (unlike draft #3260, which makes the setters accept None). Deliberate scoping: 0 means "never expires" and an absent field means no expiry was declared — both are kept (RFC 7591). Registrations with token_endpoint_auth_method "none"/absent never present the secret, so a lapsed secret does not invalidate them. Stored tokens are kept: a live access token continues to work without client authentication, and with no client info can_refresh_token() is false, so the refresh path that would present the lapsed secret is skipped. Pre-registered flows are unaffected: the client-credentials extension providers override _initialize and never load client info from storage. The issue's "expected behavior" (2) — reactively invalidating on an invalid_client token response for servers that expire registrations without declaring it — is intentionally left out: it needs a way to delete (not just overwrite) persisted state, i.e. a TokenStorage contract decision that deserves its own discussion. docs/client/oauth-clients.md is updated in the same PR: the TokenStorage tip and the CIMD section's "stored client_info still wins" statement now mention the expired-secret discard. Tests Three new tests in tests/client/test_auth.py: predicate unit test covering lapsed secret (post/basic), 0 = never expires, absent expiry, still-live expiry, and "none"-method registrations; flow regression test: a lapsed stored registration is treated as absent on load (stored access token still used), and after the 401 the flow issues a POST /register instead of reusing the dead record; mid-session lapse test: a registration that expires after _initialize already loaded it is discarded by the 401 handler, which then re-registers. ruff format/ruff check clean, pyright strict 0 errors, tests/client/test_auth.py + tests/client/auth + tests/interaction/auth pass with 100% branch coverage on src/mcp/client/auth/oauth2.py.
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...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3264
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6019dc7b-b385-5519-0753-494054e97fbc |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C9B4:EDA7A:16C3B70:1CECD42:6B01381F |
| html-safe-nonce | a0ee56ded0943c9aa5f37172b3fd7bab514634b4debb85a420d58f592956958d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUI0OkVEQTdBOjE2QzNCNzA6MUNFQ0Q0Mjo2QjAxMzgxRiIsInZpc2l0b3JfaWQiOiI2Nzc4NzE4MjI5MDUwMjQzMTAzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 20f4d8d3d29dbe6c7916914086b1f406124d1e35107894bcff8a427e88b1a88b |
| hovercard-subject-tag | pull_request:4225926400 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/modelcontextprotocol/python-sdk/pull/3264/files |
| twitter:image | https://avatars.githubusercontent.com/in/1236702?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1236702?s=400&v=4 |
| og:image:alt | 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... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width