Expand description
The client-side decisions of the authorization flow that need no network.
Three rules from the authorization page, each a pure function so it can be tested without an authorization server: https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization#scope-selection-strategy
- Initial scope: use the
scopefrom theWWW-Authenticatechallenge; failing that, all ofscopes_supported; failing that, send none. - Step-up: re-authorize with the union of what was requested before and what the new challenge names, so earlier permissions are not lost.
- Retry limit: a few attempts, then a permanent failure.
offline_access is added only when the server lists it in its own
scopes_supported, and a resource must never advertise it.
Constants§
- MAX_
STEP_ UP_ ATTEMPTS - How many step-up authorizations are attempted for one operation before the failure is treated as permanent. “No more than a few times”.
- OFFLINE_
ACCESS - The
offline_accessscope, which asks for a refresh token.
Functions§
- initial_
scope - Picks the scope for the first authorization request.
- may_
step_ up - Whether another step-up may be attempted after
attemptshave been made. - step_
up_ scope - The scope for a step-up: everything requested before, plus the challenge.
- with_
offline_ access - Adds
offline_accesstoscopewhen the authorization server lists it.