Skip to content

fix(mcp): return 503 on auth-backend outages instead of invalid_token - #1591

Merged
graphite-app[bot] merged 1 commit into
mainfrom
security/mcp-transient-auth
Aug 24, 2026
Merged

fix(mcp): return 503 on auth-backend outages instead of invalid_token#1591
graphite-app[bot] merged 1 commit into
mainfrom
security/mcp-transient-auth

Conversation

@MaheshtheDev

@MaheshtheDev MaheshtheDev commented Aug 24, 2026

Copy link
Copy Markdown
Member

Cherry-picks #1587 from @Sravanjangam, plus the OAuth half on top.

When the auth backend is slow or returns a 5xx, the MCP server currently answers invalid_token. That is the protocol's signal to discard the credential and re-authenticate, so a brief upstream blip logs every connected client out, and sm_ API key users have no automatic way back. These requests now return 503 with Retry-After: 5 so clients retry instead.

His change covered the API key path only. This shares one transientAuthErrorFor helper between validateApiKey and validateOAuthToken, so a JWKS timeout or a 5xx also returns 503 on the OAuth path that Claude, Cursor and browser clients use.

Genuinely bad tokens are unaffected: bad signature, expired, and no-matching-key still resolve to 401. Verified across all seven cases.

Co-Authored-By: Sravanjangam 163002695+Sravanjangam@users.noreply.github.com

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
supermemory-app 6cae175 Commit Preview URL

Branch Preview URL
Aug 24 2026, 03:56 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 24, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supermemory-mcp 6cae175 Aug 24 2026, 03:55 PM

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add the label Main to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@MaheshtheDev MaheshtheDev changed the title fix(mcp): report transient session-endpoint failures as 503, not invalid token fix(mcp): return 503 on auth-backend outages instead of invalid_token Aug 24, 2026
@MaheshtheDev
MaheshtheDev marked this pull request as ready for review August 24, 2026 02:13
@claude

claude Bot commented Aug 24, 2026

Copy link
Copy Markdown

Claude finished @MaheshtheDev's task in 1m 30s —— View job


Reviewing PR #1591

  • Fetch PR diff and existing review comments
  • Read changed files and surrounding context
  • Analyze for bugs, security issues, and logic errors
  • Submit review findings

Overview: Returns 503 with Retry-After when auth backend is unavailable instead of invalid_token, preventing clients from discarding valid credentials during transient outages.

Issues found: None — this looks good to ship.

The implementation correctly distinguishes transient failures from invalid tokens:

  • Transient detection is comprehensive: transientAuthErrorFor now covers all the right cases:

    • HTTP 5xx/4xx (except 401/403) via status check
    • Network unreachable via TypeError
    • Timeouts via AbortError, TimeoutError, JWKSTimeout
    • JWKS fetch failures via ERR_JWKS_TIMEOUT, ERR_JOSE_GENERIC
  • Previous P1/P2 issues are resolved: The latest commit (cd2eb4e) added TypeError and jose error code handling, and Retry-After is now exposed in CORS config.

  • Type-safe control flow: The AuthResolution discriminated union makes the three outcomes (valid user, invalid token, transient failure) explicit and prevents mixing them up.

  • Tests cover the API key path: Both 500 responses and timeouts are tested. OAuth transient errors follow the same transientAuthErrorFor path so the logic is covered.

Score: 9/10

The only thing I'd note (not blocking): OAuth-path transient errors (e.g., JWKS timeout) aren't explicitly tested, but the implementation is shared so it would work identically. Could add a test for completeness in a follow-up.


@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview: Returns 503 with Retry-After when auth backend is unavailable instead of invalid_token, preventing clients from discarding valid credentials during transient outages.

Issues found: None — this looks good to ship.

The implementation is clean:

  • TransientAuthError properly distinguishes backend outages (5xx, timeouts, JWKS failures) from genuinely invalid tokens (401, 403, bad signatures, expired JWTs)
  • The resolveAuthUser discriminated union keeps the control flow explicit and type-safe
  • Tests cover the API key path for both 500 responses and timeouts

Score: 9/10

Minor note: OAuth transient errors (e.g., JWKS timeout) aren't explicitly tested, but the implementation logic is correct — JWKSTimeout is in TRANSIENT_ERROR_NAMES and would follow the same path.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c2bbb731d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/mcp/src/server/auth/index.ts
Comment thread apps/mcp/src/server/index.ts
MaheshtheDev added a commit that referenced this pull request Aug 24, 2026
jose reports a non-200 JWKS response as a plain JOSEError with no status, and an unreachable host rejects with TypeError, so neither matched the name set and both still collapsed to invalid_token. Also expose Retry-After through CORS so browser clients can read it.

Both raised in review on #1591.
@graphite-app

graphite-app Bot commented Aug 24, 2026

Copy link
Copy Markdown

Merge activity

…#1591)

Cherry-picks #1587 from @Sravanjangam, plus the OAuth half on top.

When the auth backend is slow or returns a 5xx, the MCP server currently answers `invalid_token`. That is the protocol's signal to discard the credential and re-authenticate, so a brief upstream blip logs every connected client out, and `sm_` API key users have no automatic way back. These requests now return 503 with `Retry-After: 5` so clients retry instead.

His change covered the API key path only. This shares one `transientAuthErrorFor` helper between `validateApiKey` and `validateOAuthToken`, so a JWKS timeout or a 5xx also returns 503 on the OAuth path that Claude, Cursor and browser clients use.

Genuinely bad tokens are unaffected: bad signature, expired, and no-matching-key still resolve to 401. Verified across all seven cases.

Co-Authored-By: Sravanjangam <163002695+Sravanjangam@users.noreply.github.com>
@graphite-app
graphite-app Bot force-pushed the security/mcp-transient-auth branch from a316f3a to 6cae175 Compare August 24, 2026 15:53
@graphite-app
graphite-app Bot merged commit 6cae175 into main Aug 24, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants