Uh oh!
There was an error while loading. Please reload this page.
fix: use the auth provider's current token instead of a connect-time snapshot - #1434
fix: use the auth provider's current token instead of a connect-time snapshot#1434buptliuhs wants to merge 1 commit into
Conversation
…snapshot When relying on OAuth, useConnection read the access token from the provider once at connection setup and baked `Authorization: Bearer <token>` into `requestInit.headers`. The SDK transports already receive the same provider as their `authProvider` and add a fresh `Authorization` from it on every request, refreshing it on 401. But the SDK's `_commonHeaders()` spreads `requestInit.headers` after the provider token, so the connect-time snapshot always won. The effect: after the access token expires, the SDK refreshes successfully (token endpoint returns 200 and the provider stores the new token), but the retried request still carries the stale snapshot token, gets another 401, and the SDK's circuit breaker throws "Server returned 401 after successful authentication" — a 401 loop the session can't recover from. Stop snapshotting the OAuth token into requestInit and let the provider be the single source of truth. A user-supplied static Authorization header still flows through the custom-headers path and intentionally overrides the provider. Update the related test to assert the token is no longer baked in, and add direct SSE / Streamable HTTP tests covering it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
buptliuhs
commented
Jun 7, 2026
@cliffhall can you please review? thanks! |
Closing: v1 is deprecated. Thank you for this contribution, and apologies for the long wait for a response. v1 will receive security fixes only. We reviewed every open v1 PR for security impact before closing — see the backlog triage in #1819 — and a small number were retained for a final If the underlying problem still exists in v2, we'd genuinely like to know. Please open an issue describing it against v2. Note that we accept external contributions as issues rather than pull requests — maintainers handle design and implementation through a prompt-driven workflow. See Thanks again for taking the time to contribute to the Inspector. |
Summary
After a successful OAuth token refresh, direct (non-proxy) connections keep sending the old access token, so the session enters a 401 loop it can't recover from. Once the access token expires:
POST /mcpreturns 401, the SDK refreshes,POST /token(grant_type=refresh_token) returns 200, and the provider stores the new token.POST /mcpstill carries the oldAuthorization: Bearer …, gets another 401.This is rarely hit with a long token TTL, but a short TTL breaks the session at first expiry.
Type of Change
Changes Made
Root cause
When relying on OAuth,
useConnectionread the access token from the provider once at connection setup and bakedAuthorization: Bearer <token>intorequestInit.headers.The transports already receive that same provider as their
authProvider, so the SDK adds a freshAuthorizationfrom it on every request (and refreshes it on 401). But the SDK's_commonHeaders()spreadsrequestInit.headersafter the provider token:So the connect-time snapshot always shadows the provider's current token. The provider does store the refreshed token (
saveTokens/tokens()round-trip the samesessionStoragekey) — it just never gets used.Fix
Stop snapshotting the OAuth token into
requestInit. The provider is the single, always-current source of the token, and the SDK injects and refreshes it per request. A user-supplied staticAuthorizationheader still flows through the custom-headers path and intentionally overrides the provider.This affects connections that use the SDK's OAuth
authProviderand is independent of the malformed-Content-Typefix.Related Issues
Testing
Test Results and/or Instructions
requestInitand thatauthProvideris set.All
useConnectiontests pass; lint and prettier clean; client build compiles.Checklist
npm run prettier-fix)Breaking Changes
None. Non-breaking bug fix.
Additional Context