Skip to main content

How OAuth Sign-In Works for MCP Servers

Short answer

A remote MCP server that needs your account uses OAuth. The first time your AI app calls it, the server replies 401 Unauthorized, and the app opens the service's own sign-in page in your browser. You log in there and approve the access the server asks for. The app then keeps a token and sends it with later requests, so you sign in once instead of on every tool call. Local servers that run on your computer don't use this flow.

Tested withMCP spec 2026-07-28Checked 20 Oct 2026

The sign-in, step by step​

From your side, the sequence is short. Your app is doing the protocol work in the background.

  1. You add the server's URL to your app. Nothing is signed in yet.
  2. The first time the app calls a tool, the server refuses it with a 401 response that points to the sign-in service.
  3. The app opens that service's sign-in page in your browser. The address bar shows the service's domain, not the AI app's.
  4. You log in and see a consent screen listing what the server wants to do. Check it before you approve.
  5. The service sends your browser back to the app. The app swaps the code it receives for an access token. The protocol also requires a PKCE code challenge, so an intercepted code isn't enough on its own.
  6. The app sends the token in an Authorization header on every later request to that server.

The 401 response is what starts the whole flow. The MCP authorization specification gives this example:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource",
scope="files:read"

The resource_metadata link tells the app where the sign-in service is, and scope lists the permissions the server needs right now.

Where sign-in starts, and how to remove it​

Every app puts sign-in in a different place. The table shows what each app's docs say, as of 2026-10-20. Where a docs page doesn't cover sign-out, the table says so.

AppStart sign-inSign out or remove access
Claude CodeRun /mcp in a session, or run claude mcp login <name> in your shellSelect Clear authentication in /mcp, or run claude mcp logout <name>. Removing the server also deletes its stored tokens.
Claude (Desktop and claude.ai)Go to Customize > Connectors, then click Connect on the connectorRemove the connector in Customize > Connectors, or disconnect it in Claude's settings
CodexSelect Authenticate in the MCP server list, or run codex mcp login <name>The Codex docs don't list a sign-out command. Revoke the app in the service's security settings.
CursorAdd the server from Customize. Marketplace servers authenticate with OAuth when you click Add to Cursor.Turn the server off or remove it in Customize. The docs don't list a sign-out step.
Gemini CLIRun /mcp auth <name>The docs don't list a sign-out command. Tokens are kept in ~/.gemini/mcp-oauth-tokens.json.
VS CodeAdd the server with MCP: Add Server, then follow the publisher's sign-in promptThe docs page doesn't cover sign-out.
ChatGPT (connected apps)Go to Settings > Plugins, select the app, then ConnectGo to Settings > Plugins, select the app, then disconnect it

Removing a server from an app and revoking the app's access at the service are two different things. Claude Code's removal deletes the tokens it stored on your machine. Claude's help center says you can revoke the permissions by disconnecting the connector in Claude's settings or in the third-party service's security settings, so use both when you want the access gone for good.

Sign-in is per app and per account​

Signing in to a server in one app doesn't sign that app's other servers in, and it doesn't sign another app in. Each app gets its own token during its own sign-in. Claude Code keeps sign-ins per endpoint, so if the same server name is defined in two scopes with different URLs, you sign in separately for each one.

The account you're signed into at the service is the one the server acts for. If you have two accounts, pick the right one on the sign-in page.

When the app asks you to sign in again​

A token isn't a permanent login. Several things send you back to the sign-in page:

  • The app can't refresh the token. When a token expires, Claude Code refreshes it and retries the request once. Refresh tokens aren't guaranteed, though. The specification says clients must not assume one will be issued. When the stored refresh token is rejected, Claude Code shows a notice pointing to /mcp, where you select Re-authenticate on the server.
  • The server wants more permission. If a tool needs a scope you didn't approve, the server answers 403 Forbidden with error="insufficient_scope" and the scope it needs. The app should ask you to approve the wider set. The specification asks servers to list every scope an operation needs in one challenge, so you shouldn't be sent back again and again for the same tool.
  • You revoked the access, either at the service or in the app.

Gemini CLI has the same idea in its own words: run /mcp auth <name> again when the tokens expire.

What the app can see​

The sign-in happens on the service's own page, so the AI app receives a token and doesn't see your password. Anthropic's help center says connecting Claude this way means Claude never sees your actual password.

A token only works with the server it was issued for. The specification says a client must not send a token to any server other than the one whose authorization server issued it, and the server must reject tokens meant for something else. Claude Code also sends OAuth credentials only to an HTTPS token endpoint or to localhost, so a plain http:// endpoint elsewhere fails.

A token also lets the server act for you, within the scopes you approved. Read the consent screen before you approve it, and deny anything that asks for more than the server's job needs.

Common misconceptions​

"Local servers need OAuth too." They don't. The specification says a server using stdio should get its credentials from the environment instead. Claude Code's claude mcp add can pass them with -e, for example.

"I signed in once, so it's permanent." Tokens can stop working when the service revokes them, when a refresh fails, or when the server asks for a new scope. Expect to sign in again sometimes.

"Removing the server revokes its access." It removes the stored copy of the token in your app. The service's own list of authorized apps is separate, and you need to revoke there too.

"A 401 means my password is wrong." A 401 from an MCP server means the request had no valid token. Sometimes that's because the sign-in never finished, and sometimes the token expired or was revoked. Signing in again usually fixes it.

Check that it worked​

Run a read-only tool and check the result:

  • In Claude Code, /mcp shows a checkmark next to a connected server. A server that needs sign-in shows ! Needs authentication in claude mcp list.
  • In Codex, the MCP server list shows which servers need OAuth. Select Authenticate on one that does.
  • In Gemini CLI, /mcp auth lists the servers that need sign-in.
  • In Cursor, the MCP Logs view in the Output panel shows connection errors and authentication problems.

If a tool call returns a result, the sign-in worked.

Common problems​

Failed to connect with a 401 in the detail. Claude Code shows the HTTP status the server returned in claude mcp get <name>. A 401 means the server didn't accept the token. Run /mcp and select Re-authenticate. If it still fails, check that the endpoint is the one the service documents.

The server rejects a token you configured yourself. You may have set an Authorization header in the server's config. Claude Code reports the connection as failed rather than falling back to OAuth when that header is rejected. Remove the header to use OAuth, or fix the token in it.

The browser doesn't open, or the redirect fails with a connection error. In Claude Code, copy the sign-in URL from the prompt and open it yourself. If the browser lands on an error after you sign in, copy the full callback URL from the address bar and paste it into the URL prompt in Claude Code.

claude -p says the server needs authentication. Non-interactive runs have no /mcp panel, so they can't start the sign-in. Sign in from an interactive session or with claude mcp login <name> first.

For more connection errors, see Fix MCP connection errors.

FAQ​

Do I have to sign in to every MCP server?

No. Only servers that need access to your account ask you to sign in. A server that runs on your computer should read its credentials from environment variables instead of using OAuth, according to the MCP specification.

Does the AI app get my password when I sign in to an MCP server?

No. The sign-in happens on the service's own page in your browser, and the app receives an access token. Anthropic says connecting Claude this way means Claude never sees your password.

How do I sign out of an MCP server?

It depends on the app. In Claude Code, select Clear authentication in the /mcp menu. In Claude, remove the connector in Customize > Connectors. For the others, use the app's server list to turn the server off or remove it, then revoke the app in the service's security settings.

Why does my MCP server keep asking me to sign in?

The app may be unable to refresh its token, the server may need a permission you haven't approved, or you or the service may have revoked the access. Sign in again from the app's server list. If the sign-in keeps failing, check the app's logs.

Do I need to sign in separately in each AI app?

Yes. Each app gets its own token during its own sign-in, so sign in once in each app you use.

  • MCP clientsWhich AI apps run local servers, which run remote servers, and which support OAuth.
  • Claude CodeAdd remote and local servers with claude mcp add, and sign in from /mcp.
  • CursorConfigure mcp.json and sign in to remote servers from Customize.
  • Fix MCP connection errorsWork through 401 loops, failed connections and missing logs.
  • MCP authorization for buildersHow a server validates tokens and advertises its sign-in service.