Skip to content

fix(client): surface OAuth token persistence failures#2121

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/auth-save-token-refresh-errors
Open

fix(client): surface OAuth token persistence failures#2121
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/auth-save-token-refresh-errors

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

Fixes #2034.

When OAuth refresh succeeds but provider.saveTokens() fails, auth() should surface that persistence failure. The authorization server may already have rotated the refresh token, so silently falling through to a new authorization flow can hide the only useful error and leave the client with stale credentials.

This keeps the existing fallback behavior for refresh request failures, but moves saveTokens() out of that catch block so store/I/O failures propagate normally.

To verify

  • pnpm --filter @modelcontextprotocol/client exec vitest run test/client/auth.test.ts -t "does not hide token persistence failures"
  • pnpm --filter @modelcontextprotocol/client exec vitest run test/client/auth.test.ts
  • pnpm --filter @modelcontextprotocol/client typecheck
  • pnpm --filter @modelcontextprotocol/client lint
  • git diff --check

The repository pre-push hook also ran workspace typecheck, build, and lint successfully.

@he-yufeng he-yufeng requested a review from a team as a code owner May 19, 2026 02:41
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: c35d16f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@2121

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/codemod@2121

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@2121

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@2121

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/fastify@2121

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@2121

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@2121

commit: c35d16f

@he-yufeng
Copy link
Copy Markdown
Author

The red CI job is the existing Cloudflare Workers/Miniflare flaky path ( est/server/cloudflareWorkers.test.ts: Network connection lost). The OAuth test, full client auth test file, typecheck, lint, and pre-push workspace checks pass locally. I don't have repository admin rights to rerun the failed job.

@he-yufeng he-yufeng force-pushed the fix/auth-save-token-refresh-errors branch from 34c5df5 to c35d16f Compare May 27, 2026 10:37
@he-yufeng
Copy link
Copy Markdown
Author

Rebased onto current main, added the client patch changeset, and force-pushed c35d16f. Local validation: changeset status shows @modelcontextprotocol/client patch; client auth.test.ts passed with 168 tests; client typecheck and lint passed; git diff --check passed. Pre-push typecheck, build, and lint also 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.

auth() silently swallows non-OAuthError exceptions from refreshAuthorization / saveTokens, preventing token persistence

1 participant