Fix: MCP Authorization Bearer Error
Updated 2026-11-17
Remote MCP servers often return 401 Unauthorized when the Authorization: Bearer header is missing, malformed, or expired. The fix depends on whether the server expects OAuth (Cursor completes a browser flow) or a static API key you paste into headers. This guide covers both patterns used on aiagenthowto.com. Start with Fix: MCP server not connecting when no tools load at all. Last tested 2026-11-17.
Docs used:
Prerequisites
- An MCP client showing 401,
invalid_token, orUnauthorizedin logs - Access to regenerate API keys or repeat OAuth for the service
Steps
1. Read the exact error
Open the client’s MCP log (Cursor: Settings → MCP → show logs). Note whether the server mentions Bearer, token expired, or invalid_scope.
2. Prefer OAuth when the host documents it
Hosted servers such as Notion (https://mcp.notion.com/mcp) and Linear (https://mcp.linear.app/mcp) expect you to finish OAuth in the client. Remove stale headers blocks that override OAuth with an old token.
{
"mcpServers": {
"linear": {
"url": "https://mcp.linear.app/mcp"
}
}
}
Then reconnect and complete the browser prompt. Linear suggests clearing saved auth with rm -rf ~/.mcp-auth if OAuth fails repeatedly.
3. Use Bearer only when docs require a PAT or API key
GitHub’s remote MCP documents a PAT in headers for Cursor:
{
"mcpServers": {
"github": {
"url": "https://api.githubcopilot.com/mcp/",
"headers": {
"Authorization": "Bearer YOUR_GITHUB_PAT"
}
}
}
}
Replace YOUR_GITHUB_PAT with a current token; scopes must match the tools you call (GitHub MCP server).
4. Match header format exactly
Use the literal prefix Bearer (capital B, trailing space) unless the provider states otherwise. Do not wrap the token in extra quotes inside JSON.
Wrong:
"Authorization": "YOUR_TOKEN_WITHOUT_BEARER"
Right:
"Authorization": "Bearer ghp_xxxxxxxx"
5. Rotate expired secrets
Regenerate PATs, Linear API keys, or Notion MCP tokens in the provider’s admin UI. Update mcp.json or environment variables, restart the MCP client, and never commit secrets.
6. Separate read-only tokens
When you only need search/read tools, use provider read-only endpoints (Linear /mcp/readonly) or keys limited to Read permissions.
Common errors
401 after OAuth succeeded once: Cached credentials under ~/.mcp-auth or the client’s MCP store are stale. Clear auth cache, disconnect the server, and sign in again.
Bearer set but OAuth also enabled: Conflicting config—remove manual headers when using interactive OAuth servers.
403 instead of 401: Token is valid but lacks scope. GitHub auth failures often need the repo scope for private repositories (GitHub install guide).
Works in Cursor but not Claude Desktop: Client config keys differ (mcpServers vs Docker stdio). Use the install guide for each client; see Fix: MCP server not connecting.
FAQ
Should I put the token in an environment variable?
Yes for CI and Docker MCP servers. Reference it in config as "Authorization": "Bearer ${LINEAR_API_KEY}" only if your client expands env vars—otherwise inject at runtime from process.env in a small launcher script.
Is a Bearer token the same as MCP mcp-remote?
No. mcp-remote bridges stdio to HTTP and runs its own OAuth. Bearer headers apply to direct HTTP MCP clients.
Where do I test the header?
Use MCP Inspector or your client’s “list tools” action after fixing headers—see Build an MCP server in Python for local server testing patterns.