Skip to content

fix(mcp): invalidate stale credentials before re-authentication#29521

Open
lexlian wants to merge 1 commit into
anomalyco:devfrom
lexlian:fix/mcp-auth-clean
Open

fix(mcp): invalidate stale credentials before re-authentication#29521
lexlian wants to merge 1 commit into
anomalyco:devfrom
lexlian:fix/mcp-auth-clean

Conversation

@lexlian

@lexlian lexlian commented May 27, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #29227

Type of change

  • Bug fix

What does this PR do?

startAuth() was not clearing stored credentials before starting a new OAuth flow. When tokens existed in mcp-auth.json for a previous account, McpOAuthProvider.tokens() returned them and the SDK used them — the server rejected them and returned needs_auth. Since the tokens were never removed, the cycle repeated on every re-auth attempt.

The fix removes stored credentials at the start of startAuth() so the SDK triggers a fresh OAuth flow.

How did you verify your code works?

  • bun typecheck in packages/opencode — clean
  • bun test --grep mcp — all 12 tests pass

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

The search found one potentially related PR:

Related PR:

This PR addresses OAuth flow and authentication handling, which is related to your fix about invalidating stale credentials before re-authentication. It may be worth checking if it's already merged or if there's any overlap in the authentication logic being modified.

Before starting a new OAuth flow, remove any stored tokens so the MCP
SDK triggers a fresh authorization rather than reusing stale credentials
from a previous account or API key. This breaks the needs_auth loop
where stale tokens exist but belong to a different account.

Fixes anomalyco#29227
@lexlian lexlian force-pushed the fix/mcp-auth-clean branch from b687609 to de6e48e Compare June 1, 2026 05:24
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.

Unexpected status: needs_auth when trying to authenticate MCP after changing account (already authenticated)

1 participant