[BUG] HTTP MCP server behind basic auth: stale mcpOAuth entry in .credentials.json forces OAuth flow on every session

Resolved 💬 2 comments Opened Apr 13, 2026 by rafipiccolo Closed Apr 22, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When connecting to a Streamable HTTP MCP server protected by Traefik basic auth, Claude Code creates a stale mcpOAuth entry in ~/.claude/.credentials.json with empty tokens. This entry persists across sessions and forces an OAuth authentication flow on every new session, even after configuring static credentials via headers or headersHelper in .mcp.json.

What Should Happen?

  • A 401 with WWW-Authenticate: Basic should not trigger OAuth discovery
  • Adding headers or headersHelper to .mcp.json should take precedence over any cached OAuth state

Stale mcpOAuth entries with empty tokens (accessToken: "", expiresAt: 0) should not block normal authenticated connections

Workaround :
Manually delete the mcpOAuth key from ~/.claude/.credentials.json. It gets recreated on next session if the underlying issue isn't addressed.

Error Messages/Logs

Steps to Reproduce

  1. Configure an HTTP MCP server behind a reverse proxy with basic auth:

```json
// .mcp.json
{
"mcpServers": {
"myserver": {
"type": "http",
"url": "https://myserver.example.com/mcp"
}
}
}
Start a Claude Code session — the MCP client gets a 401 from basic auth
Claude Code interprets this as OAuth and creates authenticate / complete_authentication tools
A mcpOAuth entry is written to ~/.claude/.credentials.json:

"mcpOAuth": {
"myserver|abc123": {
"serverName": "myserver",
"serverUrl": "https://myserver.example.com/mcp",
"accessToken": "",
"expiresAt": 0,
"discoveryState": {
"authorizationServerUrl": "https://myserver.example.com/"
}
}
}
Even after adding headersHelper or header field to .mcp.json to send the Authorization: Basic ... header, the stale mcpOAuth entry keeps triggering the OAuth flow

Environment
Claude Code (VS Code extension)
MCP server: custom Streamable HTTP server (@modelcontextprotocol/sdk 1.29.0)
Auth: Traefik reverse proxy with basic auth middleware

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.104

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

VS Code integrated terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗