Omniscio

OmniscioGuidesClaude Code MCP OAuth

Claude Code MCP OAuth: signing in to a remote MCP server

OAuth is how Claude Code signs in to a remote MCP server that belongs to a service you already have an account with. The flow is the same one you have seen in other tools, with a handful of Claude Code specifics that decide whether it succeeds.

This page owns authentication. Adding an MCP server owns the transports and the add commands, MCP errors owns the failure messages, and the callback-port page owns the one error where the port is already taken.

Sources read November 26, 2026. By the Omniscio team. Updated .

How Claude Code decides a server needs a sign-in

Claude Code marks a remote server as needing authentication when the server responds with 401 Unauthorized or 403 Forbidden. What happens next depends on the server. Only the first case below becomes a sign-in prompt; the other three are reported as something else.

  • A server you have never signed in to is flagged in /mcp, so you can complete the flow there.
  • A claude.ai connector whose 401 comes from claude.ai rejecting your session token is not flagged, because re-authorizing the connector cannot fix your login; Claude Code reports the session-token-rejected state instead.
  • A server whose Authorization header you configured, in headers or through a headersHelper, is not flagged: the credential to fix is the one you supplied, so the connection is reported as failed.
  • A connector delivered to a cloud session gets no sign-in flow, because the session's proxy authenticates with the authorization you granted in claude.ai; reconnect it at claude.ai/customize/connectors instead.

Claude Code also shows a startup notice when configured servers need authentication, so you do not have to open /mcp to find them. The notice counts only servers you can sign in to from Claude Code, announces each one once, and leaves it out of later counts until it connects and needs sign-in again. /mcp still lists every server that needs a sign-in.

The sign-in flow

Add the server, then run /mcp inside Claude Code and follow the browser steps. Anthropic's example adds Sentry's remote server first.

claude mcp add --transport http sentry https://mcp.sentry.dev/mcp

Four tips from the docs cover most of the friction: tokens are stored securely and refreshed automatically; Clear authentication in the /mcp menu revokes access; if the browser does not open, copy the URL and open it manually; and if the redirect fails with a connection error after you authenticate, paste the full callback URL from the browser's address bar into the prompt Claude Code shows.

When the stored token is rejected

A server you already signed in to can reject the stored token with a 401. With a refresh token, Claude Code refreshes it, reconnects and retries once, and flags the server only if that retry fails too. Without a refresh token it connects once without the token: if the server answers, its tools work while you are signed out and the rejected token is deleted; if not, /mcp shows that the server needs authentication.

When the server rejects the stored refresh token, Claude Code shows a notice pointing at /mcp. Open it and choose Re-authenticate before the next tool call fails.

Signing in from the shell

claude mcp login <name> runs the flow directly from your shell, so you never open the panel; claude mcp logout <name> clears the stored credentials later.

claude mcp login sentry
claude mcp login sentry --no-browser

The command notices when there is no local browser, such as over SSH or on Linux without a display server, and prints the authorization URL instead. Open it on your own machine and paste the full redirect URL back at the prompt. That paste needs an interactive terminal, so connect with ssh -t; --no-browser forces the URL prompt even when a browser is detected.

A run with no panel cannot sign in

A claude -p or Agent SDK run has no /mcp panel, so the OAuth flow cannot run there. Complete the sign-in first in an interactive session or with claude mcp login, and the stored token is used afterwards. If a server still needs authentication during such a run with tool search enabled, Claude Code tells Claude the server's tools are unavailable until you authorize it.

A fixed callback port

Some servers require a redirect URI registered in advance. By default Claude Code picks a random available port for the OAuth callback; --callback-port fixes it so the callback matches a pre-registered http://localhost:PORT/callback.

claude mcp add --transport http \
  --callback-port 8080 \
  my-server https://mcp.example.com/mcp

The flag works on its own with dynamic client registration, or together with --client-id when you also supply credentials. If the port is already in use, the callback-port page owns that error.

Pre-configured credentials

When a server does not support Dynamic Client Registration, sign-in fails with a message like "Incompatible auth server: does not support dynamic client registration". Claude Code also discovers servers that publish a Client ID Metadata Document automatically; when that fails too, you register an OAuth app through the server's developer portal and pass its credentials.

If the registration form asks for a redirect URI, enter http://localhost:PORT/callback with the port you intend to use, then add the server with the same port.

claude mcp add --transport http \
  --client-id your-client-id --client-secret --callback-port 8080 \
  my-server https://mcp.example.com/mcp

--client-secret takes no value: Claude Code prompts for the secret when you add the server.

As JSON, the same credentials go in an oauth object, with --client-secret as a separate flag; setting callbackPort alone lets Claude Code register the client itself. In CI, set MCP_CLIENT_SECRET to skip the interactive prompt.

One version detail explains a mismatch error: Claude Code v2.1.229 sent http://127.0.0.1:PORT/callback, which servers that exact-match the registered URI rejected; v2.1.231 restored the localhost form. Upgrade, or temporarily add the 127.0.0.1 form to the server's registered URIs.

The client secret is stored in the system keychain on macOS or in a credentials file, never in your configuration. It can only be set when you add the server — later sign-ins use the stored secret and do not prompt for one — so changing it means removing the server and adding it again with the same --scope. A public client with no secret uses --client-id alone. These flags apply to HTTP and SSE transports only, and claude mcp get <name> confirms whether OAuth credentials are configured.

Metadata discovery and scopes

By default Claude Code looks for RFC 9728 Protected Resource Metadata at /.well-known/oauth-protected-resource, then falls back to RFC 8414 authorization server metadata at /.well-known/oauth-authorization-server. To bypass that chain — because the standard endpoints error, or because discovery must go through an internal proxy — set authServerMetadataUrl in the server's oauth object. The URL must use https://, and its scopes_supported overrides what the upstream server advertises.

To pin what Claude Code asks for, set oauth.scopes to a single space-separated string. It takes precedence over both the metadata URL and the scopes discovered at /.well-known, which is the supported way to grant an approved subset when the authorization server advertises more than you want.

Two wrinkles. If the authorization server advertises offline_access, Claude Code appends it to the pinned scopes so the token can refresh without another browser sign-in. And if a tool call later fails with a 403 insufficient_scope, the error names the scope the server wants: add it to oauth.scopes and authenticate again, because otherwise the new token still lacks it.

A server behind an authenticating proxy

If the MCP server sits behind a proxy or gateway that checks a header of its own, sign-in fails when the OAuth requests arrive without that header. Signing in through the proxy needs Claude Code v2.1.299 or later, with two things configured. First, pass the proxy's header through --header, the headers field or a headersHelper, under the name the proxy reads. Second, keep Authorization out of those headers and sign in with claude mcp login <name>. An Authorization header you configure is used as the server's credential, and Claude Code does not fall back to OAuth for that server.

Sources

Every line on this page rests on one source. The date is the day we read it.

  • Connect Claude Code to tools via MCP, for the Authenticate with remote MCP servers section: the 401 handling, the sign-in flow, claude mcp login, the callback port, pre-configured credentials, metadata discovery, scopes and the proxy case. Read November 26, 2026.

No OAuth sign-in was run for this page. Every flag, message and version floor is transcribed from that page.

Common questions

How do I authenticate an MCP server in Claude Code?

Add the server, then run /mcp inside a session and follow the browser login, or run claude mcp login with the server's name in your shell. Claude Code marks a remote server as needing authentication when it answers 401 or 403.

Why does my MCP server show as needing authentication?

The server answered 401 or 403 and you have not signed in, a stored token was rejected with no refresh token to recover it, or the token lacks a scope a tool needs. Open /mcp and choose the server to sign in or re-authenticate.

Can I sign in to an MCP server in a non-interactive run?

No. A claude -p or Agent SDK run has no /mcp panel, so the OAuth flow cannot run there. Complete the sign-in first in an interactive session or with claude mcp login, and the stored token is used afterwards.

What is the OAuth callback port in Claude Code?

By default Claude Code picks a random available port for the callback. Pass --callback-port when the server compares against a redirect URI you registered in advance, in the form http://localhost:PORT/callback.

Where is the MCP client secret stored?

In the system keychain on macOS or in a credentials file, not in your configuration. It can only be set when you add the server, so changing it means removing the server and adding it again with the new secret.

Every session, one window

Omniscio runs several agent sessions side by side in one window, each with its own context and its own diff view. Any model, any harness: Claude Code, Codex, OpenCode, Devin, Pi, and Hermes all supported.