Title: OAuth token refresh hits the wrong endpoint when the auth server lives under a path · Issue #3240 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: OAuth token refresh hits the wrong endpoint when the auth server lives under a path · Issue #3240 · modelcontextprotocol/python-sdk
X Title: OAuth token refresh hits the wrong endpoint when the auth server lives under a path · Issue #3240 · modelcontextprotocol/python-sdk
Description: Ran into this with a hosted MCP server whose authorization server isn't at the origin root — token endpoint is https://host/oauth2/api/v1/token, not https://host/token. If a client starts up with a cached-but-expired access token (+ refr...
Open Graph Description: Ran into this with a hosted MCP server whose authorization server isn't at the origin root — token endpoint is https://host/oauth2/api/v1/token, not https://host/token. If a client starts up with a...
X Description: Ran into this with a hosted MCP server whose authorization server isn't at the origin root — token endpoint is https://host/oauth2/api/v1/token, not https://host/token. If a client starts up wi...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3240
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"OAuth token refresh hits the wrong endpoint when the auth server lives under a path","articleBody":"Ran into this with a hosted MCP server whose authorization server isn't at the origin root — token endpoint is `https://host/oauth2/api/v1/token`, not `https://host/token`.\n\nIf a client starts up with a cached-but-expired access token (+ refresh token) and hasn't done discovery yet, `async_auth_flow` refreshes at the very top — before any 401/metadata discovery. So `oauth_metadata is None` and `_refresh_token` uses the fallback `urljoin(get_authorization_base_url(server_url), \"/token\")`, i.e. just `{scheme}://{netloc}/token`. That 404s, `_handle_refresh_response` clears the tokens, and the flow drops to full interactive auth — which a headless/gateway client can't do. So the server silently disconnects every time the access token expires (mine are 5 min, so… constantly).\n\nSame path-stripping fallback is in `_get_token_endpoint`, `_perform_authorization_code_grant` (`/authorize`) and DCR (`/register`) — refresh is just the one that bites silently.\n\nRepro (roughly):\n- MCP server whose AS metadata puts `token_endpoint` under a path, not `{origin}/token`\n- log in normally so tokens get cached\n- let the access token expire (or clear the expiry), reconnect with a fresh provider\n- watch the refresh POST go to `https://host/token` → 404 → \"Token refresh failed\" → tokens cleared → it tries to open a browser\n\nFix looks like: discover metadata before the eager refresh (or stop dropping the issuer path in the fallback). Happy to PR — have a branch that pulls the PRM/ASM discovery out of the 401 branch and runs it before the refresh.\n\n(used some AI help digging into this)","author":{"url":"https://github.com/mfadul24","@type":"Person","name":"mfadul24"},"datePublished":"2026-08-03T12:55:14Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3240"}
| 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:9ce57f7a-35d2-1dbc-f245-5aa5057f9a79 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E0C4:269AD9:1229920:184C351:6B0120A9 |
| html-safe-nonce | f211c36791c598db4235ad61958c8bd9fa53c4c908bb81d8faa250619c0c2507 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMEM0OjI2OUFEOToxMjI5OTIwOjE4NEMzNTE6NkIwMTIwQTkiLCJ2aXNpdG9yX2lkIjoiMzM4Mjk2MzY4MTQ4NTcyNTg2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 175daeafab04215c753fb17b009ee6dba265b7ae6255cd94da41352d679fce39 |
| hovercard-subject-tag | issue:5049999877 |
| 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/3240/issue_layout |
| twitter:image | https://opengraph.githubassets.com/859b1b6e2fcbe24e41cb4e204167652f65ae1811c73916b8a40b985b1787e64b/modelcontextprotocol/python-sdk/issues/3240 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/859b1b6e2fcbe24e41cb4e204167652f65ae1811c73916b8a40b985b1787e64b/modelcontextprotocol/python-sdk/issues/3240 |
| og:image:alt | Ran into this with a hosted MCP server whose authorization server isn't at the origin root — token endpoint is https://host/oauth2/api/v1/token, not https://host/token. If a client starts up with a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mfadul24 |
| 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