Skip to content

Commit de6e48e

Browse files
committed
fix(mcp): invalidate stale credentials before re-authentication
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
1 parent 34b1045 commit de6e48e

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎packages/opencode/src/mcp/index.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ export const layer = Layer.effect(
785785
const url = remoteURL(mcpName, mcpConfig.url)
786786
if (!url) throw new Error(`Invalid MCP URL for "${mcpName}"`)
787787

788+
// Invalidate any stale credentials so the SDK triggers a fresh OAuth flow
789+
// instead of reusing tokens that may belong to a different account/API key.
790+
yield* auth.remove(mcpName)
791+
pendingOAuthTransports.delete(mcpName)
792+
788793
// OAuth config is optional - if not provided, we'll use auto-discovery
789794
const oauthConfig = typeof mcpConfig.oauth === "object" ? mcpConfig.oauth : undefined
790795

0 commit comments

Comments
 (0)