Topic 3 of 5 · 5 min read
Scopes, audiences and least-privilege tokens
Goal: Design the scopes for a server's tools and decide whether a presented token must be accepted, refused or stepped up.
A token should carry only the scopes the current work needs, name your server as its audience, and expire soon; the server checks all three on every request. Scopes say what the holder may do. The audience says who may accept the token.
Check yourself · 1 of 3
A token is valid, signed by your authorization server, and was issued for the server with scope tickets:read. It is used to call delete_ticket. What should the server return?
Why it matters
An MCP server often fronts real actions: close a ticket, delete a file, send a payment. If one broad scope covers everything, a leaked token or a confused agent can do all of it. Per-tool scopes shrink the damage. Audience checks stop a token issued for another service from working on yours.
How to do it
- Group tools by risk and name scopes by capability. For a ticketing server:
tickets:readfor search and get,tickets:writefor create and update,tickets:deletefor removal. Do not use one scope calledadmin. - Ask for the least at first. Put the basic scope in
scopes_supportedand in thescopepart of the first 401 challenge. - Step up when needed. If a valid token lacks a scope for this call, return 403 with
WWW-Authenticate: Bearer error="insufficient_scope", scope="tickets:delete", resource_metadata="...". Put every scope the operation needs in one challenge. The client unions the new scopes with those it already holds, asks the user again, and retries a few times at most. - Check the audience. The token must have been issued for your server, which is the
resourcevalue the client sent. Reject anything else with 401. Never accept a token meant for another service, and never pass the client's token on to an upstream API. - Keep tokens short-lived. A leaked token then stops working soon. Do not ask for
offline_accessin your server's challenge; refresh tokens are not a resource requirement. - Honour hierarchies. If
tickets:writeis defined to includetickets:read, a write token may read.
Before and after
// weak: any valid token from our identity provider is enough
if (!verifySignature(token)) return unauthorized();
return runTool(name, args);
This accepts a token issued for a different application and ignores scope. The fixed check:
const claims = verify(token);
if (!claims.aud.includes("https://mcp.example.com")) return unauthorized(); // 401
if (!hasScope(claims.scope, REQUIRED[name])) return insufficientScope(REQUIRED[name]); // 403
return runTool(name, args);
What goes wrong
- One catch-all scope, so a read-only integration holds delete rights.
- Returning one missing scope per challenge, which sends the user through several consent screens.
- Forwarding the client's token to a downstream API, which makes your server a confused deputy.
Examples
Scope map for a tickets server
const REQUIRED: Record<string, string> = {
search_tickets: "tickets:read",
get_ticket: "tickets:read",
update_ticket: "tickets:write",
delete_ticket: "tickets:delete",
};
A client that starts with tickets:read can search all day. The first delete_ticket call returns 403 with scope="tickets:delete", and the user sees one consent prompt for that scope.
Decide: accept, refuse or step up
Three requests reach delete_ticket. A token issued for https://billing.example.com with scope tickets:delete: refuse with 401, wrong audience. A token for this server with only tickets:read: 403 step-up asking for tickets:delete. A token for this server with tickets:delete: accept.
Key points
- Design scopes around capabilities and risk, with separate scopes for read, write and delete.
- Invalid, expired or wrong-audience tokens get 401; a valid token without the needed scope gets 403 with insufficient_scope.
- A step-up challenge lists every scope the operation needs in one response, and the client unions them with scopes it already holds.
- Servers must check that a token was issued for them, using the resource indicator, and must not accept or pass through other tokens.
- Short-lived access tokens limit what a leak is worth.
Common mistakes
- Granting a single broad scope because per-tool scopes feel like extra work.
- Validating the signature but not the audience.
- Answering 401 for a valid token with too few scopes, which makes the client restart login instead of stepping up.
- Forwarding the client's access token to another API instead of getting a separate token for it.
Check yourself · 2 of 3
A token has the right scopes but its audience is a different company service. What must your MCP server do?
Check yourself · 3 of 3
A tool needs both files:read and files:write. The client holds neither. Which challenge is best?
Practice items, not counted towards your mastery.
Start here
- MCP authorization specification (opens in a new tab)DocsFree
The normative OAuth profile: discovery, registration priority, resource parameter, token handling and scope challenges.
- MCP transports specification (opens in a new tab)DocsFree
Streamable HTTP rules: one endpoint, required headers, Origin validation and the removal of sessions.
- Understanding authorization in MCP (tutorial) (opens in a new tab)DocsFree
A step-by-step explanation of the authorization flow for server and client builders.
More for this topic
- Resource Indicators for OAuth 2.0 (RFC 8707) (opens in a new tab)StandardFree
Defines the resource parameter that binds a token to the server that should accept it.