Commit 6e5f685
authored
improvement(mcp): let users re-open OAuth authorization anytime (#5809)
* improvement(mcp): let users re-open OAuth authorization anytime
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.
* fix(mcp): guard OAuth start against double-click opening two popups
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.
* test(mcp): cover OAuth popup double-click guard and reopen-after-settle
* fix(mcp): kill prior popup poll before reopening so it can't clear the 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.
* fix(mcp): retire prior OAuth flow's pending entry on reopen, not just 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.
* fix(mcp): preserve prior OAuth flow until reopen's start succeeds
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.
* refactor(mcp): make OAuth connecting state deterministic via reference 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.1 parent da56246 commit 6e5f685
3 files changed
Lines changed: 301 additions & 74 deletions
File tree
- apps/sim
- app/workspace/[workspaceId]/settings/components/mcp
- hooks/mcp
Lines changed: 17 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
85 | 88 | | |
| 89 | + | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
| |||
121 | 125 | | |
122 | 126 | | |
123 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
124 | 136 | | |
125 | 137 | | |
126 | 138 | | |
| |||
450 | 462 | | |
451 | 463 | | |
452 | 464 | | |
453 | | - | |
454 | 465 | | |
455 | 466 | | |
456 | 467 | | |
457 | 468 | | |
458 | | - | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
459 | 472 | | |
460 | 473 | | |
461 | 474 | | |
| |||
660 | 673 | | |
661 | 674 | | |
662 | 675 | | |
| 676 | + | |
663 | 677 | | |
664 | 678 | | |
665 | 679 | | |
666 | 680 | | |
667 | 681 | | |
668 | 682 | | |
669 | 683 | | |
| 684 | + | |
670 | 685 | | |
671 | 686 | | |
672 | 687 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
0 commit comments