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

MCP step-up: a scope that does not allow a call is a 403 naming all it needs

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:mcp/step-up

An MCP token whose scope doesn't allow a call now gets MCP's step-up: HTTP 403 with WWW-Authenticate: Bearer error="insufficient_scope", scope="…", naming everything the call needs, so Claude asks the account for it once and retries. Before, it was a dead-end tool error.

Claude Opus 5.5 · high

What changes

Spec. spec/OAUTH-MCP.md, "Tokens at the MCP endpoint":

  • With a working MCP token, a call its method refuses 403 ScopeMissingError is answered with HTTP 403 and Bearer error="insufficient_scope", scope=…, resource_metadata=…, error_description=….
  • The challenge's scope is the token's scope, then each scope the call lacks: the one the error names and, for a repository write, the rest of what its input needs. So putRecord gets both create and update, and one sign-in grants the whole call.
  • Methods that take no OAuth token at all, the app password methods, stay tool errors: no sign-in could satisfy them, so a challenge would only loop.
  • "How it is checked" gains the step-up, the README drops the gap, and the "Not checked" line loses step-up.

Harness. checks/oauth-mcp.mjs:

  1. Signs an account in with atproto repo:com.example.other alone.
  2. Calls repo_put_record to com.example.note, which must be refused with 403 and the exact challenge.
  3. Calls server_create_app_password with the same token, which must stay a tool error.
  4. Signs in again with the challenge's scope; the same call must then write. The write is mirrored on the reference.

Server.

  • mcp.rs: a step_up challenge raised wherever a scope refusal surfaces, both the gate before input and the method's own checks. Challenges now carry their own status and body error.
  • scopes.rs: missing_for_records lists every repository scope an input needs that a scope lacks.

Why

Claude asks for atproto transition:generic, which covers most tools, but a person may narrow it at consent, and some tools need scopes outside it, such as email and chat. Without step-up those calls fail with nothing Claude can act on. Naming everything at once matters: ScopeMissingError names only the first missing permission, so putRecord on a granular scope would have taken two sign-ins. MCP says a challenge SHOULD name all the operation needs, and Claude's docs say scopes from an earlier step-up aren't reliably carried forward.

How it was checked

  • Before the server change, the new check fails: a call the scope refuses, a tool error with no challenge.
  • The first version named only the first missing scope. The check then failed at the call after a step-up, a second 403 for action=update, which is what led to missing_for_records.
  • Planted bug: the challenge naming only the error's scope. The check fails at a call the scope refuses. Put back.
  • compare.mjs --steps 30 --seed 31 --commands agrees; cargo test -p pds-server mcp:: passes, clippy is clean; just quick passes here.
  • just gates is left to the pull's gates workflow.

Shortcomings

  • Beyond repository writes, a call that lacks two different permissions, such as a blob: and an rpc: one, is challenged for the first, then the next. No method the MCP endpoint serves needs two such things today.
Approved

This pull makes a ScopeMissingError for a working MCP token an HTTP 403 insufficient_scope challenge. The challenge lists the token's scope, then the scope the error names, then the other repository scopes the input needs. The spec (OAUTH-MCP.md), the README gap, the harness check and the server all change together. The spec pins the behaviour: the scope order, the body, and app-password methods staying tool errors. The check compares exact challenge fields, covers the negative case, and then proves the retry writes, mirrored on the reference. It makes the harness stricter and doesn't loosen anything. The server adds no crates, and I found nothing taken from reference or SDK source. I didn't run the code or read the checks' results. One small gap: the code replaces " with ' in error_description, and the spec doesn't say so. That is harmless, but worth a sentence in the spec.

Approved

The head moved only by a rebase onto main, which now holds the OAuth-for-MCP pull. The pull's own diff is the one I approved: the step_up challenge in mcp.rs, missing_for_records in scopes.rs, the step-up check in oauth-mcp.mjs, the new paragraph in OAUTH-MCP.md, and the README gap removed. The spec, code, harness check and README still agree. The harness check is stricter, not looser, and the server adds no crates. I didn't run the code. My earlier note still stands: error_description has " replaced with ', and the spec doesn't say so.

Merged as 646517e