Skip to content

fix(client/auth): propagate saveTokens errors after refresh#2053

Open
SAY-5 wants to merge 1 commit into
modelcontextprotocol:mainfrom
SAY-5:fix/auth-swallow-savetokens-2034
Open

fix(client/auth): propagate saveTokens errors after refresh#2053
SAY-5 wants to merge 1 commit into
modelcontextprotocol:mainfrom
SAY-5:fix/auth-swallow-savetokens-2034

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 12, 2026

Closes #2034

The try { refreshAuthorization(...); saveTokens(...); } catch (error) block in auth() was wide enough to swallow saveTokens() failures (any non-OAuthError, plus ServerError). With rotating refresh tokens, that loses the freshly minted refresh token while the AS has already invalidated the old one, leaving the client unable to recover.

Split the block: the try/catch now wraps only refreshAuthorization, where fall-through to a fresh authorization flow is the intended recovery. saveTokens runs after the catch on a separate, unguarded path so its errors propagate to the caller.

Added a vitest regression test under OAuth Authorization > auth function that mocks saveTokens to reject, asserts the rejection bubbles to the auth() caller, and asserts redirectToAuthorization is never reached. The test fails on main and passes with this change. Full packages/client suite (365 tests) passes; pnpm lint clean.

@SAY-5 SAY-5 requested a review from a team as a code owner May 12, 2026 04:47
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2026

⚠️ No Changeset found

Latest commit: 676d040

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 12, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2053

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 676d040

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