Turning Point Academy · MCP Engineering

OAuth for MCP — Solved exercises

MCP Engineering course · M3


Conceptual exercises to consolidate the OAuth 2.1 flow for remote MCP servers, as taught in lesson L13 (spec 2026-07-28). No code is needed: the goal is to understand why each step exists. Solve them on your own first; detailed solutions follow.

The map before you begin: 401 → Protected Resource Metadata (RFC 9728) → authorization-server metadata → client ID (pre-registered or CIMD) → /authorize with PKCE S256 and resource → /token with code_verifier and resource → Authorization: Bearer on every request. The server validates signature, issuer, audience, expiry and scope, and never passes the client's token through.

Exercise 1 — Order the flow

Number these seven moments 1 to 7:

Exercise 2 — The missing step

A developer describes their flow: "The client asks, receives a 401, and then retries the same request expecting to be let through the second time." What did they skip? Why will the retry fail?

Exercise 3 — Open discovery

/.well-known/oauth-protected-resource/mcp responds without credentials. A colleague says: "That's a security hole." Are they right? What does the endpoint hand out, and what not?

Exercise 4 — A valid token, rejected

Your server receives a correctly signed, unexpired token, and rejects it. Name two correct reasons, and say which HTTP status each one gets.

Exercise 5 — Local or remote?

For each case, should the server follow the MCP authorization spec? Justify in one line.

Exercise 6 — Translate the header

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.example.com/.well-known/oauth-protected-resource/mcp"

What should the client do next, and why did the server send a URL instead of just saying "no"?

Exercise 7 — The token from next door

Your MCP server is https://api.myapp.example/mcp. An attacker has a legitimate, valid JWT that another service's authorization flow issued for https://api.otherthing.example. They present it to your server. Which check stops this, and which parameter made the token carry that value?

Exercise 8 — Which parameter binds the token to this server?

The client sends one parameter in both the authorization request and the token request so that the issued token is bound to your MCP server. Name it and its RFC. What should the authorization server do if the value at /token differs from the one at /authorize?

Exercise 9 — Why PKCE?

A public client (no client secret) receives the authorization code on a redirect. What attack does PKCE prevent, and why must the client use S256 and not plain? What must the client do if the authorization server's metadata has no code_challenge_methods_supported?

Exercise 10 — May the server forward the token?

Your MCP server has a tool that calls GitHub on the user's behalf. The incoming request carries Authorization: Bearer <token>. May the tool forward that same header to GitHub? Why not, and what should it use instead?

Exercise 11 — Insufficient scope

A client with a notes:read token calls an endpoint that requires notes:write. What should the server return, and what can the client do next?

Exercise 12 — Who issues, who presents, who validates?

Complete: "The ______ issues the token; the ______ presents it on every request; the ______ validates it before responding." Then explain how a server can validate a JWT without calling the authorization server on every request, and what changes if the token is opaque.


Solutions

1 — Correct order. (1) First request without credentials. (2) 401 with resource_metadata. (3) Fetch the Protected Resource Metadata. (4) Read the authorization-server metadata and record the issuer. (5) /authorize with PKCE S256 and resource (then check state and iss on return). (6) /token with code_verifier and resource. (7) Call the server with the Bearer token. A client ID (pre-registered or CIMD) must be in hand before step 5.

2 — The missing step. Between the 401 and the retry the client must obtain a token: discovery (RFC 9728, then the authorization-server metadata), a client ID, user authorization with PKCE and resource, and the token exchange. A 401 means "you need credentials, here is where to start", not "try again". Repeating the empty request gets another 401.

3 — Open discovery. The colleague is wrong. MCP servers MUST publish this metadata, and it must be reachable without a token so a new client can bootstrap. It hands out only where to get a token (the resource URI and its authorization servers); it hands out no protected data and no tokens. Knowing which door to knock on does not let you in.

4 — A valid token, rejected. Any two of: wrong audience (issued for another resource) → 401; wrong issuer (not the authorization server you trust) → 401; insufficient scope for the action → 403 with error="insufficient_scope" (the client may step up). A good signature and expiry say "this token is real"; they do not say "this token is for me and for this".

5 — Local or remote.

6 — Translate the header. Fetch the Protected Resource Metadata at that URL, learn the authorization server, read its metadata, get a client ID, run PKCE with resource, get the token, and retry with Authorization: Bearer <token>. The 401 is designed to be actionable: it gives the client the map to obtain permission on its own.

7 — The token from next door. The audience check stops it: the token's aud is the other service, not https://api.myapp.example/mcp, so your server answers 401. The value came from the resource parameter (RFC 8707) the other client sent when it obtained the token. Without the audience check, any legitimate token from any service would work on yours. (In mcp 2.3.0, also set validate_token_resource=True; the default only warns.)

8 — Which parameter binds the token. resource, RFC 8707 (Resource Indicators). It MUST appear in both the authorization and the token request. If the values differ, the authorization server must refuse the exchange. (The lab's test authorization server adds exactly that check, TokenResourceCheck, because the mcp 2.3.0 /token handler does not pass resource to the provider.)

9 — Why PKCE? PKCE stops authorization-code interception: whoever steals the code cannot redeem it without the code_verifier that only the original client holds. S256 sends a hash of the verifier; plain sends the verifier itself, so an interceptor would learn it. If the authorization server does not advertise code_challenge_methods_supported, the client MUST refuse to continue.

10 — May the server forward the token? No. That is token passthrough, which the spec forbids: "MCP servers MUST NOT accept or transit any other tokens." The token was issued for your MCP server, not for GitHub. The tool uses a separate credential issued for GitHub (the server's own credential, or a token obtained for that API). In lab-l13, check A7 proves the upstream never saw the client's token.

11 — Insufficient scope. HTTP 403 with WWW-Authenticate: Bearer error="insufficient_scope" (ideally naming the needed scope). The client can run the authorization flow again asking for the extra scope (step-up), with the user's consent. A bare rejection with no hint leaves the client stuck.

12 — Who issues, who presents, who validates. The authorization server issues the token; the client presents it on every request; the MCP server validates it. A JWT carries its claims and a signature the server checks with the authorization server's public keys (JWKS), so no call is needed per request. An opaque token carries no readable claims: the server validates it by introspection at the authorization server. Tokens need not be JWTs.

To remember

  1. 401 → RFC 9728 → AS metadata → client ID → PKCE S256 + resource → token (resource again) → Bearer.
  2. resource (RFC 8707) binds the token to this server; the server checks the audience.
  3. Invalid token = 401; insufficient scope = 403 insufficient_scope with step-up.
  4. Never pass tokens through; use your own credential for upstream APIs.
  5. Authorization is optional in MCP; HTTP servers SHOULD follow it; stdio servers use the environment.

Turning Point Academy · MCP Engineering course · Module 3 · Lesson 13 (L13) · V2, spec 2026-07-28