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

⚠️ No Changeset found

Latest commit: 34c5df5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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/client@2121

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 34c5df5

@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.

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