MCP Authentication and Authorization
In this article
- Trace how a client starts from a remote MCP server's URL, finds its authorization server and gets a token issued for that server.
- Check a token's audience, issuer and scope in server code, and say which check rejects a wrong token.
- Explain why a server never forwards the token it received, and describe the token it uses downstream instead.
- Apply least privilege to the scopes a client asks for and to the server's downstream token.
- Terms defined here: OAuth, authorization server, bearer token, protected resource metadata, OAuth scope, audience binding, token passthrough, token exchange.
Overview
The shop's orders server now runs at a public address, https://mcp.shop.example/orders. Anyone on the internet can send it a get_order request. A local server started by the app can read a key from its environment, and MCP says it should. [1] A remote one cannot: it has to learn, on every request, who the call is for and what they may do. The shop, its addresses and its customers are made up for this example.
Here is the whole picture. The client starts with nothing but the server's URL. The server tells it where customers sign in. The customer signs in there, and the client receives a token made for this one server. The server checks three things about every token it receives, in its own code. When it then calls the order API at https://api.shop.example, it never passes that token on; it uses a separate token made for the order API.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- Three parties and a token
- Finding where to sign in
- Audience binding
- Three checks in server code
- The call behind the call
- A request for someone else's order
- Least privilege
- Common mistakes
- Sources
- Check yourself, 13 questions