Skip to content

improvement(mcp): let users re-open OAuth authorization anytime#5809

Merged
waleedlatif1 merged 7 commits into
stagingfrom
fix/mcp-oauth-reconnect
Jul 21, 2026
Merged

improvement(mcp): let users re-open OAuth authorization anytime#5809
waleedlatif1 merged 7 commits into
stagingfrom
fix/mcp-oauth-reconnect

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A server stuck on "OAuth Authorization required" had no discoverable way to re-open the auth popup once it was closed/abandoned. The connect button lived only in the server detail view and hard-disabled while "Connecting…" — a state cleared by polling popup.closed, which is unreliable under COOP (Gauge and many auth pages set it), so it could stay locked until the 10-minute safety timeout.
  • List row: add an "Authorize" / "Reopen authorization" action to the menu for unconnected OAuth servers, so re-auth is reachable without drilling into Details.
  • Detail view: the button is now always clickable (reopens a fresh popup — the hook already drops the prior in-flight flow safely) instead of locking on an unverifiable "Connecting…" state; label reads "Reopen authorization window" while a flow is pending.
  • Matches how Cursor/Claude/VS Code treat re-auth: an idempotent, always-available action, never a lockout.

Type of Change

  • Improvement (UX)

Testing

Type-checks and biome clean. Manual: an OAuth server that needs auth now offers Authorize/Reopen from both the list menu and the detail button, and re-clicking after closing the popup opens a fresh window.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

A server stuck on 'OAuth Authorization required' had no discoverable way to
re-trigger the auth popup once it was closed or abandoned: the connect button
lived only in the server detail view and hard-disabled while 'Connecting…',
a state cleared by polling popup.closed (unreliable under COOP), so it could
stay locked until the 10-minute safety timeout.

- Add an 'Authorize'/'Reopen authorization' action to the server list row menu
  for unconnected OAuth servers, so re-auth is reachable without drilling in.
- Make the detail-view button always clickable (reopens a fresh popup) instead
  of locking on an unverifiable 'Connecting…' state.
@cursor

cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Workspace MCP settings UX and client-side OAuth popup state only; no auth backend or token handling changes.

Overview
Makes MCP OAuth re-authorization reachable and repeatable when a popup was closed or abandoned, instead of hiding the action in details only or locking the UI on an unreliable “Connecting…” state.

Settings UI: Unconnected OAuth servers get Authorize / Reopen authorization in the list row menu (managers only). The detail Connect with OAuth chip stays enabled while a flow is pending and shows Reopen authorization window when connecting.

useMcpOauthPopup: Drops popup.closed polling (unreliable under COOP). Uses per-server reference counting for connecting state, a concurrent-start guard on /oauth/start, and retires superseded flows only after a successful new start; failed reopens leave an in-flight flow’s connecting state intact. already_authorized still invalidates server queries.

Adds Vitest coverage for double-start prevention, reopen-after-settle, query invalidation, and failed-reopen with a live prior flow.

Reviewed by Cursor Bugbot for commit 778a534. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes MCP OAuth authorization available again after a popup is closed or abandoned. The main changes are:

  • Adds Authorize and Reopen authorization actions to eligible server-row menus.
  • Keeps the detail-view authorization button clickable during a pending flow.
  • Tracks concurrent authorization attempts with per-server reference counts.
  • Adds tests for concurrent starts, reopened flows, cache invalidation, and failed replacement attempts.

Confidence Score: 5/5

This looks safe to merge.

  • Each authorization attempt has a balanced start and settlement path.
  • A failed replacement keeps the earlier live flow active.
  • Successful replacement flows retire stale state before tracking the new callback.
  • No blocking issue remains in the changed code.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/settings/components/mcp/mcp.tsx Adds list authorization actions and keeps the detail authorization action available while a flow is pending.
apps/sim/hooks/mcp/use-mcp-oauth-popup.ts Uses per-server reference counts to coordinate pending, replaced, failed, completed, and timed-out OAuth attempts.
apps/sim/hooks/mcp/use-mcp-oauth-popup.test.tsx Adds focused coverage for concurrent starts, reopening, cache invalidation, and replacement failure.

Reviews (5): Last reviewed commit: "refactor(mcp): make OAuth connecting sta..." | Re-trigger Greptile

Now that the connect button stays clickable, block re-entry while the
/oauth/start request is in flight; cleared once it settles so a later reopen
still starts a fresh flow.
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 21, 2026 8:02pm

Request Review

…e new flow

Addresses a stale-poll race: an abandoned attempt's popup.closed interval could
fire mid-reopen and clear 'Connecting…' for the fresh flow.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c261cf5. Configure here.

Comment thread apps/sim/hooks/mcp/use-mcp-oauth-popup.ts Outdated
… its poll

Drop the previous attempt's pending-flow map entry and safety timeout up front
too, so a late BroadcastChannel result (settleFlow) can't clear the reopened
flow's connecting state during the new /oauth/start await.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/hooks/mcp/use-mcp-oauth-popup.ts Outdated
Comment thread apps/sim/hooks/mcp/use-mcp-oauth-popup.ts Outdated
Reworks reopen concurrency so a superseded or failed reopen can't lose a real
authorization:
- Retire the prior flow only after the replacement /oauth/start succeeds; a
  failed reopen keeps it so its popup can still complete and be honored.
- Guard the connecting-clear (settleFlow + popup poll) behind the in-flight
  start set, so a stale settle can't flicker the reopened flow's label.
- Invalidate server queries on already_authorized so the UI reflects a server
  that authorized out from under the client.
Adds a test for the already_authorized invalidation.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/hooks/mcp/use-mcp-oauth-popup.ts Outdated
Comment thread apps/sim/hooks/mcp/use-mcp-oauth-popup.ts Outdated
Comment thread apps/sim/hooks/mcp/use-mcp-oauth-popup.ts
Comment thread apps/sim/hooks/mcp/use-mcp-oauth-popup.ts Outdated
…e counting

Replaces the scattered, race-prone stopConnecting/set-based tracking with a
per-server attempt count: each start increments once and clears exactly once
(fail, already_authorized, settle, or supersede), so the 'Connecting…' /
'Reopen authorization' label can never get stuck or flicker across concurrent
reopens. Retire prior flows whenever a replacement start succeeds (including
already_authorized); a failed reopen keeps the prior flow so it can still
complete. Drops the unreliable popup.closed poll entirely — the label already
invites reopening and the safety timeout guarantees clearing. Adds a test for
the failed-reopen-preserves-prior-flow case.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 778a534. Configure here.

@waleedlatif1
waleedlatif1 merged commit 6e5f685 into staging Jul 21, 2026
20 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/mcp-oauth-reconnect branch July 21, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant