MCP reconnect fails with "MCP endpoint not found" for OAuth-protected remote HTTP servers (GitLab MCP)
Bug description
Reconnecting to a remote HTTP MCP server that uses OAuth (GitLab's MCP endpoint) fails with MCP endpoint not found, even though OAuth completes successfully and the configured endpoint URL is correct and reachable.
Steps to reproduce
- Add a remote HTTP MCP server pointing at GitLab's MCP endpoint:
````
claude mcp add --transport http GitLab https://gitlab.com/api/v4/mcp
- Run
/mcpand complete the OAuth login flow for GitLab. - Observe the reconnect error:
````
Got new credentials, but reconnecting to GitLab failed: MCP endpoint not found at https://gitlab.com. Check the URL in your MCP config.
This reproduces consistently, including after claude mcp remove GitLab + re-add with the same URL (ruling out stale local config).
Expected behavior
After OAuth completes, Claude Code should send MCP requests to the configured server URL (https://gitlab.com/api/v4/mcp), and the connection should succeed.
Actual behavior
The post-auth request appears to go to the bare OAuth issuer origin (https://gitlab.com) instead of the configured resource URL (https://gitlab.com/api/v4/mcp), which 404s.
Root cause analysis
I compared the actual HTTP behavior of GitLab's endpoints directly:
POST https://gitlab.com/api/v4/mcp(unauthenticated) →401 Unauthorized, with a correctWWW-Authenticate: Bearer realm="GitLab", resource_metadata="https://gitlab.com/.well-known/oauth-protected-resource/api/v4/mcp"header. This is the expected, spec-compliant response for the real MCP endpoint.GET https://gitlab.com/.well-known/oauth-protected-resource/api/v4/mcp→200, body:
``json``
{"resource":["https://gitlab.com/api/v4/mcp"],"authorization_servers":["https://gitlab.com"],"scopes_supported":["mcp"]}
POST https://gitlab.com/(the bareauthorization_serversvalue from the discovery response) →404, matching exactly the endpoint host reported in the Claude Code error message.
This strongly suggests Claude Code's OAuth reconnect logic is using the authorization_servers value from .well-known/oauth-protected-resource (the OAuth issuer) as the MCP request endpoint after authenticating, instead of continuing to use the originally configured server URL / the resource value from that same discovery response.
Environment
- Claude Code version: 2.1.233
- OS: Linux (Fedora)
- MCP server: GitLab remote HTTP MCP (
https://gitlab.com/api/v4/mcp), OAuth transport
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗