Authorization is technically optional in the Model Context Protocol’s 2026-07-28 specification — but the moment a self-hosted MCP server accepts connections over HTTP instead of stdio, the spec expects it to behave like a real OAuth 2.1 resource server, not a service protected by a single shared API key. That means publishing a metadata document, validating who a token was issued for, and rejecting anything that wasn’t.
Optional, Until You Pick HTTP
The specification is explicit that authorization is optional for MCP implementations generally, but it splits sharply by transport. Implementations using an HTTP-based transport SHOULD conform to the authorization specification. Implementations using STDIO transport SHOULD NOT follow it at all, and should instead retrieve credentials from the environment — the kind of local API key or token a desktop MCP client already reads before granting a server any permission scope. Implementations on other transports must simply follow established security practice for that protocol.
So the first decision that matters isn’t which auth flow to build — it’s which transport the server actually needs. A server that only ever runs as a local subprocess has no business implementing OAuth at all. A server that gets taken off localhost and exposed to a network inherits the full resource-server role the moment it does.
The One MUST Most Self-Hosted Servers Skip
Once a server goes the HTTP route, the specification’s overview section lists several MUST-level requirements, and one of them is easy to overlook because it isn’t about tokens at all: MCP servers MUST implement OAuth 2.0 Protected Resource Metadata, defined in RFC 9728. MCP clients, in turn, MUST use that metadata for authorization server discovery rather than being told the authorization server’s address out of band.
In practice, this means a server that rejects an unauthenticated request can’t just return a bare 401 and a vague error string. The response has to point the client somewhere useful:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource", scope="files:read"
The spec adds a scope-selection detail worth building in from day one: servers SHOULD include a scope parameter in that header, following the principle of least privilege, so the client requests only what the specific operation needs instead of guessing at the server’s full permission set.
Step by Step: What the Metadata Endpoint Has to Answer
- Pick the server’s canonical URI. The spec requires the scheme and the host, forbids a trailing fragment, and recommends no trailing slash unless the slash is meaningful —
https://mcp.example.com/mcpis valid,mcp.example.comand anything with a#fragmentare not. - Serve a Protected Resource Metadata document at the well-known path for that resource, naming at least one authorization server the client can use for discovery.
- Have that authorization server expose at least one of two discovery mechanisms: OAuth 2.0 Authorization Server Metadata (RFC 8414) or OpenID Connect Discovery 1.0. The client is required to support both, so the server only needs to pick one.
- Decide how clients will register. The spec’s selection priority runs Client ID Metadata Documents first, pre-registered clients second, and Dynamic Client Registration (RFC 7591) last — dynamic registration is explicitly called out as deprecated and kept only for backward compatibility.
- Implement the `resource` parameter on both the authorization and token requests. The client must send it, and it must identify the MCP server using that same canonical URI from step one — not a guess, not the authorization server’s URI.
Steps three and four are where most self-hosted implementations stall, because they assume they also have to run their own authorization server. The spec is clear that the authorization server’s implementation is out of its scope — it can be hosted with the resource server or be a completely separate identity provider. A self-hosted MCP server can point its Protected Resource Metadata at a third-party authorization server and skip building OAuth infrastructure from scratch entirely.
Validating the Token: Audience Binding, Not Just Signature
Checking that a bearer token is well-formed and signed by a trusted issuer is not the whole job. The specification requires that MCP servers MUST validate that access tokens were issued specifically for them as the intended audience, per RFC 8707. A token minted for a different resource server, even by the exact same authorization server, has to be refused — servers MUST NOT accept or transmit any token that wasn’t issued for their own resource. This is the specific defense against what the spec’s security considerations call a confused-deputy attack: a server that accepts any validly signed token, regardless of who it was meant for, can be tricked into acting as a proxy for requests it was never authorized to make.
Two more requirements are easy to get right in code review and easy to get wrong under deadline pressure: the access token has to travel in the Authorization: Bearer header on every request, and it MUST NOT appear in a URL query string, where it would end up in server logs and browser history.
Failure Modes the Spec Already Anticipated
| Mistake | What the spec requires instead |
|---|---|
| Returning a bare 401 with no discovery hint | 401 response must include a WWW-Authenticate header pointing to the Protected Resource Metadata URL |
| Accepting any token signed by a trusted issuer | Server MUST validate the token’s audience against its own canonical resource URI |
| Putting the access token in the request URL | Token MUST travel only in the Authorization header, never the query string |
| Challenging one missing scope at a time across several requests | Server SHOULD return every scope needed for the current operation in a single 403 challenge |
| Running OAuth logic inside a stdio server | STDIO implementations SHOULD NOT follow this spec; read credentials from the environment instead |
That fourth row covers a real usability failure the spec calls out by name: a server that challenges for one scope, gets a token, then immediately challenges for a second scope on the next call forces the user through multiple authorization round-trips for what should have been a single decision. The fix costs nothing extra on the server side — compute every scope the operation needs before returning the 403, not just the first one you check.
Three HTTP Status Codes, Three Different Meanings
The spec assigns a specific meaning to each error status a server can return, and mixing them up is a common source of client-side bugs: a 401 means authorization is required or the token is invalid; a 403 means the token is valid but doesn’t carry enough scope for the operation; a 400 means the authorization request itself was malformed, before a token even entered the picture. A client that treats every 4xx as “go re-authenticate from scratch” will loop through a full OAuth flow for what should have been a quick scope upgrade.
That scope upgrade has a name in the spec: the step-up authorization flow. When a client already holds a token but hits a 403 for a specific operation, it’s expected to compute the union of the scopes it already had and the scopes named in the new challenge, then request a fresh token covering both — not just the new scope on its own. A server that forgets this and silently drops previously granted permissions every time it issues a narrower challenge will keep breaking clients that did nothing wrong.
Refresh Tokens: A Request, Not a Guarantee
Clients that want a refresh token have their own obligations: keep it confidential in storage and in transit, and include refresh_token in the client’s registered grant types. A client MAY add offline_access to its requested scope when the authorization server advertises it, but it MUST NOT assume a refresh token will actually be issued — the authorization server keeps full discretion over that. On the server side of the resource — the MCP server itself, not the authorization server — the spec is equally direct: it SHOULD NOT list offline_access in its own WWW-Authenticate scope or in its Protected Resource Metadata’s scopes_supported, because refresh tokens are a concern between the client and the authorization server, not something the resource server needs to request on anyone’s behalf.
Where This Leaves a Server You’re Publishing Publicly
None of this is specific to one vendor’s SDK — it’s written at the level of HTTP headers and metadata documents precisely so that a server pushed from an internal tool to the public MCP Registry can be verified against the same checklist regardless of what language it’s written in. Before that publish step, the practical test is simple: send the server a request with no token and confirm the 401 carries a usable discovery URL; send it a token minted for a different resource and confirm it’s rejected rather than quietly honored. A server that passes both has done the part of this specification that actually protects users, independent of which identity provider sits behind it.
It’s also worth remembering that this entire checklist describes the resource-server half of the relationship. The other half — what a client should check before it ever connects to a server and grants it a scope — is a separate decision that doesn’t disappear just because the server implements every MUST in this specification correctly. Authorization metadata tells a client how to get a token; it says nothing about whether the server deserves the access that token would unlock.
Image: NOIRLab/NSF/AURA/T. Slovinský, CC BY 4.0.



