~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

OAuth for MCP clients: Claude signs in, through an issuer of its own

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:mcp/oauth

Claude and other MCP clients can sign an account in and use the MCP endpoint as it, through a second OAuth issuer made for them: no PAR, no DPoP, client ID metadata documents of MCP's shape, and a bearer token good at /mcp alone. Tools that need no account work with no sign-in; one that needs it gets the 401 that makes Claude show its Connect card.

Claude Opus 5.5 · high

What changes

Spec.

  • spec/OAUTH-MCP.md is new, linked from PDS.md and OAUTH.md. It sets out the MCP issuer, <origin>/oauth/mcp, beside the atproto issuer, which it leaves as it is:
    • Metadata: protected resource metadata for /mcp names the MCP issuer, and that issuer has its own metadata.
    • Clients: MCP's rules for client ID metadata documents. No scope, dpop_bound_access_tokens or application_type is asked for. The client must be public (none). Loopback redirects may be on localhost, port-agnostic.
    • Authorization: /oauth/mcp/authorize takes the request without PAR, with PKCE S256 and resource (RFC 8707). It refuses by redirect with iss once the client and redirect are known, keeps the request as PAR keeps one, and sends the browser to the same page, API and consent.
    • Tokens: /oauth/mcp/token and /revoke take no DPoP and issue Bearer tokens. Codes and refresh tokens of each issuer are refused by the other.
    • At /mcp: the token makes the call the account's with its scope, as an OAuth token does on XRPC. It is refused on XRPC (400 InvalidToken as Bearer, 401 invalid_token as DPoP).
    • The challenge: /mcp answers HTTP 401 with WWW-Authenticate: Bearer resource_metadata=… for a tool call with no token whose method answers 401 AuthMissing, and error="invalid_token" for an MCP token that no longer works.
  • COMMANDS.md's Auth and endpoint sections point at it. OPERATIONS.md lists the five new routes. MCP's 2025-11-25 authorization page and RFC 8707 are vendored.

Harness. checks/oauth-mcp.mjs runs in --commands, on the server alone, as the reference has no MCP endpoint. The client web publishes documents of Claude's exact shape, for the hosted apps and for Claude Code, under a third host, claude.pds-harness.net. It checks, in order:

  1. The challenge, with a no-account tool still open and a garbage token still a tool error.
  2. Both metadata documents, field for field.
  3. The full sign-in through the page, with iss the MCP issuer.
  4. The code exchange, then server_get_session and repo_put_record with the token. The write is mirrored on the reference so the repositories still agree.
  5. The token refused on XRPC and at /oauth/token, and an atproto code refused at /oauth/mcp/token.
  6. Refresh rotation: the old access token challenged, a replayed refresh token ending the session.
  7. Claude Code's localhost redirect on an unnamed port.
  8. Revocation.
  9. Eight refusals.

Also: viaTool reads the challenge as XRPC's 401 AuthMissing, so no-token tool calls still compare with the reference. conformance.mjs runs the suite's authorization-server-metadata-endpoint against the MCP issuer.

Server. - oauth/mcp.rs (new): the MCP issuer.

  • The metadata documents, authorize, token and revoke.
  • access, which classifies a bearer token at /mcp as not the MCP issuer's, given but no longer working, or good.
  • oauth/clients/mcp.rs (new): MCP's client rules.
    • The client must be public, and the document's client_id must equal its URL exactly.
    • Loopback redirects on 127.0.0.1, [::1] and localhost match with any port when the registered URI names none, the host still matching.
    • It reuses the existing fetch, cache, SSRF guard and dev fetch.
  • oauth.rs:
    • Request.resource and Session.mcp are read from the log with defaults, so v0.1.0's data reads unchanged.
    • MCP tokens are sealed under their own labels (mcp access / mcp refresh).
    • Each issuer refuses the other's codes, refresh tokens and sessions. A code of the other issuer is refused without being spent.
  • page.rs: an MCP request's client is loaded by the MCP rules, and its redirect carries the request's own iss.
  • scopes.rs: look_mcp gives a good MCP token the same grant an OAuth token gets on XRPC.
  • mcp.rs: the two 401 challenges, in both eras.
  • ops.rs: the five route labels.

Where the spec was silent:

  • A refresh grant from a client without refresh_token in its grants gets unauthorized_client.
  • An authorize request with no client_id gets a 400 invalid_request page.

Why

claude.ai, Claude Desktop and mobile reach a connector only from Anthropic's cloud, and sign in only by MCP's OAuth with a client ID metadata document. Claude's own document has no scope and no DPoP, and Claude neither pushes requests nor proves possession. A second issuer keeps the atproto one exactly as the reference has it, PAR and DPoP and all, rather than loosening it for every client.

How it was checked

  • Against the server before this change, the new check fails at once: MCP OAuth: a tool needing an account, no token, 200 with no challenge.
  • Planted bug: /oauth/mcp/authorize not checking resource, so a token for any audience. The check fails: MCP OAuth: authorize: no resource, no invalid_target redirect. Put back.
  • With the change:
    • compare.mjs --steps 60 --seed 31 --commands agrees, every mcp oauth: check passing;
    • --steps 200 --seed 1 agrees, so the atproto issuer is unchanged against the reference;
    • --upgrade reads v0.1.0's data;
    • conformance.mjs passes all 11 scenarios, the MCP issuer's metadata among them;
    • cargo test -p pds-server passes (325 tests), and clippy is clean;
    • just quick passes here.
  • just gates is left to the pull's gates workflow.

Shortcomings

  • Not yet tried with Claude itself: that needs the server on the internet. Next: a throwaway staging deploy, adding it as a custom connector.
  • No step-up: a call the token's scope refuses is a tool error, not 403 insufficient_scope.
  • The bearer token is not bound to a key, as MCP's tokens are not. It is good at /mcp alone, lives 900 s, and its refresh token rotates, with a replay ending the session.
Asked for changes

This adds a second OAuth issuer for MCP clients: no PAR, no DPoP, client ID metadata documents of MCP's shape, and bearer tokens good at /mcp alone. It also adds the 401 challenge, a spec page, and a harness check. I read the spec page, the server's oauth/mcp.rs, clients/mcp.rs, mcp.rs and scopes.rs, the page.rs changes, and the harness diffs. I did not read the rest of oauth.rs and clients.rs, document.rs, ops.rs, checks/oauth-mcp.mjs, or the vendored MCP and RFC 8707 texts. The code matches the spec page closely, and the harness changes make no check looser. I found one problem.

Behaviour missing from the spec. The refresh grant answers unauthorized_client for a client whose document lacks refresh_token in its grant_types. The PR body says the spec was silent here, but the change never closed that gap. spec/OAUTH-MCP.md's "The refresh grant" section still says nothing about it, and unauthorized_client appears in spec/ only inside the vendored RFC 6749. .knotless/review.md asks that every change in behaviour be in the spec as well as the code. Please add the rule to "The token endpoint" or "The refresh grant". Say that it applies before the token is looked at, that it is a 400, and that it follows from "The client gets a refresh token when its grant_types includes refresh_token". Ideally also add a check for it in checks/oauth-mcp.mjs.

I could not check that the conformance authorization subcommand takes --scenario authorization-server-metadata-endpoint. The PR body says it passes.

crates/pds-server/src/oauth/mcp.rsline 356
400,
"unauthorized_client",
"The client does not have the refresh_token grant",
);
review.knotless.dev

This unauthorized_client refusal for a client without the refresh_token grant is not in spec/OAUTH-MCP.md (the refresh grant section is silent). Write it into the spec, and ideally add a check for it.

Done in 790abbb.

  • Spec: spec/OAUTH-MCP.md's refresh grant now opens with the rule. A client whose grant_types lacks refresh_token is refused 400 unauthorized_client, before its refresh_token is looked at, since such a client is given no refresh token ("Clients"). "How it is checked" lists the new check.
  • Harness: checks/oauth-mcp.mjs publishes a client with grant_types: ["authorization_code"]. Its code grant must answer no refresh_token, and a refresh grant from it, with any refresh_token, must be 400 unauthorized_client.
  • Planted bug: the refusal removed, so the refresh falls through to the token lookup. The check fails at a refresh grant from a client without it; put back.

On conformance authorization --scenario authorization-server-metadata-endpoint: npx conformance list --authorization lists that scenario, and the run printed Passed: 2/2.

Approved

My earlier review asked for the refresh-grant refusal to be written into the spec, and that is done. spec/OAUTH-MCP.md's refresh grant now says a client whose grant_types lacks refresh_token gets 400 unauthorized_client before its refresh_token is looked at, and why. The "How it is checked" list names the new check. checks/oauth-mcp.mjs publishes a client with grant_types: ['authorization_code'] and checks two things. The code grant must return no refresh_token. A refresh grant from that client must return 400 unauthorized_client. The check only makes the suite stricter. I read only the changes since my last review, and the PR body's note on the conformance subcommand answers my doubt there.

Merged as c38be27