← cartapi.io blog

MCP server authentication: OAuth vs API key vs no auth

Published 2026-12-03 · Last updated 2026-12-03 · 8 min read · agent commerce protocol
TL;DR

A remote MCP server that off-the-shelf clients connect to should use OAuth 2.1 as the MCP authorization specification describes: the server is a resource server, publishes Protected Resource Metadata, and accepts only tokens issued for it. API keys suit local stdio servers and clients you build yourself. A public, read-only server can skip authentication entirely.

Most comparisons of MCP authentication pick a winner. The specification is less absolute: it makes authorization optional and only describes how to do it over HTTP. This guide works from the 2026-07-28 authorization specification, checked on 2026-12-03, and uses cartapi's own open MCP server as a worked example of the third option.

Does an MCP server need authentication?

Not always. The MCP authorization specification says authorization is optional for MCP implementations. When a server does support it, implementations using an HTTP-based transport should follow the specification, and implementations using the stdio transport should not, retrieving credentials from the environment instead.

That leaves three real choices for an MCP server: OAuth 2.1 as the specification defines it, a static API key, or no authentication. Which one fits depends on two questions. Who runs the client, and what can a caller do with your tools?

OAuth vs API key vs no auth: how do they compare?

OAuth is the only option that a general-purpose client can discover and complete on its own. API keys are simpler but need the user to paste a secret. No authentication is the simplest and only safe when the tools expose nothing private. This table compares the three for MCP servers:

OAuth 2.1 (MCP spec)API keyNo auth
Best fitRemote servers used by any clientstdio servers, your own clientsPublic, read-only tools
How the client gets inDiscovers the authorization server, user signs inUser pastes a key into configConnects directly
Works in off-the-shelf clients without setupYes, if the client supports MCP authOnly if the client lets users add headersYes
Knows which user is callingYes, per tokenPer key, if you issue one per userNo
Scopes and expiryBuilt in (scopes, token lifetime, refresh)You build themNot applicable
Rate limitingPer tokenPer keyPer IP address
Work to buildHighest: authorization server, metadata, token checksLowNone

The "works in off-the-shelf clients" row decides most cases. If you want people to add your server to Claude, ChatGPT or Cursor by URL alone and reach private data, OAuth is the route the specification gives clients to follow.

Why does MCP use OAuth instead of API keys?

Because a general-purpose client has to connect to servers it has never seen, and OAuth gives it a standard way to find out how. In a post on the Agentic AI Foundation blog (2026-11-20), Nate Barbettini makes two arguments: asking non-developers to find and paste an API key is a poor experience, and clients can't write custom code for thousands of servers.

He also argues that once you add provisioning, expiry, scoping, renewal, client identification and consent to API keys, you have rebuilt OAuth. The same post lists where other schemes are fine: unprotected servers, custom clients that talk only to your own server, and local stdio servers.

How does OAuth work for a remote MCP server?

The MCP server acts as an OAuth 2.1 resource server, a separate or co-hosted authorization server issues tokens, and the client discovers both through metadata. Following the flow in the 2026-07-28 specification, these are the steps:

  1. The client calls the server without a token. The server answers HTTP 401 with a WWW-Authenticate header that includes a resource_metadata URL and, ideally, the scope needed.
  2. The client fetches Protected Resource Metadata (RFC 9728), which names the authorization server. The specification says MCP servers must implement this document.
  3. The client reads the authorization server's metadata through OAuth 2.0 Authorization Server Metadata (RFC 8414) or OpenID Connect Discovery. Clients must support both.
  4. The client gets a client ID through a Client ID Metadata Document, a pre-registered ID, or Dynamic Client Registration, which the 2026-07-28 revision marks deprecated.
  5. The user signs in and approves. The client uses PKCE and sends a resource parameter (RFC 8707) naming the MCP server's canonical URI, in both the authorization and token requests.
  6. The client checks the issuer in the authorization response against the one it recorded (RFC 9207) before exchanging the code.
  7. The client sends the access token as Authorization: Bearer <token> on every HTTP request. The specification forbids putting it in the query string.

On the server side, the main duty is token validation. The MCP server must check that each token was issued for it as the audience, return 401 for invalid or expired tokens, and return 403 with error="insufficient_scope" when a valid token lacks a needed scope.

When is an API key enough for an MCP server?

An API key is enough when the person who configures the client is also the person who owns the key. That covers two common cases.

The first is a local stdio server. The specification tells stdio servers to take credentials from the environment, so a key in an environment variable, set in the client's MCP configuration, is the expected pattern. The second is a custom client: an internal agent or backend job that only calls your server can agree on a key, or on OAuth client credentials, in advance.

If you use keys, treat them like passwords. Send them in a header, not the URL. Issue one per user or per integration so you can revoke one without breaking the rest, and log which key made each call.

Can an MCP server run with no authentication?

Yes, if every tool is safe for anyone to call. A server that only searches public data, and never returns private information or spends money on its own, gains little from a login and loses the users who won't set one up.

cartapi's MCP server is an example. Its llms.txt says the MCP endpoint is currently open, with authentication planned, while the REST API takes a Bearer API key. When we called https://mcp.cartapi.io/mcp on 2026-12-03 without credentials, initialize succeeded, and the server has no /.well-known/oauth-protected-resource document. Its source applies a rate limit of 120 requests a minute, keyed on the Authorization header when one is sent and on the IP address otherwise.

What makes this workable is where the money moves. The search tools return public catalog data. The checkout tools return a Stripe-hosted payment page that the human opens and pays, so calling them commits no one. For off-session purchases, the checkout tool accepts an envelope_token: a consent envelope the human set up in advance, with per-purchase and total limits, allowed categories and countries, and an expiry date. Authorization for spending travels with the purchase, not the connection.

That design has a cost, in our view. An envelope token is a bearer credential, so anyone holding it can spend within its limits until it expires or is revoked. Keep it as secret as an API key. Our guides to AI agent spending limits and consent-first checkout cover how to size those limits.

What are the most common MCP authentication mistakes?

Most mistakes come from treating the MCP server as a thin proxy for someone else's tokens. These are the rules in the 2026-07-28 specification that are easiest to miss, in our reading:

Which authentication should a commerce MCP server use?

For a server that sells things, separate two questions: who may connect, and who may spend. Connection can be open if the read tools are public. Spending should always need a human decision, whether that is a payment page the human opens, a URL elicitation request, or a pre-approved limit.

If your tools read order history, saved addresses or anything tied to one person, add OAuth so each call carries a user identity. Whatever you choose, mark which tools spend money with tool annotations and make purchase tools safe to retry with idempotency keys.

Frequently asked questions

Does a local stdio MCP server need OAuth?

No. The MCP authorization specification says implementations using the stdio transport should not follow the OAuth flow and should retrieve credentials from the environment instead. A local server usually reads an API key from an environment variable that the user sets in their client's configuration, because it runs on their own machine.

Can I put an API key in the MCP server URL?

Avoid it. The MCP specification forbids putting OAuth access tokens in the URI query string, and the same reasoning applies to API keys: URLs end up in logs, browser history and shared configuration files. Send the key in an HTTP header such as Authorization instead, and rotate any key that was ever shared in a URL.

What is OAuth Protected Resource Metadata in MCP?

It is a JSON document, defined in RFC 9728, that tells a client which authorization server protects an MCP server. The MCP specification says servers must implement it, and a 401 response points to it through the WWW-Authenticate header. The client reads it first, then discovers the authorization server's endpoints from there.

Is Dynamic Client Registration still required for MCP?

No. In the 2026-07-28 specification, Dynamic Client Registration is optional and marked deprecated, kept for authorization servers that don't support Client ID Metadata Documents. Clients and authorization servers should support Client ID Metadata Documents, where the client ID is an HTTPS URL. Pre-registered client IDs remain a third option.

Can an MCP server forward the user's token to an upstream API?

No. The MCP specification says servers must only accept tokens issued for their own resources and must not accept or transit any other tokens. If your server calls an upstream API, it should get its own credential for that API, such as a separate OAuth token or a server-side API key.

Try it

Connect cartapi from the install page to see an open commerce MCP server in your client, or read the docs for the REST API and its API keys. To add payments to your own server, see how to add Stripe Checkout to an MCP server.

About the author

Roc Chow

Roc Chow builds cartapi, the commerce layer for AI agents, and runs . The rules quoted here come from the MCP 2026-07-28 authorization specification and the Agentic AI Foundation post linked above, both checked on 2026-12-03. The details of cartapi's server come from its source code and a call to its public endpoint the same day.

LinkedIn · · cartapi.io