Repository navigation
Description
Which version line?
v2 — current (@modelcontextprotocol/inspector@latest)
Which client?
All / shared core
Inspector version
2.11.0
Node version
v24.12.0
Operating system (and browser, for the web client)
Linux (WSL2)
Transport
Streamable HTTP
MCP server under inspection
Remote OAuth-protected server behind AWS Bedrock AgentCore Gateway (CUSTOM_JWT authorizer), negotiated protocol version 2025-03-26
Steps to reproduce
Related: #2051 (closed, fixed in v2.4.0) fixed this exact failure shape — "checkAuthChallengeSatisfied() reports the challenge as already satisfied, so the caller reconnects with the same expired token" — for the token_expired branch, by adding isAccessTokenProvablyUnexpired(). That check was never mirrored into the insufficient_scope branch, which still has the identical gap today.
- Connect successfully to an OAuth-protected remote MCP server; let the access token expire naturally (scope unchanged).
- Reconnect. Server returns 403 with WWW-Authenticate: Bearer error="insufficient_scope", scope="..." where scope is fully covered by the stored token's own scp.
- Inspector's Network tab shows exactly two identical initialize POSTs, both 403, then "Failed to connect" — no token-endpoint request ever appears.
- Manually clearing cached OAuth state and reconnecting (fresh login) immediately works, since checkAuthChallengeSatisfied short-circuits to false once no stored tokens exist.
Expected behavior
insufficient_scope satisfaction should also verify the stored access token isn't expired before concluding "satisfied" — or at minimum, a same-token retry that gets the identical 403 again should fall back to attempting a refresh/interactive flow instead of giving up.
Actual behavior
Connection fails outright with no refresh attempt, forcing a full cache-clear and manual re-login.
Logs, errors, or screenshots
When a connect-time 403 challenge is classified as insufficient_scope, OAuthManager.checkAuthChallengeSatisfied() only checks whether the stored token's scope is already a superset of what's required — it never checks whether that stored token is actually still valid/unexpired (unlike the token_expired branch, which explicitly calls isAccessTokenProvablyUnexpired per the #2051 fix).
When a resource server returns 403 insufficient_scope for a token that's simply expired — not actually missing scope (this happens against at least one real world gateway we use fronting an IdP) — this check wrongly reports "satisfied," so handleAuthChallenge tells the transport to just retry with the same (still expired) token. The retry gets the identical 403, retryCount >= 1 trips in RemoteClientTransport.startWithRecovery, and the connection attempt fails outright — no refresh_token grant is ever attempted, and no interactive re-authorization is ever offered.
We confirmed the stored refresh_token was fully valid throughout (a direct refresh_token grant against the IdP succeeded outside of Inspector), so a silent refresh would have resolved the connection transparently had it been attempted.
Relevant code (reading from main, may have shifted):
- core/mcp/oauthManager.ts — checkAuthChallengeSatisfied()
- core/mcp/remote/remoteClientTransport.ts — startWithRecovery() / recoverFromAuthChallenge()
How we verified it: Decoded the JWT directly to confirm expiry, replayed the expired token against the gateway to reproduce deterministically, captured the exact HTTP exchange via Inspector's own Network tab, and confirmed the refresh_token itself was still valid via a direct grant against the IdP outside of Inspector.
Already prototyped a fix?
No response
Before you submit
- I searched existing issues and this is not a duplicate.
- This is not a security vulnerability report (those go through the private advisory process).
Activity
its-nott-me commentedon Oct 16, 2026
Hi, I'd like to take this. Reading
core/mcp/oauthmanager.tson main, theinsufficient_scopebranch ofcheckAuthChallengeSatisifed()only checks scope coverage, so an expired token whose scope is already covered returns "satisfied" andhandleAuthChallengefails before the filent-refresh path.My plan: gate the
insufficient_scopebranch onisAccessTokenProvablyUnexpired(tokens), mirroring #2051. One issue: the same method is called after a successful refresh/grant (standard, EMA, andtryForceReauthorizationForStepUp). A refreshed opaque token has no readableexp, so a plain guard would make those post-grant checks fail and force an unnecessary interactive re-auth. So i'd split out a private scope-only check for those internal call sites and keep the public method as "live token AND scope covered".Cost: opaque-token servers lose the free retry after a step-up and do one extra refresh, same tradeoff as #2051. I'd keep the broader same-token-retry fallback in
startWithRecovery()out of this PR. Does this approach work for you? Also happy to adjust if you'd rather avoid this split.danpatsey commentedon Oct 16, 2026
Hey, thanks for digging into this -- and for the precision. I pulled
oauthManager.tsmyself to check, and your read matches the code exactly:insufficient_scopefalls straight to!isStrictScopeSuperset(...)with no expiry check at all, whiletoken_expiredalready gates onisAccessTokenProvablyUnexpired(tokens)from #2051. Good catch tying it back to that precedent -- it's clearly the same gap, just never mirrored over.I also traced the three post-grant call sites you flagged (
handleStandardAuthChallenge, the EMA branch inhandleEnterpriseManagedAuthChallenge, andtryForceReauthorizationForStepUp) -- all three callcheckAuthChallengeSatisfied()right after a fresh mint/refresh, so a shared gate would indeed break opaque-token servers there. The public/private split sounds like the right shape: entry-point semantics stay "live token AND scope covered," post-grant call sites stay scope-only since liveness is already guaranteed by having just minted.The opaque-token tradeoff (one extra refresh, lose the free retry after step-up) is fine with me, especially given it's the same cost #2051 already accepted -- consistency there seems more valuable than optimizing around it. And yes, agreed on keeping the
startWithRecovery()same-token-retry fallback out of this PR -- smaller, reviewable scope.Appreciate you taking this on. Happy to test against our Bedrock AgentCore Gateway setup once you've got a PR up, since that's where we hit it originally.
its-nott-me commentedon Oct 16, 2026
Thanks for the detailed review and for confirming the approach!
i just noticed the repo's contribution guidelines specify a maintainer-led PR workflow for external contributions. I won't open a PR myself. I'll proceed with validating the proposed fix locally and share the exact prompt, before/after behavior, and verification results here in the issue, following the contribution guidelines.
I'll keep the scope focused on the
insufficient_scopeexpiry check and the scope-only checks after a fresh grant as we discussed.its-nott-me commentedon Oct 17, 2026
Following up locally. I'm not opening a PR or sharing a diff; this is the analysis, verification, and the prompt.
Root cause: in
core/mcp/oauthManager.ts, theinsufficient_scopebranch ofcheckAuthChallengeSatisfied()checks only scope coverage, while thetoken_expiredbranch (#2051) also requiresisAccessTokenProvablyUnexpired. An expired token whose scope is already covered returns "satisfied",handleAuthChallengereturns early, and the transport replays the same token, so no refresh is attempted.Behavior: before, expired JWT or opaque token + covered scope →
satisfied, nomcpAuthcall. After,false, sohandleAuthChallengeruns the silent-refresh path. A live JWT with covered scope keeps the cheap short-circuit.Shape of the change: the public method now requires a provably unexpired token and covered scope, with the scope logic extracted to a private
isStepUpScopeCovered. The three post-grant call sites (standard, EMA,tryForceReauthorizationForStepUp) use a scope-only wrapper, because a freshly minted opaque token has no readableexp, and a liveness check there would turn a successful refresh intofailed. The doc comment and theinsufficient_scopebullet inspecification/v2_auth_mid_session.mdare updated to match. The strategy table's "Silent: N/A" cell forinsufficient_scopeis now slightly stale and left for you to decide.Verification:
handleAuthChallengereachingmcpAuth, and a refresh-to-opaque-token resolvingsatisfied.oauthManager.test.ts: 127/127 pass. Coverage onoauthManager.ts: 99% statements, 98.16% branches, 100% functions, 98.98% lines.validate:core(format and lint forcore/) andtsc -binclients/webare clean.Environment note: I developed on native Windows, where
test:scriptsand 34 tests across five secret-storage and persistence files fail for platform reasons (POSIXchmod, symlink privileges,/proc/self/mountinfo). None of them importoauthManager. I re-ran all five files with my changes stashed and got identical failure counts (4, 7, 7, 13, 3). I haven't run the fulllocal:gateon Linux and can do that on request.Side effects to evaluate:
step_up_confirm. I haven't checked how the UI handles that.Out of scope: the same-token-retry fallback in
startWithRecovery().Prompt to reproduce: "In
core/mcp/oauthManager.ts,checkAuthChallengeSatisfiedreturns true forinsufficient_scopewhen scope is covered even if the stored token is expired or opaque. RequireisAccessTokenProvablyUnexpiredfor that branch. Extract the scope-coverage logic into a private method and use a scope-only wrapper at the three post-grant call sites (standard, EMA,tryForceReauthorizationForStepUp) so refreshed opaque tokens still resolve as satisfied. Add regression tests and update the existing tests that pin the old behavior. Update the doc comment and theinsufficient_scopebullet inspecification/v2_auth_mid_session.md."Happy to test against a rotating-refresh-token gateway if useful, or to re-run the gate on Linux.
cliffhall commentedon Oct 20, 2026
Triage: Priority Medium (total 7)
insufficient_scope. The workaround (clear OAuth state, then log in again) works but is annoying.token_expiredis answered from an unknowable local expiry #2051 fixed fortoken_expired, and the fix shape has already been worked out in the thread.bugBoard: #28, Status
Incoming, awaiting maintainer review (no milestone yet).cliffhall commentedon Oct 20, 2026
Fixed by #2738 (merged to
v2/mainas fd82b10), shipping in v2.12.0.Merge branch 'v2/main' into v2/fix/2726-per-flow-pkce-verifier
fix(oauth): refresh an expired token behind an insufficient_scope cha…