Menu

AI

MCP 401 Unauthorized: How to Fix It (Claude, Claude Code, Cursor, VS Code)

Fix 401 Unauthorized from a remote MCP server. Sign in again, check token audience and scopes, remove redirects that drop the header, and fix discovery.

By: Irina ShvayaNovember 2, 2026

MCP 401 Unauthorized: How to Fix It (Claude, Claude Code, Cursor, VS Code)

This fix is part of MCP troubleshooting, within The MCP Guide. Still stuck? Request a free MCP readiness review.

A 401 Unauthorized from a remote MCP server means the server did not accept your credentials: the token is missing, expired, revoked, or issued for a different server. As a user, the fastest fix is to sign in again from your client (in Claude Code, run /mcp and authenticate). As a server owner, check that your 401 includes a WWW-Authenticate header with resource_metadata, and that your MCP URL does not redirect to another host.

Checked against: the MCP 2026-07-28 authorization spec, its authorization server discovery page, Claude's connector authentication docs, Claude's connector troubleshooting page and the Claude Code MCP docs on 2 November 2026. eSEOspace did not test any vendor's server.

Key Takeaways

  • The MCP spec says "invalid or expired tokens MUST receive a HTTP 401 response," and 403 is for "invalid scopes or insufficient permissions."
  • A 401 is also how sign-in starts: the server answers with WWW-Authenticate: Bearer resource_metadata="...", and the client discovers where to log in.
  • Claude's docs say a 401 is required to start sign-in, and Claude ignores WWW-Authenticate on a 200 response.
  • If your MCP URL redirects to another host, Claude drops the Authorization header, the target returns 401, and you see "Authorization with the MCP server failed."
  • Claude Code marks a server as needing authentication on 401 or 403, but does not fall back to OAuth if you set a static Authorization header that the server rejects.

What this error means

Remote MCP servers act as OAuth 2.1 resource servers. The authorization spec says servers "MUST validate that access tokens were issued specifically for them as the intended audience." A token for another service, even from the same identity provider, must be rejected.

A 401 has two meanings in practice:

  • Expected: The first call has no token. The server returns 401 with a pointer to its protected resource metadata. The discovery page says clients "MUST be able to parse WWW-Authenticate headers and respond appropriately." Your client then opens a sign-in page.
  • A real failure: You signed in, but calls still return 401. The token expired and refresh failed, the token was issued for a different audience, or something between client and server stripped the header.

Quick fix

If you use the server:

  1. Sign in again. In Claude, reconnect the connector under Customize > Connectors. In Claude Code, run /mcp and authenticate. In Cursor, sign out and back in on the server's row in Customize.
  2. Check API keys. If you pass a key in headers, confirm it is current and has the scopes the server needs.
  3. Check the URL. Use the exact URL from the vendor's docs, including the path, such as /mcp.

If you run the server:

  1. Return a proper 401. Include WWW-Authenticate: Bearer resource_metadata="https://your-server/.well-known/oauth-protected-resource".
  2. Match the resource. Claude's docs say the metadata's resource field "must equal the URL as the user enters it in Claude, including any path component."
  3. Accept the canonical audience. Claude's troubleshooting page says Claude sends the RFC 8707 resource parameter as the canonical server URL: lowercase scheme and host, no trailing slash, no default port.
  4. Remove cross-host redirects. Run curl -sI https://your-server/mcp. A 3xx to another host means you should register the target URL instead.
  5. Return invalid_grant when a refresh token is no longer valid, per Claude's authentication docs.
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource"

Fix by client / OS

Claude (claude.ai, Desktop, mobile)

Claude's authentication docs say Claude refreshes tokens "reactively on a 401 response, and proactively up to five minutes before the stored expiry." If refresh fails, you need to reconnect. The troubleshooting page lists issuer mismatch, audience mismatch, missing S256 PKCE, slow token endpoints and cross-host redirects as causes of "Authorization with the MCP server failed."

Claude Code

The Claude Code MCP docs say Claude Code marks a remote server as needing authentication when it responds with 401 Unauthorized or 403 Forbidden. claude mcp list then shows ! Needs authentication. Run /mcp to sign in. If you configured headers.Authorization and the server rejects it, Claude Code "reports the connection as failed instead of falling back to OAuth," so remove the header if you want OAuth.

Cursor

Cursor's MCP docs support ${env:NAME} inside headers. If that variable is not set where Cursor can read it, the server may get an empty or wrong token and return 401. Check Output > MCP Logs.

VS Code

On the VS Code MCP management page, HTTP connection and authentication failures appear in the troubleshooting table. Use MCP: List Servers > Show Output to see the response.

Where to find the logs

  • Server side: your access logs show whether a request arrived with an Authorization header and which audience the token carried.
  • claude.ai: the ofid_ reference ID in the error URL; report it on the anthropics/claude-ai-mcp tracker.
  • Claude Code: claude mcp get <name> shows the HTTP status on an Issue: line.
  • Cursor: MCP Logs. VS Code: Show Output.

If it still fails

Check the status code meaning with the MCP error code lookup. If you need OAuth done right on your own server, talk to our MCP development team.

More in the MCP Guide

Free tools: MCP Error Code Lookup · MCP Config Generator

Latest research: State of MCP: October 2026

Frequently asked questions

Is a 401 from an MCP server always an error?

No. The first request to a protected server is expected to get a 401. That response tells the client where to sign in. It is only a problem if it repeats after you sign in.

What is the difference between 401 and 403 in MCP?

The spec uses 401 for "authorization required or token invalid" and 403 for "invalid scopes or insufficient permissions." A 403 usually means you need a broader scope or a different role.

Can I put the API token in the URL instead?

No. The MCP spec says access tokens "MUST NOT be included in the URI query string," and Claude's docs warn that URLs end up in logs and browser history.

Why does my token from the same provider get rejected?

The server must accept only tokens issued for it. A token minted for another API has the wrong audience, even if the same identity provider issued it.

You Might Also like to Read

Get a FREE Website Audit

Enter your website and get a 20–30 page SEO, GEO, AEO & CRO audit within 24 hours. Completely free.

Don't have a site yet? Get in touch →

Ready to speak with a marketing expert?
Give us a call! (916) 866-7893

Websites Launched
1407
Websites Launched
Marketing Experts
29
Marketing Experts
Hours of Dedicated Work
204533
Hours of Dedicated Work
Irina S.Benjamin G.Jeanette M.David G.