Skip to content

fix(mcp): authenticate on toggle in TUI MCP picker#27704

Open
msvechla wants to merge 1 commit into
anomalyco:devfrom
msvechla:fix/mcp-tui-auto-authenticate-on-toggle
Open

fix(mcp): authenticate on toggle in TUI MCP picker#27704
msvechla wants to merge 1 commit into
anomalyco:devfrom
msvechla:fix/mcp-tui-auto-authenticate-on-toggle

Conversation

@msvechla
Copy link
Copy Markdown
Contributor

@msvechla msvechla commented May 15, 2026

Issue for this PR

Closes #16893

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Pressing space on a needs_auth MCP in the picker (/mcps) now runs the full OAuth flow instead of looping mcp.connect(). Previously, toggling a needs_auth row called mcp.connect(), which immediately re-failed with UnauthorizedError, kept the row at needs_auth, and emitted a "Run: opencode mcp auth " toast. There was no in-TUI path that actually completed OAuth.

This now calls mcp.auth.authenticate, which already exists server-side: opens the browser, awaits the callback, exchanges the code, and rebuilds the transport.

A second loading kind (authenticating) is rendered in the row footer while the long-blocking call sits open.

The startup toast for needs_auth MCPs is also updated to point at /mcps first and the shell command second.

Related: #21702 (broader, not addressed here).

How did you verify your code works?

  • bun run typecheck clean (passes pre-push hook).
  • Cleared tokens for a Keycloak-backed MCP, opened /mcps, pressed space. Browser opened, OAuth completed, row transitioned to connected. Repeated on a second MCP.
  • Confirmed the original symptom (space did nothing useful) reproduces on dev before applying the patch.

Screenshots / recordings

None — terminal-only keybinding-behavior change; reproduce locally.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Two related changes that make the in-TUI MCP picker actually usable when
an MCP needs OAuth:

1. dialog-mcp.tsx: when the user toggles a 'needs_auth' MCP via the
   picker (space), call mcp.auth.authenticate instead of mcp.connect.
   Previously, toggle re-ran connect, which re-failed with
   UnauthorizedError, set the row back to needs_auth, and emitted a
   toast pointing at the shell. There was no in-TUI path that actually
   completed OAuth. This now opens the browser, awaits the callback,
   exchanges the code, and rebuilds the transport. A second loading
   kind ('authenticating') is rendered in the row footer while the
   long-blocking call sits open.

2. mcp/index.ts: update the startup 'requires authentication' toast to
   mention /mcps first, and the shell command as a fallback. Now that
   the in-TUI flow works, users in a running TUI can recover without
   dropping to a shell.

Related: anomalyco#16893, anomalyco#21702.
@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels May 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant