MCP Authentication
Some MCP servers need you to sign in.
Claude Code supports OAuth, a script that makes headers, and managed sign-in for enterprises.
For example, /mcp opens a panel where you start the OAuth sign-in for a server.
This page describes the options only. It does not walk through any account sign-in.
OAuth works for http and sse servers. Headers work for http, sse, and ws servers. Use the server oauth fields, headers, headersHelper, and env vars to change it. Turn it off with claude mcp logout, Clear authentication in /mcp, disableClaudeAiConnectors, or ENABLE_CLAUDEAI_MCP_SERVERS. Tokens are in secure storage.
OAuth Options
Source: Connect Claude Code to Tools via MCP, Environment Variables, and the program for the rows marked
| Item | Status | What It Does | How It Works |
|---|---|---|---|
| OAuth flow | Documented: An official docs page names this item. | Signs in to a remote server. | A 401 or 403 marks a server as needing auth. / or claude mcp login runs the flow. A 401 on a signed-in server refreshes the token and retries once. |
oauth. | Documented: An official docs page names this item. | Gives a pre-configured client ID. | For servers with no dynamic client registration. Claude Code also finds a Client ID Metadata Document (CIMD) on its own. |
oauth. | Documented: An official docs page names this item. | Fixes the callback port. | The redirect URI is http://. A positive integer. |
oauth. | Documented: An official docs page names this item. | Skips the discovery chain. | Must start with https://. The default order is RFC 9728 /., then RFC 8414 /.. |
oauth. | Documented: An official docs page names this item. | Pins the requested scopes. | One space-separated string, at least one character. It overrides the scopes in metadata. Claude Code adds offline_ if the server advertises it. |
oauth. | Gated: Works only behind a flag or a server gate. CLAUDE_CODE_ENABLE_XAA=1 | Enables XAA for the server. | Boolean. Without the gate Claude Code says Remove 'oauth.. |
--, --, -- | Documented: An official docs page names this item. | Set the OAuth fields when you add a server. | See MCP Commands. You set the secret only at add time. |
MCP_, MCP_ | Documented: An official docs page names this item. | Env forms of the secret and port. | The secret skips the prompt. Login and / never read it again. |
MCP_ | Undocumented: Only the program shows this item. It can change without notice. | Overrides the CIMD URL. | The program logs Using CIMD URL from env. |
| Token storage | Documented: An official docs page names this item. | Keeps tokens. | Claude Code stores tokens securely and refreshes them. The client secret is in the macOS keychain or a credentials file. Clear authentication in / and claude mcp logout remove them. |
| v2 runtime checks | Documented: An official docs page names this item. | Hardens OAuth. | Fails on an unexpected issuer. Sends credentials only to https or loopback token endpoints. |
| Local OAuth refusal | Documented: An official docs page names this item. | Handles hosted connectors. | Microsoft 365, Gmail, and Google Calendar hosts need claude.ai. Claude Code shows is Anthropic-. |
| No OAuth fallback | Documented: An official docs page names this item. | Respects your header. | If the server rejects a configured Authorization header (static or from a helper), the connection fails. There is no auth prompt. |
headersHelper
A headersHelper is a shell command that prints request headers.
Use it for short-lived tokens.
| Item | Status | What It Does | How It Works |
|---|---|---|---|
| Command | Documented: An official docs page names this item. | Prints headers. | A shell command. The output is a JSON object of strings. It reaches its timeout after 10 s. It overrides static headers. It runs on each connect and again after a 401 or 403. |
CLAUDE_, CLAUDE_ | Documented: An official docs page names this item. | Tell the helper which server it serves. | Set only for the helper. The URL hides a live credential value as REDACTED. |
CLAUDE_ | Documented: An official docs page names this item. | The plugin folder. | Set only for a plugin server. |
| Working folder | Documented: An official docs page names this item. | Resolves relative paths. | The plugin folder, the project folder, the primary working folder, or ~/. (user, managed, connector). It depends on where you configure the server. |
| Env scrub | Documented: An official docs page names this item. | Hides credential variables. | Project ., plugin, and project agent servers receive no variables with TOKEN, SECRET, PASSWORD, KEY, or AUTH in the name, plus a fixed list. |
| Trust rule | Documented: An official docs page names this item. | Runs the helper late. | Project and local servers run it only after the trust dialog for the folder that declares them. Until then, Claude Code uses only static headers. |
${user_ | Documented: An official docs page names this item. | Plugin options. | Not allowed. Claude Code reports the server as misconfigured. Before 2. it substituted them. |
| Policy refusal | Documented: An official docs page names this item. | Refuses a plugin helper. | A marketplace entry with headers must inline its full manifest with strict:. Otherwise Claude Code refuses to run it. |
XAA
XAA (SEP-990) signs you in through an enterprise identity provider (IdP).
It is off. Set CLAUDE_CODE_ENABLE_XAA=1 to turn it on.
| Item | Status | What It Does | How It Works |
|---|---|---|---|
| XAA | Gated: Works only behind a flag or a server gate. CLAUDE_CODE_ENABLE_XAA=1 | Signs in through an enterprise IdP. | All XAA servers share one IdP connection. Claude Code swaps a cached IdP id_ for a server token. Servers with oauth. use it. |
| Gate | Gated: Works only behind a flag or a server gate. CLAUDE_CODE_ENABLE_XAA=1 | Turns XAA on. | An env var. |
| Setup | Gated: Works only behind a flag or a server gate. CLAUDE_CODE_ENABLE_XAA=1 | Stores the IdP data. | claude mcp xaa setup writes xaa. The secret comes from MCP_ and goes to the keychain. |
| Login | Gated: Works only behind a flag or a server gate. CLAUDE_CODE_ENABLE_XAA=1 | Caches the IdP token. | claude mcp xaa login. Without it Claude Code says no Id. |
Claude.ai Connectors
Connectors are MCP servers that you configure in claude.ai. Claude Code fetches them only when you use a claude.ai login.
| Item | Status | What It Does | How It Works |
|---|---|---|---|
| Fetch | Documented: An official docs page names this item. | Loads the connectors of your account. | Only with a claude.ai subscription login. Not with an API key, ANTHROPIC_, api, a cloud provider, a profile, or a setup- token. Works in the terminal, VS Code, JetBrains, and the SDK. |
ENABLE_ | Documented: An official docs page names this item. | Switch for the fetch. | false stops it for the shell session. |
disable | Documented: An official docs page names this item. | Switch in settings. | See MCP Settings and Policy. |
| Per-tool controls | Documented: An official docs page names this item. | Organization policy on connector tools. | ask prompts on each call. blocked hides the tool. See tool in Server Configuration. |
| Session token rejected | Documented: An official docs page names this item. | A separate state from a connector problem. | Run /, then reconnect. Authorizing the connector again does not help. |
| Cloud and desktop sessions | Documented: An official docs page names this item. | Other delivery paths. | A cloud host or the desktop app delivers connectors. disable does not act on them. |
Example
{
"mcpServers": {
"crm": {
"type": "http",
"url": "https://crm.example.com/mcp",
"oauth": {
"clientId": "my-client-id",
"callbackPort": 8765,
"scopes": "read write"
}
},
"internal": {
"type": "http",
"url": "https://tools.example.com/mcp",
"headersHelper": "./scripts/mcp-headers.sh"
}
}
}
The helper script prints {"Authorization": "Bearer <token>"} to stdout. Then it exits.
How It Works
Errors
Each row is a family of messages. The backticked text is the start that every message in the family shares.
| Start of Message | Status | What It Means | Cases |
|---|---|---|---|
XAA, auth, Configured auth server metadata, HTTP ${…} fetching configured auth server, Unexpected auth result, Invalid authorization URL, No TTY available to prompt for client secret, Enter OAuth client secret, Unable to build claude., Server type "${…}" does not support OAuth, No OAuth flow in progress, Invalid callback URL, MCP OAuth failed, OAuth flow completed without, No available ports for OAuth redirect, client | Undocumented: Only the program shows this item. It can change without notice. | An MCP OAuth or XAA (cross-app access) sign-in step failed. | Discovery of protected resource metadata or authorization server metadata failed or did not match, the token endpoint is not HTTPS, the token exchange or jwt-bearer grant failed or returned an unexpected shape, XAA is not enabled (CLAUDE_), no IdP connection is configured, or the callback URL does not belong to this sign-in. In 2., the server now names an authorization server other than the one you signed in with (XAA:). If the move is expected, run claude mcp remove for the server and add it again with its client secret (chunk-). |
Related Pages
- MCP
- MCP Commands
- MCP Env Vars
- Settings: Authentication for the sign-in of Claude Code itself