This lesson covers what an MCP server has to do as an OAuth 2.1 resource server: publish Protected Resource Metadata, answer 401 and 403 with the right WWW-Authenticate header, validate every token (especially its audience) and authorize each tool by scope. It ends with an illustrative TypeScript/Express skeleton and a checklist.
In this lesson
List the responsibilities of a protected MCP server as a resource server
Validate access tokens correctly, including the aud claim
Return 401 and 403 insufficient_scope responses that clients can act on
Review a server implementation against a short checklist
Use an existing authorization server
Responsibilities of the MCP server
Publish /.well-known/oauth-protected-resource (at the path-specific location and/or the root).
Answer 401 with WWW-Authenticate (resource_metadata and, optionally, scope).
Validate every token: signature, iss, aud, exp.
Authorize per tool: enough scope, or 403 insufficient_scope listing every scope the operation needs.
Never forward tokens: for upstream APIs, use tokens of its own (see lesson 5.3).
Never accept tokens in the URL; HTTPS always (see lesson 5.5).
Skeleton (TypeScript/Express, illustrative)
The numbered comments map to the responsibilities above.
The same metadata document is served at both well-known locations, so clients find it whether they derive the path-specific URL or fall back to the root.
The 403 lists all the scopes write_file needs (files:read files:write), not only the missing one, so the client can reauthorize in a single round trip.
Because MCP 2026-07-28 is stateless, this middleware runs on every request; there is no session to lean on.
Checklist
Does resource in your metadata match exactly the audience you configure in the authorization server?
Do you reject tokens without the correct aud, even when the signature is valid?
Does the 403 ask for all the scopes of the operation at once?
Do your logs never print full tokens?
Is validation cheap (cached JWKS keys)?
Summary
Use an existing authorization server; focus on being a good resource server.
Metadata, a 401 that points to it, complete validation (above all aud), a 403 with scopes, and no token passthrough.
Serve Protected Resource Metadata at both the path-specific URL and the root, and keep validation cheap because every request is validated on its own.
quiz · 3 questions
1. In the skeleton, which line implements "the MCP server rejects tokens that were not issued for it"?
The audience is the "for whom" of the token. The issuer option checks "who issued it", not who it was meant for.
2. A tool needs files:read and files:write; the token only has files:read. What should the 403 response ask for?
The server should request every scope the operation needs in one 403, so the client can reauthorize once and does not end up in a loop.
3. What is the first piece of advice for building a protected MCP server?
Mature authorization servers already implement PKCE, metadata and resource indicators; the MCP server's job is to be a correct resource server.