Skip to content

V2: MCP OAuth login registers a new dynamic client every time #40767

Closed

Description

@justprosh

Description

On the V2 engine (opencode2, packages/core/src/mcp), logging in to a remote MCP server registers a brand-new dynamic OAuth client every time. Each login produces a different client_id and a full consent screen, and the authorization server accumulates one dead client registration per login.

MCPOAuth.authorize builds its store with memoryStore(), which starts empty, so the SDK finds no client information and goes to dynamic registration before it would ever reuse anything. The working registration is already stored — refreshes read it from the credential's metadata.client — the interactive path just never looks at it.

This is the V2 counterpart of #35625, which describes the same bug on the dev engine (packages/opencode/src/mcp, mcp-auth.json). The V2 code path is separate.

Plugins

None

OpenCode version

opencode2, next channel (built from v2)

Steps to reproduce

  1. Log in to an OAuth MCP server that supports dynamic client registration.
  2. Log in again.
  3. The second login registers another client instead of reusing the stored one — a different client_id in the authorization URL.

Screenshot and/or share link

n/a

Operating System

macOS 26 (not platform-specific)

Terminal

n/a

Activity

  1. rekram1-node commented on Sep 22, 2026

    @rekram1-node
    Collaborator

    Fixed on V2. McpOAuth.authorize now seeds its store from the client registration saved in the previous OAuth credential before handing the flow to the SDK, so a repeat login reuses the existing client_id instead of registering again (packages/core/src/mcp/oauth.ts, covered by "reuses the client registered by an earlier login" in packages/core/test/mcp-oauth.test.ts). The SDK still discards the stored client if the issuer changed, which is the intended fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions