Authorizing Access to an MCP Server
A bearer token proves the client was issued credentials for this server, not that the server should trust everything the token's holder asks for, so the protocol makes the client prove the token, prove the audience, and prove the issuer, every single time. Explain why the MCP server plays the OAuth 2.1 resource server, the MCP client plays the OAuth client, and a separate authorization server issues tokens, and why stdio servers are told to skip this flow entirely. Trace Protected Resource Metadata discovery from a 401 response's WWW-Authenticate header through the well-known fallback order a client uses when the header is silent. Trace authorization server metadata discovery for a path-scoped issuer and a root issuer, and explain why the returned issuer value must match the one used to build the request. Generate a PKCE S256 code challenge from a code verifier with the standard library, and explain why a client must refuse to proceed when an authorization server does not advertise codechallengemethodssupported. Apply the resource parameter from RFC 8707 to bind a token request to one canonical server URI, and validate an incoming token's audience against that same URI. Apply the four-row iss validation table from RFC 9207 to defend against mix-up attacks, and tell 401, 403, and 400 apart on an MCP server's authorization responses. Most of what…
Authorizing Access to an MCP Server: A bearer token proves the client was issued credentials for this server, not that the server should trust everything the…
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.