Skip to content

[BUG] OAuth Authentication Succeeds but MCP Reconnection Fails - Requires Restart #10250

Closed

Description

@jhinrichsen

Bug Report: OAuth Authentication Succeeds but MCP Reconnection Fails - Requires Claude Code Restart

Summary

After successful OAuth authentication with an MCP server using streamable-http transport, Claude Code displays "Authentication successful, but server reconnection failed. You may need to manually restart Claude Code for the changes to take effect." The OAuth tokens are correctly stored, but MCP tools remain unavailable until Claude Code is restarted.

Environment

  • Claude Code Version: 2.0.26
  • OS: Linux (Fedora 42, kernel 6.16.12)
  • MCP Server: Custom Quarkus-based MCP server
  • Transport: streamable-http
  • Auth Method: OAuth 2.0 with Dynamic Client Registration (RFC 7591)
  • OAuth Provider: Keycloak 24.0.3

Steps to Reproduce

  1. Configure an MCP server with OAuth using streamable-http transport:

    claude mcp add --transport http myserver http://localhost:8080/mcp
  2. Start MCP server with OAuth/OIDC enabled:

    • Server implements Dynamic Client Registration (DCR)
    • Server provides protected resource metadata at /.well-known/oauth-protected-resource
    • Token lifetime: 24 hours
    • Redirect URIs: localhost only (as per MCP spec)
  3. Run /mcp command in Claude Code

  4. Complete OAuth flow in browser (login with test user)

  5. Observe authentication completion in browser

Expected Behavior

Based on Claude Code MCP documentation:

"Authentication tokens are stored securely and refreshed automatically."

Expected: After OAuth completes, Claude Code should:

  1. Store the OAuth tokens ✅ (works)
  2. Automatically reconnect to the MCP server using stored tokens ❌ (fails)
  3. Load authenticated MCP tools immediately ❌ (fails)
  4. No restart required ❌ (restart IS required)

Actual Behavior

  1. OAuth authentication completes successfully in browser
  2. Tokens are correctly stored in ~/.claude/.credentials.json:
    {
      "mcpOAuth": {
        "myserver|<hash>": {
          "serverName": "myserver",
          "serverUrl": "http://localhost:8080/mcp",
          "clientId": "<dynamically-registered-client-id>",
          "accessToken": "[valid 24h JWT token]",
          "expiresAt": 1761406726618,
          "refreshToken": "[valid refresh token]",
          "scope": "email profile"
        }
      }
    }
  3. Claude Code displays error: "Authentication successful, but server reconnection failed. You may need to manually restart Claude Code for the changes to take effect."
  4. MCP tools are NOT available in the current session
  5. Running claude mcp list shows: ✗ Failed to connect
  6. After restarting Claude Code:
    • Connection succeeds automatically using stored tokens
    • All authenticated MCP tools are available
    • No re-authentication needed

Technical Details

Token Validity

The stored access token is valid and working:

  • Decoded JWT shows: exp: 1761406726 (24 hours from issuance)
  • Token contains correct user identity
  • Token includes proper scopes (email profile)
  • Token can successfully call authenticated API endpoints when tested directly with curl

Server Configuration

  • MCP server is running (verified with curl http://localhost:8080/mcp → HTTP 405 as expected)
  • Server properly implements:
    • Dynamic Client Registration endpoint
    • OAuth 2.0 protected resource metadata (RFC 9728)
    • PKCE flow support
    • Token validation

Transport Details

Workaround

Restart Claude Code after OAuth authentication completes. The stored tokens are preserved and work correctly after restart.

Impact

  • Poor user experience: requires manual restart after every OAuth authentication
  • Contradicts documentation which states tokens work automatically
  • Makes iterative development/testing of OAuth-enabled MCP servers cumbersome
  • First-time users may think authentication failed when it actually succeeded

Related Issues

This issue is distinct from #9127 as it affects streamable-http (modern protocol), not deprecated SSE.

Additional Notes

  • The OAuth flow itself works perfectly (DCR succeeds, tokens are valid)
  • The token storage works correctly
  • The issue is specifically in the reconnection logic after initial authentication
  • Subsequent Claude Code sessions work fine (tokens persist across restarts)
  • The problem only occurs during the initial authentication session

Proposed Fix

After successful OAuth token storage, Claude Code should:

  1. Use the newly stored tokens to establish an MCP connection
  2. Load the MCP tools into the current session
  3. Avoid requiring a restart for a session state that should be hot-reloadable

Questions for Maintainers

  1. Is the "reconnection failed" + restart requirement intentional behavior?
  2. If so, why does the documentation not mention this?
  3. Is there a technical limitation preventing hot-reconnection after OAuth completes?
  4. Should the error message be clearer about whether restart is always required vs. optional?

Would you like me to test any additional scenarios or provide more debug information?

Activity

  1. added
    bug
    has repro
    platform:linux
    on Oct 24, 2025
  2. github-actions commented on Oct 24, 2025

    @github-actions

    Found 1 possible duplicate issue:

    1. [Bug] Jira Authentication Fails: Persistent Reconnection and Session Issues #9127

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  3. jhinrichsen commented on Oct 24, 2025

    @jhinrichsen
    Author

    #9127 is all about SSE, which is deprecated. The problem can be reproduced using streamable HTTP.

  4. naofumi-fujii commented on Nov 1, 2025

    @naofumi-fujii

    same issue with newrelic mcp

    $ claude --version
    2.0.31 (Claude Code)
    
    claude mcp add newrelic --transport http https://mcp.newrelic.com/mcp/
    
    Image
  5. pedromarcos11 commented on Nov 19, 2025

    @pedromarcos11

    Same here with supabase mcp

  6. mauricekleine commented on Dec 16, 2025

    @mauricekleine

    I have a custom MCP that uses Microsoft OAuth. Microsoft access tokens are valid for 60-75 minutes, so the MCP regularly enters an unauthenticated state. Refresh tokens are issued, but currently not used by Claude Code to automatically re-authenticate

  7. canarybrad commented on Dec 21, 2025

    @canarybrad

    I think I'm experiencing the same issue with the Notion mcp plugin. I've done additional investigation that suggests this is a Claude Code client-side issue, not a server-side problem.

    Environment

    • Claude Code version: 2.0.75
    • OS: macOS Darwin 25.1.0 (arm64)
    • Node version: v25.2.1
    • Plugin: Notion@claude-plugins-official v0.1.0

    Proof: The same OAuth tokens work perfectly via curl

    After Claude Code's OAuth flow completed (and failed with 401)

    Debug Log Evidence

    From ~/.claude/debug/latest:

    [DEBUG] MCP server "plugin:Notion:notion": Initializing HTTP transport to https://mcp.notion.com/mcp
    [DEBUG] MCP server "plugin:Notion:notion": HTTP transport options: {"url":"https://mcp.notion.com/mcp","headers":{"User-Agent":"claude-code/2.0.75"},"hasAuthProvider":true,"timeoutMs":60000}

    Tokens are successfully retrieved

    [DEBUG] MCP server "plugin:Notion:notion": Returning tokens
    [DEBUG] MCP server "plugin:Notion:notion": Token length: 86
    [DEBUG] MCP server "plugin:Notion:notion": Has refresh token: true
    [DEBUG] MCP server "plugin:Notion:notion": Expires in: 3594s

    Tokens are saved

    [DEBUG] MCP server "plugin:Notion:notion": Saving tokens
    [DEBUG] MCP server "plugin:Notion:notion": Token expires in: 3600
    [DEBUG] MCP server "plugin:Notion:notion": Has refresh token: true

    Then it fails

    [DEBUG] MCP server "plugin:Notion:notion": HTTP Connection failed after 1085ms: Streamable HTTP error: Server returned 401 after successful authentication
    [ERROR] MCP server "plugin:Notion:notion" Error: Streamable HTTP error: Server returned 401 after successful authentication
    [ERROR] MCP server "plugin:Notion:notion" Connection failed: Streamable HTTP error: Server returned 401 after successful authentication

    I extracted the tokens and tested manually:

    Initialize MCP session - works!

    curl -X POST https://mcp.notion.com/mcp
    -H "Authorization: Bearer $ACCESS_TOKEN"
    -H "Accept: application/json, text/event-stream"
    -d '{"jsonrpc":"2.0","id":1,"method":"initialize",...}'
    Returns: {"result":{"protocolVersion":"2024-11-05","serverInfo":{"name":"Notion MCP"}}}

    Call tools - works!

    curl -X POST https://mcp.notion.com/mcp
    -H "Authorization: Bearer $ACCESS_TOKEN"
    -H "Mcp-Session-Id: $SESSION_ID"
    -d '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"notion-search",...}}'
    Returns search results successfully

    This proves:

    • The OAuth tokens are valid
    • The Notion MCP server accepts them
    • Claude Code's MCP client fails to use them correctly after OAuth

    The bug looks to be specifically in how Claude Code reconnects to the MCP server after storing the OAuth tokens, not in the OAuth flow itself or the server.

  8. InsanePrototyper commented on Jan 14, 2026

    @InsanePrototyper

    Okay, I was able to figure out a workaround for the above error:
    do the following instead:
    claude mcp add <app> -- npx -y mcp-remote@latest <url>

  9. peregrinuscode commented on Jan 17, 2026

    @peregrinuscode

    i'm also getting this problem...

  10. dhpwd commented on Feb 5, 2026

    @dhpwd

    Additional data point: Slack's MCP server (mcp.slack.com/sse) returns a 302 redirect to a shard-specific host before establishing the SSE connection:

    GET https://mcp.slack.com/sse → 302 → https://mcp-9827.slack.com/sse
    

    This may be a contributing factor to the reconnection failure – the SSE/HTTP client may not be following the redirect or carrying the OAuth bearer token through to the target host.

    Tested with both --transport http and --transport sse using the new pre-configured OAuth credentials (--client-id / --client-secret) from v2.1.30. Both produce the same 'Authentication successful, but server reconnection failed' result.

  11. added
    stale
    on Feb 19, 2026
  12. alexey-sh commented on Feb 23, 2026

    @alexey-sh

    Might there be any possibility of having this resolved in the near future?

  13. jonathan-fileread commented on Feb 23, 2026

    @jonathan-fileread

    bump!

  14. removed
    stale
    on Feb 23, 2026
  15. mdthorpe-sc commented on Mar 17, 2026

    @mdthorpe-sc

    Please don't go stale. We need this fixed.

  16. jonathan-fileread commented on Mar 17, 2026

    @jonathan-fileread

    I spoke with NR. Here's what they said.

    Per this public document, New Relic AI Model Context Protocol (MCP) is in Preview status at this time, which means a user with Core or Full Platform user type that has the Billing User role, must have opted into the New Relic AI MCP Server preview of in the Previews & Trials UI (User menu -> Administration).

  17. localden commented on May 25, 2026

    @localden
    Collaborator

    Thanks for the report. We've made a number of improvements to authenticated MCP server stability since this was filed, including the post-OAuth reconnect path. Closing this out; if you're still seeing auth or reconnect failures on a current build, please open a new issue with your Claude Code version, the MCP server URL, and the exact error text shown so we can trace it.

  18. github-actions commented on Jul 21, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  19. locked as resolved and limited conversation to collaborators on Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:autharea:mcpbughas reproplatform:linux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions