Title: OAuth client can never recover from an expired DCR client secret — even though the SDK's own server issues and enforces one · Issue #3256 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: OAuth client can never recover from an expired DCR client secret — even though the SDK's own server issues and enforces one · Issue #3256 · modelcontextprotocol/python-sdk
X Title: OAuth client can never recover from an expired DCR client secret — even though the SDK's own server issues and enforces one · Issue #3256 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before openi...
Open Graph Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex...
X Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/mod...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3256
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"OAuth client can never recover from an expired DCR client secret — even though the SDK's own server issues and enforces one","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Release line\n\n2.x (current stable) — the code paths below were verified on `main` @ a4f4ccd09113 and are identical on `v1.29.0`; the production observation happened on 1.28.1 (provenance).\n\n### Description\n\n#### Summary\n\nThe SDK ships **both halves of a trap**, and they don't fit together.\n\n**As a server**, the SDK can issue expiring DCR client secrets and rejects them once lapsed:\n\n| step | code (`main` @ a4f4ccd09113) |\n|---|---|\n| knob | `ClientRegistrationOptions.client_secret_expiry_seconds: int \\| None = None` — `src/mcp/server/auth/settings.py:6` |\n| issuance | `client_secret_expires_at = client_id_issued_at + options.client_secret_expiry_seconds` — `src/mcp/server/auth/handlers/register.py:123-129` |\n| enforcement | `if client.client_secret_expires_at and ... \u003c int(time.time()): raise AuthenticationError(\"Client secret has expired\")` — `src/mcp/server/auth/middleware/client_auth.py:116-117` |\n| wire response | `AuthenticationError` → `{\"error\": \"invalid_client\", \"error_description\": \"Client secret has expired\"}` — `src/mcp/server/auth/handlers/token.py:106-113` |\n\n**As a client**, `OAuthClientProvider` persists `client_secret_expires_at` through its own `TokenStorage` abstraction and then never looks at it — and treats `invalid_client` as a plain fatal error:\n\n- Scanning every `.py` file under `src/mcp/client/` (23 files at a4f4ccd09113) finds **zero** occurrences of `client_secret_expires_at` and **zero** of `invalid_client`. Same for `v1.29.0`'s `oauth2.py`.\n- Registration only happens when stored client info is *absent* (`if not self.context.client_info:` in `async_auth_flow`, \"Step 4\"). Expired-but-present client info is reused forever.\n- `_handle_token_response` raises `OAuthTokenError` on any non-200; nothing invalidates the dead registration.\n\n**Consequence**: point an `OAuthClientProvider` at a server that enforces secret expiry — including a server built with this very SDK and `client_secret_expiry_seconds` set — and once the window passes, the client is **permanently stuck**:\n\n1. access token expires → refresh presents the expired `client_secret` → `invalid_client` → SDK falls back to full authorization\n2. full authorization succeeds (the user consents in the browser — the authorization leg is unaffected) → token exchange presents the same expired secret → `invalid_client` again\n3. the next attempt reloads the same client info from storage → registration skipped → back to 1\n\nUser-visible symptom: **\"I re-authenticated and nothing changed.\"** No amount of consent helps. Recovery requires the application to reach into the `TokenStorage` payload and delete the persisted client info by hand — nothing in the API surface hints that a storage payload can become permanently toxic.\n\nExpiring secrets and the absence of a rotation endpoint are both squarely within spec (RFC 7591 makes `client_secret_expires_at` REQUIRED whenever a secret is issued, with `0` meaning \"never expires\"; RFC 7592 is optional and this SDK's server doesn't implement it either — its routes are `/authorize`, `/register`, `/revoke`, `/token` and metadata only). In that world, **re-registration is the only standard recovery path, and the SDK client is the only party that can perform it** — the server can't push a new secret, user consent doesn't touch client authentication, and the application above the SDK doesn't manage `client_info` at all.\n\n#### Real-world occurrence\n\nfreee (a major Japanese accounting SaaS) runs an official remote MCP server at `https://mcp.freee.co.jp/mcp` whose DCR issues secrets that expire 30 days after issuance (observable from its public `/register` endpoint). Our production client (`mcp` 1.28.1) worked for exactly 30 days and then hard-failed exactly as above — with the same error string this SDK's server produces:\n\n```\nPOST /token (grant_type=refresh_token, expired client credentials)\n→ {\"error\":\"invalid_client\",\"error_description\":\"Client secret has expired\"}\n```\n\nClient authentication is checked before the grant, so *every* token-endpoint interaction dies once the secret lapses (the same registration with live credentials and a deliberately bogus grant returns `invalid_grant` instead — confirming the ordering).\n\n#### Expected behavior\n\nTwo small, complementary changes on the client side:\n\n1. **Treat stored client info with an expired secret as absent.** Before using persisted client info, check `client_secret_expires_at` (non-zero and in the past → discard, fall through to registration / CIMD). `main` already validates freshly returned registrations for usability via `check_registration_usable`; extending that notion to *stored* info seems natural.\n2. **Invalidate stored client info when the server answers `invalid_client`.** Per RFC 6749 §5.2 that means client authentication failed — for a dynamically registered client, the registration is dead by definition. Clearing it (and the tokens bound to it) lets the next flow re-register instead of failing identically forever. Note the HTTP status varies in practice (this SDK's server returns 401, the server we hit returns 400), so keying on the `error` field rather than the status code is the robust form.\n\n(1) fixes the stuck state proactively whenever the AS declares the expiry; (2) also covers servers that expire or revoke registrations without declaring it.\n\nWe currently implement both as an application-side wrapper around `TokenStorage` / the provider, which turned recovery from \"impossible\" into \"one re-consent\" in production.\n\n#### Verification notes\n\n- Code paths above were read at `main` a4f4ccd09113 (2.x) and `v1.29.0` (1.x); the \"zero readers\" claims come from scanning all 23 client files, not a spot check\n- The stuck loop and the `invalid_client` / `invalid_grant` ordering were observed against the third-party server named above\n- **Not verified by us**: an end-to-end SDK-server ↔ SDK-client reproduction (we did not stand up an SDK server with `client_secret_expiry_seconds` set). The claim there rests on the code paths in the table — setting the knob to a few seconds and letting an `OAuthClientProvider` outlive it should confirm it quickly\n\n### Example Code\n\n```python\n# Deterministic client-side reproduction (no 30-day wait): hand the provider a\n# storage that is already in the post-expiry state, then run any flow against a\n# server that enforces expiry (e.g. an SDK server with\n# ClientRegistrationOptions(client_secret_expiry_seconds=\u003csmall>)).\n\nimport time\n\nfrom mcp.client.auth import TokenStorage\nfrom mcp.shared.auth import OAuthClientInformationFull, OAuthToken\n\n\nclass ExpiredClientStorage(TokenStorage):\n \"\"\"Storage state after the AS-issued client secret lapsed.\"\"\"\n\n def __init__(self) -> None:\n self._client_info = OAuthClientInformationFull(\n client_id=\"registered-client-id\",\n client_secret=\"expired-secret\",\n client_secret_expires_at=int(time.time()) - 3600, # already expired\n redirect_uris=[\"http://localhost:3030/callback\"],\n token_endpoint_auth_method=\"client_secret_post\",\n )\n self._tokens: OAuthToken | None = None\n\n async def get_tokens(self) -> OAuthToken | None:\n return self._tokens\n\n async def set_tokens(self, tokens: OAuthToken) -> None:\n self._tokens = tokens\n\n async def get_client_info(self) -> OAuthClientInformationFull | None:\n return self._client_info\n\n async def set_client_info(self, info: OAuthClientInformationFull) -> None:\n self._client_info = info\n\n\n# Attach to OAuthClientProvider and connect:\n# - registration is skipped (Step 4 sees client info present),\n# - authorization succeeds, token exchange fails with invalid_client,\n# - every subsequent attempt repeats identically — there is no path back.\n```\n\n### Versions\n\n- Observed in production: `mcp` 1.28.1, Python 3.14, streamable HTTP transport\n- Code-inspected as still present: `v1.29.0` (latest 1.x) and `main` @ a4f4ccd09113 (2.x)\n\n✍️ Author: Claude Code with @carrotRakko (AI-written, human-approved)\n","author":{"url":"https://github.com/carrotRakko","@type":"Person","name":"carrotRakko"},"datePublished":"2026-08-05T10:54:09Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3256"}
| 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 | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b2e45c20-1006-81de-dd6d-8cbdc3c1a709 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8300:2C4BED:151B3CB:1ADB1EA:6B012E52 |
| html-safe-nonce | 1e75d08763cb511982df053be219ccda53dba164a87bc7d5f3e41085efa40b94 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzAwOjJDNEJFRDoxNTFCM0NCOjFBREIxRUE6NkIwMTJFNTIiLCJ2aXNpdG9yX2lkIjoiNDA4NzM0NTc4MjY4Mjg4OTgxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3d4f32b5d2029fa2775ab127ddbf7fa6110cbc50b70fd1bf0143ea29d5705aa6 |
| hovercard-subject-tag | issue:5070092066 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3256/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9659b44eac12049ed2f03ffa145d42ffabd93cc17aeb6722626204aa713ac080/modelcontextprotocol/python-sdk/issues/3256 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9659b44eac12049ed2f03ffa145d42ffabd93cc17aeb6722626204aa713ac080/modelcontextprotocol/python-sdk/issues/3256 |
| og:image:alt | Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | carrotRakko |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| 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 |
| react-app-name | issues |
Links:
Viewport: width=device-width