Remote MCP Server Auth Under the 2026-07-28 Spec
A local stdio MCP server works, but the same tools behind HTTPS die on the first request with a bare 401 and no hint about where to authorize.
📜 Table of Contents
- Who is who
- The handshake, in order
- Step 1: the 401 has to carry a pointer
- Step 2: the protected resource metadata document
- Step 3: where the client ID comes from
- Step 4: the resource parameter is not decoration
- Step 5: two details that break real deployments
- Step 6: error codes are part of the contract
- A minimal resource-server skeleton
- Seven ways this breaks in practice
- Checklist before you expose the endpoint
📖 Keep reading
A local stdio MCP server works on your laptop. You put the same tools behind an HTTPS endpoint, paste the URL into a client, and the connection dies at the first request with a 401 that contains no explanation. That is usually not a bug in your tools. It is the MCP authorization layer, which changed again in the current spec revision and which most quick-start templates skip entirely.
The spec revision in force right now is 2026-07-28 (modelcontextprotocol.io/specification/latest redirects there). Its authorization section is built on OAuth 2.1, specifically the IETF draft draft-ietf-oauth-v2-1-13, plus a specific list of building blocks: RFC 6750 (bearer tokens), RFC 8414 (authorization server metadata), RFC 7591 (dynamic client registration), RFC 8707 (resource indicators), RFC 9728 (protected resource metadata), RFC 9207 (issuer identification), the Client ID Metadata Documents draft, and OpenID Connect Discovery 1.0. If your mental model of remote MCP auth predates this list, the gaps below are why a client that works with one server hangs on another.
Who is who
The spec assigns roles plainly: the protected MCP server is an OAuth 2.1 resource server, the MCP client is an OAuth 2.1 client, and a separate authorization server handles the user interaction and issues tokens. Nothing requires the authorization server to be a different deployment; it can live on the same host. But the server's job is fixed: accept a bearer token, verify it was issued for this resource, and reject everything else.
The handshake, in order
| # | Client | Server | What matters |
|---|---|---|---|
| 1 | sends an MCP request with no token | answers 401 with WWW-Authenticate | the header must point at your protected resource metadata |
| 2 | GETs /.well-known/oauth-protected-resource | returns resource metadata | lists which authorization server to use |
| 3 | GETs the AS metadata document | authorization server | endpoints, supported scopes, registration support |
| 4 | obtains a client ID (three mechanisms) | authorization server | metadata document, pre-registration, or dynamic registration |
| 5 | runs the OAuth 2.1 code flow with PKCE | authorization server | the resource parameter travels in both requests |
| 6 | retries the MCP request with Authorization: Bearer ... | validates token and audience | every HTTP request, not just the first |
Step 1: the 401 has to carry a pointer
RFC 9728 says a resource server tells the client where its metadata lives by putting a resource_metadata parameter in the WWW-Authenticate header. The MCP spec's own example looks like this:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
scope="files:read"
A bare 401 Unauthorized with no header is the single most common cause of "this connector just spins". Clients are required to parse that header and follow it; a server that omits it has told the client nothing, and most clients give up rather than guessing a well-known path. The scope parameter is optional but the spec asks servers to send it, because it tells the client exactly which scopes the current call needs, instead of asking for everything up front.
Step 2: the protected resource metadata document
Served at /.well-known/oauth-protected-resource (path-suffixed variants exist for servers mounted under a path), the document is small:
{
"resource": "https://mcp.example.com",
"authorization_servers": ["https://auth.example.com"],
"scopes_supported": ["files:read", "files:write"],
"bearer_methods_supported": ["header"]
}
Two fields do the work. resource must be the canonical URI of the MCP server, because that string is what later has to match the token's audience. authorization_servers tells the client where to look next; the spec allows several, and the client picks one following RFC 9728 section 7.6. If your server sits behind a path like https://api.example.com/mcp, the canonical URI and the field value have to agree, or audience validation will fail later in a way that looks like a token bug.
Step 3: where the client ID comes from
This is the part that changed. The 2026-07-28 revision requires clients to obtain a client ID through one of three mechanisms, and refers to a selection priority defined in its Client Registration section rather than a single mandatory path:
- Client ID Metadata Documents (the
draft-ietf-oauth-client-id-metadata-document-00draft): the client ID is an HTTPS URL that returns a JSON document describing the client. No registration round trip, no per-client database row. - Pre-registration: you issue a client ID and secret out of band and the client is configured with it. Fine for a handful of known clients, painful for a public server.
- Dynamic Client Registration (RFC 7591): the client posts to your registration endpoint and gets credentials back automatically.
For a server you intend to expose to other people's MCP clients, DCR is still the most compatible floor, because it is the mechanism clients can complete without you in the loop. Client ID Metadata Documents reduce the trust problem (the client's identity is a document you can fetch and inspect), but support is newer. Check what your authorization server advertises before assuming either works with a given client.
Step 4: the resource parameter is not decoration
RFC 8707 exists because a token minted for one API should not be replayable against another that shares the same authorization server. The MCP spec makes this mandatory in both directions:
- The
resourceparameter MUST be included in the authorization request and in the token request. - It MUST identify the MCP server the client intends to use, using that server's canonical URI.
- The MCP server, acting as resource server, MUST validate that the access token was issued specifically for it as the intended audience.
Skip the audience check and you have built a token-confusion bug: any token from the same authorization server opens your server, including tokens issued for a different service. The check is a comparison between the token's audience claim and your canonical URI, not a signature check alone.
Step 5: two details that break real deployments
Issuer identification (RFC 9207). If the authorization server supports it, it includes an iss parameter in the authorization response and advertises authorization_response_iss_parameter_supported: true in its metadata. The spec asks clients to compare that value with the issuer they recorded from validated metadata before sending the authorization code to any token endpoint, and asks servers to include it. This closes a mix-up attack where a client is tricked into redeeming a code at the wrong server. If you run the authorization server, turn it on; if you only run the resource server, expect clients to require it.
Bearer placement. The token goes in the Authorization header on every HTTP request, even inside one logical session. The spec states plainly that access tokens must not be placed in the URI query string. That rules out the convenient ?token=... shortcut people add while debugging, which ends up in proxy logs and browser history.
Step 6: error codes are part of the contract
| Status | When | What the client should do |
|---|---|---|
| 401 | no token, invalid token, expired token, wrong audience | start or restart authorization |
| 403 | valid token, insufficient scope | step-up: request more scope |
| 400 | malformed authorization request | fix the request, do not retry blindly |
The 403 path is the one people forget. The spec describes a step-up flow: the server returns an insufficient-scope error with the scopes it needs, the client re-authorizes with those scopes added, and retries. A server that answers 401 for a scope problem sends the client into a re-authorization loop that never satisfies the requirement.
A minimal resource-server skeleton
The server side is smaller than it looks. Three pieces: the challenge, the metadata, and a token check that includes the audience.
import jwt
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
RESOURCE = "https://mcp.example.com"
AS = "https://auth.example.com"
PRM_URL = RESOURCE + "/.well-known/oauth-protected-resource"
app = FastAPI()
jwk_client = jwt.PyJWKClient(AS + "/.well-known/jwks.json")
def challenge(scope=None):
value = f'Bearer resource_metadata="{PRM_URL}"'
if scope:
value += f', scope="{scope}"'
return JSONResponse({"error": "unauthorized"}, status_code=401,
headers={"WWW-Authenticate": value})
@app.get("/.well-known/oauth-protected-resource")
def prm():
return {"resource": RESOURCE,
"authorization_servers": [AS],
"scopes_supported": ["files:read", "files:write"],
"bearer_methods_supported": ["header"]}
def token_scopes(request: Request):
auth = request.headers.get("authorization", "")
if not auth.lower().startswith("bearer "):
return None
try:
key = jwk_client.get_signing_key_from_jwt(auth[7:]).key
claims = jwt.decode(auth[7:], key, algorithms=["RS256"],
audience=RESOURCE) # the line that stops token confusion
return claims.get("scope", "").split()
except jwt.PyJWTError:
return None
@app.post("/mcp")
async def mcp(request: Request):
scopes = token_scopes(request)
if scopes is None:
return challenge("files:read")
if "files:read" not in scopes:
return JSONResponse({"error": "insufficient_scope"}, status_code=403,
headers={"WWW-Authenticate": f'Bearer error="insufficient_scope", scope="files:read", resource_metadata="{PRM_URL}"'})
return {"jsonrpc": "2.0", "id": 1, "result": {"tools": []}}
That is a sketch, not a production server: it does not cache keys, does not handle key rotation, and returns a fixed tools list. But every line corresponds to a MUST in the spec, and swapping the hardcoded values for your own gets you a server that a real MCP client can complete authorization against. The part worth staring at is audience=RESOURCE; without it the rest is theater.
Seven ways this breaks in practice
- 401 without
WWW-Authenticate. Client cannot discover anything. Fix the header first. - Metadata at the wrong path, or served behind a redirect that strips the
.well-knownprefix. Clients fetch the exact URL from the header. - Canonical URI mismatch:
https://mcp.example.comin metadata,https://mcp.example.com/in the token audience. Compare normalized values. - Token in the query string. Breaks the spec and leaks into logs.
- Only checking the signature. Signature says "issued by someone"; audience says "issued for me".
- Returning 401 for scope problems instead of 403 plus
insufficient_scope, causing an authorization loop. - Treating the MCP server as its own authorization server. It can be, but then it still has to publish the metadata documents; skipping them leaves clients with nothing to discover.
Related: if you are still deciding whether your tools should be exposed as MCP tools at all, the measured token cost of a tools list is worth reading before you expose twenty of them, and the anatomy of a SKILL.md covers the case where a skill file beats a tool call. Once the server is authenticated, the read-only Postgres server comparison covers the deployment side.
Checklist before you expose the endpoint
- 401 responses carry
WWW-Authenticate: Bearer resource_metadata="...", withscopewhen you know it. - PRM is served at the exact path, with
resourceequal to the canonical server URI. authorization_serverspoints at the authorization server that actually issues your tokens.- Token validation checks signature, expiry and audience.
- Scope failures return 403 with
insufficient_scope, not 401. - Tokens never appear in URLs.
- You have tested with two different clients; conformance differs.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.