Skip to content

Offer Clear OAuth for a server with stored credentials, connected or not (#3099) - #3100

Merged
cliffhall merged 7 commits into
v2/mainfrom
v2/feat/3099-clear-oauth-disconnected
Nov 30, 2026
Merged

cliffhall merged 7 commits into
v2/mainfrom
v2/feat/3099-clear-oauth-disconnected

Conversation

@cliffhall

@cliffhall cliffhall commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Closes #3099

What changed

The header's Clear OAuth icon (#3065, PR #3091) only exists while you're connected. Now every server card has a Clear OAuth button whenever that server has stored OAuth credentials, whether it is connected or not. The server list also gets a selection, and while disconnected, the header offers Clear OAuth for the selected server.

  • Where it lives. It goes on the server's card, beside Connection Info and Settings, in both states. While connected, the header icon from Faster way to clear a server's OAuth state (without digging into Settings → Authorization) #3065 is unchanged.
  • Selection. Clicking a card selects it and gives it a blue selected border (new Card theme variant and --inspector-selected-border token). That includes a click on one of the card's buttons, so the server you last acted on is the selected one. Connecting selects that server too, so it stays selected after you disconnect. Removing it from the catalog clears the selection.
  • Header while disconnected. ViewHeader's disconnected variant takes clearSelectedOAuth: { serverName, onClear }. When the selected server has stored credentials, the header shows the Clear OAuth icon and the same confirmation, worded for a clear that ends no session. The name travels with the handler, so the prompt can't name one server while clearing another.
  • When it shows. It shows when the server has a stored access token, the same test the header applies. useStoredOAuthServerIds reads the shared web OAuth store directly, keyed by the same URL the clear deletes from, because an idle server has no live client to ask. The live session is looked up at its client's URL (oauthLookupTargets), because an entry edited while connected still authorizes, and is cleared, at the old URL. The store has no change event, so the hook re-reads whenever a clear settles or the session changes. stdio servers never show the button.
  • What it does. Clicking it opens the existing ClearOAuthConfirmModal, then runs the same runClear path: per-server in-flight guard, revoke-on-clear, error toast and success toast. A connected server is disconnected, exactly as with Clear a server's OAuth state from a header icon (#3065) #3091. A disconnected server just has its stored state removed. The modal takes two new props. disconnects means the prompt only mentions disconnecting when that will actually happen. revokes, read from the server's oauth.revokeOnClear (the same setting the clear uses), means the prompt says whether the grant will also be revoked at the authorization server. Without that, "will be removed" alone read as a local delete that leaves the grant live. That includes the case of a different entry that shares the session's URL (Clearing OAuth for one catalog entry silently kills another entry that shares its URL #2217).
  • Read-only sessions keep it. Credentials are runtime state, not catalog data, so it isn't hidden with Edit/Remove, matching Connection Info.

A fix the disconnected path depended on

After a disconnect, activeServerId is cleared but the InspectorClient stays around until the next connect. resolveOAuthClearIdentity read that client's URL as if it belonged to a live session. So a clear after disconnecting was treated as a shared-key clear. It was routed through the dead client and toasted "The active session authorizes against the same URL, so its stored tokens went too". The Settings → Authorization clear already had this bug, and the new button would have shown it on every use. It now counts a session as live only while activeServerId is set.

  • Docs: docs/mcp-server-configuration.md now mentions the card button.

Tests

  • useStoredOAuthServerIds.test.tsx covers:
    • reports only servers with a stored access token, and skips stdio servers
    • re-reads on a revision bump, but not for a new array of the same servers
    • offers nothing when the store is unreadable
    • drops an out-of-order read, whether it succeeded or failed
  • ServerCard.test.tsx covers: no button without a handler, the button on a disconnected or connected server, and the button kept in a read-only session.
  • ServerCard.test.tsx (selection) covers: the selected border, the highlight border winning over it, and selecting on a click anywhere on the card or on one of its buttons.
  • ServerListScreen.test.tsx: only the listed ids get the button, only the selected card is marked, and a card click selects its server.
  • ViewHeader.test.tsx (disconnected) covers: no icon with nothing selected, confirm-then-clear with no disconnect wording, and an open prompt dropped when the selection stops offering a clear.
  • oauthClearKey.test.ts: oauthLookupTargets uses the client's config for the live session only.
  • ClearOAuthConfirmModal.test.tsx: the disconnect wording by default, and the stored-state-only wording with disconnects={false}.
  • oauthClearKey.test.ts: a client whose session has ended is not an active session.
  • App.test.tsx: the Open the monitoring sidebar to the Network panel when a connection fails during OAuth #2108 storage-failure test now rejects every load(), not just the first. The server list's own mount-time read was using up the one-shot rejection before the callback ran.
  • New stories: ServerCard/DisconnectedWithStoredOAuth (selected), ViewHeader/UnconnectedWithSelectedOAuth, ClearOAuthConfirmModal/OpenWhileDisconnected.
  • npm run local:gate passes.

Screenshots (1280×900, Chromium)

Taken against oauth-revocation-http.json with an isolated HOME. Before authorizing, neither card had the button.

Connected, after authorizing. The card has Clear OAuth, and so does the header:

server-card-clear-oauth-connected

Disconnected, with tokens still stored, after a page reload and a click on the card to select it. The card has the blue selected border and its Clear OAuth button, and the header shows the Clear OAuth icon. The stdio card has neither:

server-card-clear-oauth-disconnected

Clicking the header icon. The confirmation for a disconnected server doesn't mention disconnecting, and it says the grant will be revoked at the authorization server. With oauth.revokeOnClear off, it would instead say that tokens already issued stay valid until they expire:

server-card-clear-oauth-confirm

After confirming, the stored state is gone, both controls disappear and the toast is correct:

server-card-clear-oauth-cleared

🤖 Generated with Claude Code

The header's Clear OAuth (#3065) only exists while connected. Each server
card now offers Clear OAuth whenever that server has a stored access token,
connected or not: confirmed first, then the same runClear path. A
disconnected server's state is removed with nothing to disconnect.

Also stops resolveOAuthClearIdentity treating the kept-after-disconnect
client as a live session, which routed a post-disconnect clear through the
dead client and toasted that an active session lost its tokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Nov 30, 2026
@cliffhall
cliffhall requested a balanced review from Copilot November 30, 2026 16:22

Copilot AI 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.

🟡 Changes recommended

The OAuth credential lookup uses the edited URL while clearing still targets the connected URL, so Clear OAuth can be hidden or offered for credentials it will not clear.

1 open issue
What changed in this PR

Adds Clear OAuth to web server cards so stored credentials can be cleared without connecting first, addressing #3099 through the existing confirmation and clear flow.

Changes:

  • Reads stored credentials to show card actions for eligible servers, including read-only sessions.
  • Adjusts confirmation wording for disconnected servers and stops treating retained clients as live sessions after disconnect.
  • Adds focused tests, stories, and documentation for the new behavior.
File Description
docs/​mcp-server-configuration.md Documents card and header clear actions.
clients/​web/​src/​utils/​oauthClearKey.ts Excludes ended sessions from active-key resolution.
clients/​web/​src/​utils/​oauthClearKey.test.ts Covers retained clients after disconnect.
clients/​web/​src/​hooks/​useStoredOAuthServerIds.ts Reads stored credentials for card eligibility.
clients/​web/​src/​hooks/​useStoredOAuthServerIds.test.tsx Covers filtering, refreshes, errors, and stale reads.
clients/​web/​src/​components/​views/​InspectorView/​types.ts Adds card-clear data and callback props.
clients/​web/​src/​components/​views/​InspectorView/​InspectorView.tsx Passes clear controls to the server list.
clients/​web/​src/​components/​screens/​ServerListScreen/​ServerListScreen.tsx Offers clearing only on eligible cards.
clients/​web/​src/​components/​screens/​ServerListScreen/​ServerListScreen.test.tsx Tests per-server action eligibility.
clients/​web/​src/​components/​groups/​ServerCard/​ServerCard.tsx Adds the Clear OAuth button.
clients/​web/​src/​components/​groups/​ServerCard/​ServerCard.test.tsx Covers connected, disconnected, and read-only cards.
clients/​web/​src/​components/​groups/​ServerCard/​ServerCard.stories.tsx Adds a disconnected OAuth card story.
clients/​web/​src/​components/​groups/​ClearOAuthConfirmModal/​ClearOAuthConfirmModal.tsx Makes disconnect wording conditional.
clients/​web/​src/​components/​groups/​ClearOAuthConfirmModal/​ClearOAuthConfirmModal.test.tsx Tests both confirmation variants.
clients/​web/​src/​components/​groups/​ClearOAuthConfirmModal/​ClearOAuthConfirmModal.stories.tsx Adds a disconnected confirmation story.
clients/​web/​src/​App.tsx Wires credential refreshes, confirmation, and clearing.
clients/​web/​src/​App.test.tsx Keeps storage-failure mocking consistent across reads.

Review effort: Balanced

Comment thread clients/web/src/App.tsx Resolved
cliffhall and others added 2 commits November 30, 2026 11:29
A connected entry edited from X to Y still authorizes, and is cleared, at X.
The card read Y, so it could hide Clear OAuth when only X held tokens or offer
it on tokens the clear would not touch. oauthLookupTargets swaps in the
client's config for the active entry, under the same live-session rule as
resolveOAuthClearIdentity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Clicking a card selects it (blue border); connecting selects that server too,
so it stays selected after a disconnect. While disconnected, the header shows
Clear OAuth for the selected server when it has stored credentials, with the
same confirmation, worded for a clear that ends no session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall cliffhall changed the title Offer Clear OAuth on a server's card, connected or not (#3099) Offer Clear OAuth for a server with stored credentials, connected or not (#3099) Nov 30, 2026
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: one finding, fixed.

  • Use live transport config when looking up active OAuth credentials — fixed in 64ba9fa (oauthLookupTargets), replied inline.

Also pushed since round 1 (1524095): card selection, and the header's Clear OAuth for the selected server while disconnected, as requested by the maintainer. The PR body is updated.

Copilot AI 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.

🟡 Changes recommended

OAuth clearing can silently do nothing, miss stored credentials, or change targets after connection/configuration transitions, alongside inaccessible keyboard selection and a hook test read/render loop.

5 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Inline storage object causes repeated reads and rerenders

clients/​web/​src/​hooks/​useStoredOAuthServerIds.test.tsx:134

The inline { getTokens } creates a new storage object on every hook render. Each successful read publishes a fresh ["a"] array, which rerenders the hook and changes its storage dependency, causing another read while the test remains mounted. Hoist the storage object outside the render callback so this test exercises the intended reads rather than a read/render loop.

Review effort: Balanced

Comment thread clients/web/src/App.tsx Resolved
Comment thread clients/web/src/utils/oauthClearKey.ts Resolved
cliffhall and others added 3 commits November 30, 2026 11:58
- Make the server name a button (aria-pressed) so a card can be selected
  from the keyboard without touching its connection toggle.
- Drop an open header Clear OAuth prompt when the connection state flips,
  so a connected prompt never turns into a clear of a different URL.
- Keep an entry edited to stdio on its own config in oauthLookupTargets,
  so the card is never offered a clear that would do nothing.
- Hoist the storage object in the stale-read hook tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
"Will be removed" alone read as a local delete that leaves the grant live.
The prompt now says the grant is revoked at the authorization server (where
it supports revocation), or, with oauth.revokeOnClear off, that tokens
already issued stay valid until they expire. Read from the same setting the
clear uses, for the card, and for the header connected or not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall
cliffhall requested a balanced review from Copilot November 30, 2026 17:06
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 2: five findings, four fixed, one declined.

  • Failed connect → edit → clear identity — declined as out of scope (an edge case of the existing clear-identity rule, which the Settings clear shares); replied inline.
  • Keyboard-inaccessible selection — fixed in 5c0036a: the server name is a button with aria-pressed.
  • Connected prompt survives disconnect — fixed in 5c0036a: the prompt is dropped when the connection state flips.
  • HTTP→stdio edit offers a no-op clear — fixed in 5c0036a.
  • Suppressed: read/render loop in a hook test — fixed in 5c0036a by hoisting the storage object.

Also since round 2, at the maintainer's request (8846ab0, 23b5d2b): the confirmation now says whether the grant will be revoked at the authorization server (per oauth.revokeOnClear), instead of only that the tokens are removed.

Copilot AI 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.

🟡 Changes recommended

An open confirmation can delete or revoke the wrong server’s credentials after disconnection, and long server names can overflow adjacent controls when selection is enabled.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

High severity Dismiss credential confirmation when the active session changes

clients/​web/​src/​App.tsx:1673

If a connected entry is edited from URL X to Y, with credentials at both URLs, the card's confirmation initially targets the live client's X. A disconnect while the prompt is open leaves the entry clearable, but confirming now deletes or revokes Y's credentials instead. Dismiss the card confirmation when the active session changes, and add a regression test for disconnecting while the target remains clearable.

5 resolved since last review

Review effort: Balanced

- Let the server-name select button shrink (miw 0), so a long name still
  truncates instead of overrunning the status and connect controls.
- Drop an open card Clear OAuth confirmation when the active session
  changes, so a prompt opened while connected cannot confirm a clear of a
  different URL after a disconnect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 3: two findings, both fixed in e0d3774.

  • Long names overflow with selection enabled — the select button gets miw={0}; replied inline.
  • Previously missed: card confirmation survives a session change — the card's pending Clear OAuth target is now dropped whenever the active session changes (same useValueChange on activeServerId that selects the connected server), so a prompt opened while connected can't confirm a clear of a different URL after a disconnect. No unit test: this wiring lives in App.tsx, the composition root outside the coverage whitelist; useValueChange itself is tested.

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because a failed OAuth clear can leave credentials stored while hiding retry controls, and App-level tests do not cover the new flow.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 4: no open issues — review loop closed on a clean round.

On the headline's two notes for human assessment:

  • A failed clear leaving credentials stored while hiding the controls — every settled clear (success or failure) re-reads the store, so a server whose credentials survived keeps its button. The button only goes when the store itself is unreadable, which is the hook's deliberate choice (never offer a clear for credentials it can't confirm exist); that failure surfaces as the clear's own error toast, which doesn't auto-close.
  • No App-level tests — App.tsx is the composition root outside the coverage whitelist; the new behavior lives in tested units (useStoredOAuthServerIds, oauthLookupTargets, ServerCard, ServerListScreen, ViewHeader, ClearOAuthConfirmModal) and was verified end to end in the browser (screenshots above).

@cliffhall
cliffhall merged commit 35d23d2 into v2/main Nov 30, 2026
12 checks passed
@cliffhall
cliffhall deleted the v2/feat/3099-clear-oauth-disconnected branch November 30, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show Clear OAuth for the selected server when it has stored credentials, even if it is not connected

2 participants