MCP Servers & Security

MCP Auth Explained: API Keys, OAuth, and Where Your Trust Boundary Really Is

12 November 2026 · Updated 28 November 2026 · 12 min read · by Yang Kai

How authentication works for MCP servers in plain terms: local stdio trust, API keys, the spec's OAuth 2.1 flow for remote servers, and which approach fits which scenario.

Table inside: MCP Auth-by-Scenario Table

Contents
  1. Local Servers over Stdio: The Trust Boundary Is Your Machine
  2. API Keys: Simple, Common, and Easy to Over-Scope
  3. OAuth for Remote Servers: The Flow the Spec Defines
  4. Three Spec Rules That Decide Real-World Safety
  5. Auth by Scenario
  6. The Questions to Ask of Any Server
  7. How We Researched This
  8. The Verdict

Ask how an MCP server authenticates and you will get answers that sound contradictory: “there is no auth”, “just use an API key”, “it needs OAuth”. All three can be true at once.

MCP covers two very different situations — a program running on your own machine, and a service running on someone else’s — and auth means something different in each. This explainer separates them, walks through the OAuth 2.1 flow the specification actually defines for remote servers, and ends with a table for choosing deliberately instead of copying a config you do not understand.

It is based on the MCP specification’s authorization chapter and the RFCs it builds on, checked in November 2026. It builds on the habits in the MCP security checklist: auth is one layer there; here it gets the full treatment.

The short version: local stdio servers have no login because your machine is the boundary — the spec says so outright. Remote servers use API keys when one trusted user is involved, and OAuth 2.1, with discovery documents and audience-bound tokens, when a server acts for many users.

Local Servers over Stdio: The Trust Boundary Is Your Machine

When a client launches a local server over stdio, there is usually no login step between client and server, and that is not an oversight. The server is a child process you configured, running as your user, on your machine. The trust decision happened earlier — when you installed it and wrote its config.

The specification says this plainly. Its authorization chapter covers HTTP transports, and states that implementations using stdio should not follow it and should instead retrieve credentials from the environment. You can read that in the spec’s authorization page.

So for local setups, installation is the authentication event. That is why vetting a server before installing it matters so much, and why the practical risks at this layer are not strangers logging in. They are:

What the local server does need is credentials for whatever it talks to on your behalf — a token for a notes service, a key for an API. Those belong in the env block of your client config or in an environment file outside any repository, scoped as narrowly as the service allows, and rotatable without editing code. A read-only token for a read-only job. A token for one project, not your whole account, when the service supports it.

API Keys: Simple, Common, and Easy to Over-Scope

For a remote server — one reachable over HTTP — the simplest auth is an API key or bearer token sent with each request. It is easy to implement and easy to use, which is why smaller and self-hosted setups reach for it first, including most of the hosting arrangements compared here.

The weaknesses are structural:

Mitigate with per-user or per-client keys where offered, short-lived tokens where the platform supports them, and a written note of everywhere a key lives, so revocation is a checklist rather than a treasure hunt.

Never put a key in a prompt. Anything in the conversation can be echoed, logged, or stored in transcripts. Keys travel in headers and environment variables, not in chat.

OAuth for Remote Servers: The Flow the Spec Defines

OAuth exists for the case API keys handle badly: a remote MCP server that acts on behalf of many different users, each with their own account at some underlying service. Instead of the server holding everyone’s keys, each user authorises it through the familiar consent flow, and any user can withdraw access without affecting anyone else.

The MCP specification makes the server an OAuth 2.1 resource server: it never issues tokens, it only validates them. A separate authorization server signs users in and issues tokens. The client — Claude Code, Cursor, your own agent — discovers both at runtime. Here is the flow, step by step:

  1. The challenge. The client calls the server without a usable token. The server replies 401 with a WWW-Authenticate header pointing to its protected resource metadata.
  2. Protected Resource Metadata (RFC 9728). The client fetches that document from a well-known URL. It names the authorization server (or servers) that protect this resource. No guessing, no hard-coded endpoints.
  3. Authorization Server Metadata (RFC 8414). The client fetches the authorization server’s own metadata document — its endpoints, its supported scopes, its registration route. Clients must support this discovery, and must check one field in particular: if the metadata does not advertise PKCE support, the client must refuse to proceed.
  4. Client registration. The client introduces itself. The current route is a Client ID Metadata Document: the client’s ID is simply a URL pointing to a JSON document describing it, which the authorization server fetches. The older route, Dynamic Client Registration (RFC 7591), still exists as a fallback — more on its status below.
  5. Consent with PKCE. The client opens the user’s browser at the authorization endpoint with a PKCE challenge (S256), the requested scopes, and a resource parameter naming the MCP server (RFC 8707). The user signs in and consents.
  6. Token and use. The client exchanges the returned code for an access token bound to that resource, then sends it as a bearer token on every request. The server validates each token — issuer, expiry, and audience — before running any tool.

Two properties in that flow do the heavy lifting. The token is audience-bound: it was issued for one specific MCP server, and the spec requires servers to reject tokens minted for a different resource. And authorization rides on every request, not on a session you opened once — under the current spec revision there is no long-lived session identity to lean on.

Three Spec Rules That Decide Real-World Safety

1. No token passthrough

An MCP server must not take the token a client presented to it and forward that token to a downstream API. This has been prohibited explicitly since the 2025-06-18 spec revision. If the server needs to call another service, it obtains its own credentials for that service through a separate flow. Passthrough is what turns one consent screen into silent access to everything behind the server — the confused-deputy problem — and it is why a well-behaved server asks for its own, narrower grant.

2. PKCE is not optional

Every authorization-code flow uses PKCE with the S256 method. There is no configuration in which a public client — a desktop app, a CLI — should run the flow without it, and, as step 3 above notes, a client must walk away from an authorization server whose metadata does not advertise it.

3. Registration moved from DCR to CIMD

If you implemented MCP auth in early 2025, check this one. Dynamic Client Registration was the original mechanism. The November 2025 revision made Client ID Metadata Documents the preferred route, and the current revision (2026-07-28) deprecates DCR, keeping it only so clients can still talk to older authorization servers. The same revision added issuer validation (RFC 9207): the client checks the iss value in the authorization response against the issuer it discovered, which blocks mix-up attacks where a response arrives from the wrong authorization server. Walkthroughs of the current revision, such as Tyk’s MCP OAuth guide and this step-by-step of the remote server flow, track these changes revision by revision.

One more honesty note: OAuth 2.1 itself is still an IETF draft, not a finished RFC. MCP pins a profile of it — the subset above — so implementations interoperate even while the underlying document settles.

What Your Client Stores After the Flow

The flow ends, but the artefacts persist, and they are part of your auth surface. After a successful run, your client typically holds three things: its registration or metadata-document identity for that authorization server, a refresh token if one was issued, and the access token it is currently using.

The current spec revision ties the first of those to the issuer. Stored client credentials are keyed to the authorization server that issued them, and if the server’s protected resource metadata later points at a different authorization server, the client must register again rather than reuse the old credentials. That rule exists because a swapped authorization server is exactly what a mix-up or phishing attack looks like from the client’s side.

For your own inventory, the practical consequence is simple: OAuth-connected servers leave traces in your client’s credential store as well as in your config file. When you remove a server, clear both. The five-minute revocation test in the FAQ below is the check that you actually did.

Auth by Scenario

Scenario Sensible approach Why Main risk to manage
Local stdio server, only you No client-server login; scoped tokens in env for upstream services You are the trust boundary; install-time vetting is the control Token leakage via configs, logs, screenshots
Self-hosted remote server, only you API key or token over HTTPS, per-client if possible Simple, adequate for a single trusted user Key spread; no expiry unless you rotate
Remote server shared by a small team Individual keys per person, or OAuth if the platform offers it You need to know who did what, and revoke one person cleanly Shared keys destroy attribution
Public or multi-tenant server OAuth 2.1 per the spec: scoped, revocable, audience-bound grants Per-user consent and revocation are the whole point Implementation complexity; consent phishing
Server calling a third-party API for you The narrowest token that service issues — read-only where possible, obtained by the server itself Token passthrough is prohibited; separate grants limit blast radius Over-scoped tokens granted “to make it work”
Browser-driven server with your sessions Separate browser profile, treated as its own boundary Session cookies are credentials in effect Reusing your daily profile — see the pattern in the Playwright MCP walkthrough

The Questions to Ask of Any Server

Whatever the scenario, four questions cut through marketing language:

That last question is the honest one. Auth design is blast-radius design. The companion piece on making sense of MCP vulnerability reports shows how often real incidents trace back to generous credentials meeting a server that accepted input it should not have.

How We Researched This

Desk research against primary sources, checked November 2026: the MCP specification’s authorization chapter (the roles, the discovery documents, the PKCE and resource-parameter requirements), the underlying RFCs it profiles — 8414, 8707, 9207, 7591, and 9728 — and two maintained explainers that track the spec revision by revision, linked above. The scenario table reflects the spec’s model applied to setups a solo builder actually runs. Nothing here comes from standing up a production authorization server and attacking it; where the spec leaves implementation freedom, this article says what the spec requires and flags the rest as your design choice. If you are wiring servers into a coding agent for the first time, the Claude Code and MCP setup guide shows where these auth decisions appear in a real client config, and running MCP in production covers the operational side for servers you host.

FAQ

Does MCP have built-in authentication? For HTTP transports, the specification defines an OAuth 2.1 profile: discovery documents, PKCE, audience-bound tokens. For local stdio servers there is typically no login at all — the spec directs them to take credentials from the environment, and the trust boundary is your machine. Most confusion comes from mixing those two worlds.

Where do MCP server tokens actually live? Usually in the client’s config (environment values in .mcp.json or your user settings), in the client’s own credential store after an OAuth flow, or in the host’s secret store for remote servers. The inventory exercise in this article exists because most builders cannot answer this for their own setup on the first try.

What is the risk of one shared token for everything? Revocation becomes all-or-nothing, and a leak anywhere exposes every service the token touches. One scoped token per server costs minutes to set up and turns a crisis into a single rotation.

How do I revoke access for one server quickly? Delete or rotate that server’s token at the issuing service, remove the server from your config, and restart the client. For OAuth grants, revoke the grant at the provider as well. If you cannot do all of that in five minutes, your auth setup — not the incident — is the problem to fix.

Do I need OAuth for a server only I will ever use? Almost certainly not. For a personal remote server, a per-client API key over HTTPS gives you revocation and attribution with a fraction of the moving parts. OAuth earns its complexity the moment a second user’s account is involved.

The Verdict

Match the mechanism to the scenario, not to the fashion. Local server: vet the install and guard the environment. Personal remote server: a scoped key you can rotate. Anything acting for other users: the spec’s OAuth flow, with audience-bound tokens and no passthrough. Inventory the servers you run today and fill in the table’s rows for your own setup — which scenario each server is, where its tokens live, and how you would revoke them. Any row you cannot fill in is your next fix, and the best MCP servers by job is the place to check how the well-maintained options handle it.

Category: MCP Servers & Security · Tags: #mcp #security #ai-api

Next step: this article is part of MCP guides, which covers the full topic from first setup to advanced use.

Related guides