Remote MCP Server Auth Under the 2026-07-28 Spec

🔧 AI Tools 2026-11-25 10 min read

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

📖 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

#ClientServerWhat matters
1sends an MCP request with no tokenanswers 401 with WWW-Authenticatethe header must point at your protected resource metadata
2GETs /.well-known/oauth-protected-resourcereturns resource metadatalists which authorization server to use
3GETs the AS metadata documentauthorization serverendpoints, supported scopes, registration support
4obtains a client ID (three mechanisms)authorization servermetadata document, pre-registration, or dynamic registration
5runs the OAuth 2.1 code flow with PKCEauthorization serverthe resource parameter travels in both requests
6retries the MCP request with Authorization: Bearer ...validates token and audienceevery 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:

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:

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

StatusWhenWhat the client should do
401no token, invalid token, expired token, wrong audiencestart or restart authorization
403valid token, insufficient scopestep-up: request more scope
400malformed authorization requestfix 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

  1. 401 without WWW-Authenticate. Client cannot discover anything. Fix the header first.
  2. Metadata at the wrong path, or served behind a redirect that strips the .well-known prefix. Clients fetch the exact URL from the header.
  3. Canonical URI mismatch: https://mcp.example.com in metadata, https://mcp.example.com/ in the token audience. Compare normalized values.
  4. Token in the query string. Breaks the spec and leaks into logs.
  5. Only checking the signature. Signature says "issued by someone"; audience says "issued for me".
  6. Returning 401 for scope problems instead of 403 plus insufficient_scope, causing an authorization loop.
  7. 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

Related Articles
2026-08-22
Best AI Proposal Generator for Consultants in 2026: 6 Tools That Win Projects While You Sleep
2026-11-07
Legal AI Tools 2026: 39% of the Clauses That Matter Sit in the Back Half
2026-08-03
AI Math Solver 2026: Texify (1.1k Stars) + LLMs - The Free Stack That Beats Paid Homework Apps
2026-08-20
Best AI E-Learning Platform in Cairo 2026: 6 Tools for Arabic EdTech and Exam Prep
2026-08-20
Best AI Contract Review Tool in Tallinn 2026: 6 Tools for Estonia's Digital Economy
2026-08-19
Best AI Video Generator in 2026: Runway vs Pika vs Kling Compared for Short-Form Creators

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.

💬 Comments (0)

No comments yet. Be the first!

Login to comment