MCP OAuth explained: how remote MCP servers sign you in
How MCP OAuth works step by step: the 401, metadata discovery, client registration, PKCE and scopes, plus fixes when Claude or Cursor sign-in fails.
Bogdan Carbune
10 min read

MCP OAuth is how a remote MCP server signs you in without you pasting an API key. When you add a server's URL and click connect, your client sends a request, gets a 401back with a pointer to the server's metadata, finds out which authorization server to use, identifies itself to it, and opens your browser so you can log in and approve access. It then trades the result for an access token that only works at that one server, and sends that token with every request. All of this is the standard OAuth 2.1 authorization code flow with PKCE, plus a few discovery rules the MCP spec adds so a client can work with a server it has never seen before. This guide walks through each step with the spec's own examples, shows how Claude, Claude Code and Cursor handle it, and lists what to do when sign-in fails.
What is OAuth in MCP?
It is the authorization part of the MCP spec. The current authorization page(revision 2026-07-28, checked November 2026) says it "defines the authorization flow for HTTP-based transports" and that authorization is "OPTIONAL for MCP implementations." Some remote servers need no sign-in at all. The ones that do should follow this flow.
It only applies to remote servers. The same page says servers on stdio "SHOULD NOT follow this specification, and instead retrieve credentials from the environment." That is why a local server asks for a key in an env block and a remote one opens a browser window. The remote vs local guide covers that split in full.
Three parties take part, and the spec names each one:
- The MCP server is an OAuth 2.1 resource server. It holds the tools and checks the token on every request.
- The MCP client, such as Claude, Claude Code or Cursor, is the OAuth client acting for you.
- The authorization serveris what you actually log in to. The spec says it "may be hosted with the resource server or a separate entity", so it can be the vendor's own login or an identity provider they use.
What happens when you click connect?
The spec's flow diagram on the authorization page runs in this order. Everything except step 5 happens without you seeing it.
- The client tries without a token. The server answers
401 Unauthorizedwith aWWW-Authenticateheader that points to its protected resource metadata. - The client reads that metadata. It lists the authorization server (or servers) this MCP server trusts.
- The client reads the authorization server's metadata. That gives it the login and token endpoints, and tells it which registration methods and PKCE methods are supported.
- The client gets a client ID. It uses one it already has, points at a metadata document it hosts, or registers on the spot. More on this below.
- Your browser opens. You log in to the authorization server and approve access. The client has sent a PKCE challenge and a
resourceparameter naming the MCP server. - The browser is redirected back to the client with a one-time authorization code. The client checks the response came from the authorization server it expected.
- The client swaps the code for tokens, proving with the PKCE verifier that it started the flow. It gets an access token and often a refresh token.
- Every MCP request now carries the token in an
Authorization: Bearerheader, and the server checks it each time.
How does the client find the authorization server?
From the 401. The spec's example looks like this, with an optional scope telling the client what to ask for:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
scope="files:read"The discovery page(checked November 2026) says MCP servers "MUST implement" protected resource metadata (RFC 9728), and that the document "MUST include the authorization_serversfield containing at least one authorization server." Clients use the URL in the header when it is there. If it is not, they fall back to well-known paths, first at the MCP endpoint's path, then at the root. Then they look up the authorization server's own metadata, trying the OAuth path before the OpenID Connect one:
# 1. protected resource metadata, if the 401 did not say where it is
https://example.com/.well-known/oauth-protected-resource/public/mcp
https://example.com/.well-known/oauth-protected-resource
# 2. authorization server metadata, for an issuer like https://auth.example.com
https://auth.example.com/.well-known/oauth-authorization-server
https://auth.example.com/.well-known/openid-configurationOne safety check matters here. The same page says the issuerin the fetched document "MUST be identical to the issuer identifier used to construct the well-known URL", and if not, "the client MUST NOT use the metadata." A server cannot point you at someone else's login and pass it off as its own. You can watch step 1 on any protected server with curl:
# see the 401 and the resource_metadata pointer for yourself
$ curl -si -X POST https://mcp.usegoro.ai/mcp -H 'content-type: application/json' -d '{}' | grep -i www-authenticateHow does the client register itself?
OAuth servers only hand tokens to clients they know by ID, but your client and a new MCP server have usually never met. The client registration page (checked November 2026) gives three ways around that, and a priority order for clients that support all three: pre-registered details first, then a Client ID Metadata Document if the authorization server advertises client_id_metadata_document_supported, then Dynamic Client Registration if it has a registration_endpoint, and last, asking you to type the details in.
Registration routes
| How it works | Status in 2026-07-28 | |
|---|---|---|
| Client ID Metadata Document | The client ID is an https URL. The authorization server fetches the JSON there to learn the client's name and redirect URIs. | SHOULD support. The spec calls it the choice when client and server have no prior relationship (most common). |
| Pre-registration | You or the client vendor register an OAuth app ahead of time and supply its client ID (and secret, if any). | SHOULD support. For when client and server already have a relationship. |
| Dynamic Client Registration | The client POSTs to the server's registration endpoint and gets a client ID back on the spot. | MAY support. Deprecated, kept for backwards compatibility. |
The Dynamic Client Registration change is the one to know about. Older revisions leaned on it, and many live servers still use it. The current page says plainly that it "is deprecated. New implementations should use Client ID Metadata Documents instead", and that it "remains available for backwards compatibility with authorization servers that do not support Client ID Metadata Documents." If you use MCP servers, nothing changes for you: clients pick the route. If you build one, plan for metadata documents. Here is the spec's example document:
{
"client_id": "https://app.example.com/oauth/client-metadata.json",
"client_name": "Example MCP Client",
"client_uri": "https://app.example.com",
"logo_uri": "https://app.example.com/logo.png",
"redirect_uris": [
"http://127.0.0.1:3000/callback",
"http://localhost:3000/callback"
],
"grant_types": ["authorization_code"],
"response_types": ["code"],
"token_endpoint_auth_method": "none"
}What stops a token from being used somewhere else?
Three rules, all from the spec, and they are the reason MCP OAuth is safer than pasting a long-lived key.
- PKCE. The security considerations page(checked November 2026) says clients "MUST implement PKCE" and "MUST use the
S256code challenge method when technically capable." If the authorization server's metadata has nocode_challenge_methods_supported, clients "MUST refuse to proceed." A stolen authorization code is useless without the verifier only your client holds. - The token names its server. The authorization pagesays clients "MUST" send a
resourceparameter in both the authorization and token requests, set to the MCP server's canonical URI, and servers "MUST validate that access tokens were issued specifically for them as the intended audience." A token for one MCP server does not open another. - No passing tokens along.Servers "MUST NOT accept or transit any other tokens." If an MCP server calls an upstream API, the security page says it needs its own separate token for that API and "MUST NOT pass through the token it received from the MCP client."
Tokens travel only in a header, never in the URL. The spec says authorization "MUST be included in every HTTP request from client to server" and access tokens "MUST NOT be included in the URI query string":
GET /mcp HTTP/1.1
Host: mcp.example.com
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...What are scopes, and why does a server ask you to sign in again?
Scopes are the named permissions a token carries, such as files:read. The authorization page tells clients to request the scope from the first 401if there is one, otherwise everything in the server's scopes_supported, which it describes as "the minimal set of scopes necessary for basic functionality."
Extra permissions come later, on demand. If a tool needs more than your token allows, the server should answer 403 with insufficient_scope and name what it needs:
HTTP/1.1 403 Forbidden
WWW-Authenticate: Bearer error="insufficient_scope",
scope="files:write",
resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
error_description="File write permission required for this operation"The client then runs the sign-in again, asking for the union of what it had and what the server just named, so you do not lose earlier permissions. That is why a server can work for days and then ask you to approve something new the first time you use a write tool. The spec also says clients "MUST NOT assume refresh tokens will be issued", so some servers will send you back to the browser when a short-lived token runs out.
How do Claude, Claude Code and Cursor handle MCP OAuth?
All three run the flow for you. What differs is where you start it and how you supply your own OAuth app when a server needs one.
Claude (web and desktop). Anthropic's custom connector guide(checked November 2026) puts the choice in the add-connector dialog. Under Authentication the options are "Sign in now", "Sign in when needed" and "No sign in". Under OAuth client, which sets "how Claude identifies itself to the server's authorization server", the options are "Use Claude's published identity (Recommended)", "Register automatically" and "Use your own OAuth client". Pick the last one "only if the server's documentation says it requires a client you register yourself", and then register https://claude.ai/api/mcp/auth_callback as the redirect URL for that client. The full click path is in the Claude Desktop MCP guide.
Claude Code. Its MCP docs (checked November 2026) say you authenticate with /mcpand "follow the steps in your browser to log in", that tokens "are stored securely and refreshed automatically", and that Claude Code discovers servers that use a Client ID Metadata Document automatically.
# add a remote server, then sign in from inside a session
$ claude mcp add --transport http goro https://mcp.usegoro.ai/mcp
> /mcp
# or sign in straight from your shell
$ claude mcp login goro
# no browser on this machine (SSH, headless Linux)
$ claude mcp login goro --no-browser
# revoke at the server, then remove
$ claude mcp logout goro
$ claude mcp remove goroFor a server that needs a pre-registered app, the same docs pass your client ID as a flag. --client-secretprompts for the secret with masked input, and the docs say it is stored "in your system keychain (macOS) or a credentials file, not in your config."
$ claude mcp add --transport http \
--client-id your-client-id --client-secret --callback-port 8080 \
my-server https://mcp.example.com/mcpCursor. Its MCP docs (checked November 2026) say "Sign-in uses the authorization code flow with PKCE", that "with dynamic client registration, Cursor registers as a public client with no client secret", and that "Cursor renews an expired access token with the refresh token the server issued." For servers that need your own app, you add an auth object with static client credentials:
{
"mcpServers": {
"oauth-server": {
"url": "https://api.example.com/mcp",
"auth": {
"CLIENT_ID": "${env:MCP_CLIENT_ID}",
"CLIENT_SECRET": "${env:MCP_CLIENT_SECRET}",
"scopes": ["read", "write"]
}
}
}
}Cursor's redirect URLs are fixed: http://localhost:8787/callback for the desktop app and https://www.cursor.com/agents/mcp/oauth/callback for web and Cursor Agents. More on Cursor setup is in the Cursor MCP guide.
What should you do when MCP sign-in fails?
Match the symptom to the cause. Each fix below comes from the client docs linked above.
- "Incompatible auth server: does not support dynamic client registration" in Claude Code. The Claude Code docssay this means "the server requires pre-configured credentials." Register an OAuth app in the server's developer portal and add the server again with
--client-id. In Claude, choose "Use your own OAuth client"; in Cursor, add theauthobject. - Redirect URI mismatch.The redirect registered on your OAuth app must match the client's exactly. Use the callback URL your client documents: Claude's, Cursor's fixed ones above, or for Claude Code
http://localhost:PORT/callbackwith the same port you pass to--callback-port. - The browser never opens.Claude Code's docs say to copy the URL it prints and open it yourself, and if the redirect then fails, "paste the full callback URL from your browser's address bar" into its prompt. Over SSH, use
claude mcp login <name> --no-browser. - Scripted runs say the server needs sign-in. A
claude -por Agent SDK run "has no/mcppanel, so Claude Code can't run the OAuth flow there." Sign in once interactively, or withclaude mcp login, before the scripted run. - OAuth never starts at all. If you set an
Authorizationheader for the server, Claude Code uses it and "doesn't fall back to OAuth for that server." Remove the header to get the browser sign-in. - It worked, then a tool says it needs more access. That is a step-up
403. Approve the new permission in the browser. In Claude Code, if you pinnedoauth.scopes, the docs say to add the missing scope there first, or the new token will still lack it.
How does Goro sign you in?
Goro is a remote MCP server at https://mcp.usegoro.ai/mcp that signs you in with OAuth 2.1 and dynamic client registration, so every client in this guide connects with the URL alone. There is no API key for the MCP connection; API keys exist only for Goro's REST API, and the setup for each route is in the docs.
Once you are signed in, your agent gets one catalog of real-world tools: web and news search, page scraping, social platform data, maps, people and company enrichment, and image, video and voice generation. It sees the price before each call and reports what ran and what it cost. A web search is from $0.0075 per page, and a web page scrape is from $0.005970 per result. Running tools needs a plan, from $19 a month with $25 of tool credit included, as listed on the pricing page. If you only need one service's data and that service has its own MCP server, connect that one directly. A gateway is worth it when you would otherwise sign in to, pay for and keep track of a separate server for each source.
Common questions
Does MCP use OAuth 2.0 or OAuth 2.1?
OAuth 2.1. The MCP authorization spec is built on the OAuth 2.1 IETF draft, plus OAuth 2.0 extensions such as protected resource metadata (RFC 9728), authorization server metadata (RFC 8414) and resource indicators (RFC 8707). In practice it is the authorization code flow with PKCE required.
Do I need an API key to connect a remote MCP server?
Not if the server supports MCP OAuth. You add the URL and sign in through your browser, and the client stores and refreshes the token. Some servers use a fixed token instead, which you send as a request header: Claude puts these under Request headers, Cursor's mcp.json has a headers field and Claude Code has a --header flag.
Is dynamic client registration deprecated in MCP?
Yes, as of spec revision 2026-07-28. The client registration page says Dynamic Client Registration is deprecated, that new implementations should use Client ID Metadata Documents, and that it remains available for backwards compatibility with authorization servers that do not support them. Existing servers that use it still work with clients that support it.
Can the MCP server see my password?
Not through the OAuth flow. You type your password into the authorization server's login page in your browser, and the client only receives tokens. Anthropic's connector guide says OAuth lets Claude act on your behalf without Claude ever seeing your actual password. The authorization server itself, which may belong to the same vendor as the MCP server, does handle your login.
How do I revoke an MCP server's access?
Remove or disconnect it in the client, and revoke it at the service too. In Claude, remove the connector under Customize > Connectors. In Claude Code, run claude mcp logout <name> before claude mcp remove <name>: the docs say removing a server deletes the stored tokens but doesn't revoke them at the authorization server.


