Skip to content

MCP OAuth authentication UX issues: stale token not auto-refreshed, silent errors, foreground login timeout #3819

Description

@bevis-wong

Description

Summary

After configuring an OAuth-protected HTTP MCP server (Nordic MCP at https://aidev.nordicsemi.com/mcp) in mcp.json, the following chain of issues made authentication far more difficult than it should be.

Steps to reproduce

  1. Added nordic-mcp to mcp.json (HTTP type, no explicit auth fields)
  2. Restarted CodeWhale — list_mcp_resources returned empty []
  3. tool_search for nordic returned zero deferred tools
  4. Had to manually grep ~/.codewhale/logs/ to discover: 401 Unauthorized, bearer token expired
  5. codewhale mcp list showed auth=not-logged-in
  6. codewhale mcp connect nordic-mcp failed with 401 and exited — no hint to use login
  7. Foreground codewhale mcp login nordic-mcp generated the authorization URL but was killed by exec_shell's 30-second timeout while waiting for the browser callback
  8. Finally ran mcp login in background mode; user completed OAuth in the browser; credentials were stored successfully

Root issues

# Issue Detail
1 Stale token not auto-refreshed CodeWhale caches an expired bearer token, gets 401, and silently fails instead of clearing it and re-initiating OAuth
2 Auth errors silently swallowed list_mcp_resources returns an empty array with no indication that authentication is required; user must dig through logs
3 mcp connect doesn't trigger OAuth mcp connect receives 401 and exits immediately without suggesting mcp login
4 mcp login times out in foreground OAuth requires manual browser interaction, so foreground execution is guaranteed to hit the timeout; no progress indicator or background-mode guidance
5 mcp list shows auth=not-logged-in but doesn't auto-recover The client is aware of the unauthenticated state but takes no action

Expected behavior

  • On receiving 401, automatically clear the stale token and (in TUI) prompt the user to complete OAuth login
  • list_mcp_resources / list_mcp_resource_templates should return a human-readable error (e.g., {"error": "authentication_required", "server": "nordic-mcp"}) instead of an empty array when authentication fails
  • mcp connect should print a helpful message on 401: "This server requires OAuth authentication. Run codewhale mcp login <name>"
  • mcp login should print a clear status line after starting the local callback server ("Waiting for browser authorization…") and warn on prolonged inactivity rather than crashing

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreliabilityReliability, flaky behavior, retries, fallbacks, and robustnesstoolsTool execution, tool schemas, tool UX, and built-in tool behaviorv0.8.66Targeting v0.8.66

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions