Skip to content

MCP OAuth: stale DCR client registration is reused, authorization fails with "Invalid redirect URI" until credentials are deleted by hand #2606

Description

@xpzouying

Problem

The OAuth provider persists the DCR client registration (credentials/mcp/<key>-client.json) and reuses it for every subsequent authorization (clientInformation() in packages/agent-core/src/mcp/oauth/provider.ts). When the server side has meanwhile expired or dropped that registration (common for authorization servers that GC dynamic registrations), the next interactive flow builds its authorization URL from the stale client_id/redirect URI and the authorization server rejects it — in our case with "Invalid redirect URI" on the consent page.

Nothing in the client detects this: the flow just fails, and retrying reuses the same stale registration. The only recovery is knowing to delete credentials/mcp/<key>-client.json manually, which no error message suggests.

Suggested direction

When the authorization endpoint (or token exchange) rejects with a registration-related error (invalid_client, redirect-URI mismatch), invalidate the persisted client info (invalidateCredentials('client')) and re-run DCR once before surfacing the failure. Open to other designs — mainly filing this so the failure mode and its manual workaround are on record. Applies to both v1 (mcp/oauth/) and v2 (mcpCore/oauth/).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions