Skip to content

Remote MCP OAuth: browser never opens for re-authentication after session loss #16893

Description

@Nicogabler

Bug Report

Version: 1.2.20 (also reproduced on 1.2.12)
OS: macOS

Description

When a remote MCP server using OAuth loses its saved state (e.g. after a restart where the token was not persisted), OpenCode fails to re-initiate the OAuth flow. The browser never opens and the MCP stays in a broken state permanently.

Steps to Reproduce

  1. Configure a remote MCP with OAuth (e.g. Atlassian: https://mcp.atlassian.com/v1/sse)
  2. Complete the OAuth flow successfully — MCP connects and tools are available
  3. Restart OpenCode (token is not persisted to ~/.local/share/opencode/mcp-auth.json)
  4. On next startup, observe that the browser does NOT open to re-authenticate

Expected Behavior

OpenCode should detect that the OAuth token is missing and automatically open the browser to re-authenticate, the same way it did on first setup.

Actual Behavior

  • mcp-auth.json only contains the client registration (clientId), no access/refresh tokens
  • The MCP panel shows: fehlgeschlagen — No OAuth state saved for MCP server: atlassian
  • The toggle in the MCP panel is non-interactive (cannot be clicked to trigger re-auth)
  • No browser window opens
  • Attempting to manually trigger the OAuth authorize URL returns a 500 Internal Server Error from https://mcp.atlassian.com/v1/authorize

Config

{
  "mcp": {
    "atlassian": {
      "type": "remote",
      "url": "https://mcp.atlassian.com/v1/sse",
      "oauth": {},
      "enabled": true
    }
  }
}

Additional Notes

The MCP worked fine in previous sessions. The issue only appears after a restart where the OAuth token was not persisted. The workaround is to use a personal API token via environment variables instead.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions