Skip to content

feat(settings): list and disconnect connected apps - #2273

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-oauth-connected-apps
Nov 10, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:feature/mcp-oauth-connected-apps

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

PR 6 of the MCP over OAuth plan (#2141). Based on main: it needs only #2261's data model, which is merged, and upstream/main is merged into this branch, so the diff is this PR alone. It also merges cleanly into current main (f947d77). It doesn't need the consent PR.

It adds screens 7 to 9 of the approved mockup. It is still behind MCP_OAUTH_ENABLED: while the flag is off, the list answers 404 and the card doesn't show, so Settings looks exactly as on main.

Settings › MCP & API Keys › Connected apps (web/src/components/settings/connected-apps-card.tsx)

  • A new card above the keys card. Each person sees only their own apps, as with API keys.
  • Each app shows:
    • a letter tile and its name;
    • Recognised or Not checked. Recognised means its code goes to claude.ai or chatgpt.com/platform.openai.com, and then it is named Claude or ChatGPT whatever it registered as;
    • Read and changes or Read only;
    • "via claude.ai", or "on this computer (127.0.0.1)" for a loopback app;
    • "Connected {date} · Last used {date}", or "Not used yet";
    • Disconnect.
  • A footnote says an app unused for 30 days is disconnected on its own.
  • Disconnect: a confirmation ("Disconnect Claude? Claude loses access to Ansvisor at once. To use it again, connect it again from Claude."), then the toast "Claude disconnected", and the list loads again.
  • No apps: "No connected apps. In Claude or ChatGPT, add https://app.ansvisor.com/api/mcp as a connector and sign in."
  • Plan note (owner, 2026-11-09):
    • In the free trial: "Signing in from an app needs a paid plan. In the free trial, use an API key below: it reads your data."
    • On an ended plan: "Your workspace's plan has ended. Connected apps work again once an admin chooses a plan."
    • An admin gets Choose a plan (Settings › Billing); a member is told to ask an admin.
  • While app sign-in is on, the MCP endpoint box says "Claude and ChatGPT: add this address as a connector and sign in. Other clients: create a key…", and the plan note adds "Signing in from an app needs a paid plan."
  • api-keys-section.tsx changes little: the keys card is kept in a constant, and the section returns it under Connected apps, so the rest of the file isn't re-indented.

API (web/src/lib/mcp-oauth/connected-apps.ts)

  • GET /api/oauth/connections returns the signed-in person's live connections (not revoked, used or made within the last 30 days; older ones have no live refresh token) and whether their plan lets connections work (oauthMcpAccess, from feat(mcp): accept OAuth access tokens at /api/mcp, behind MCP_OAUTH_ENABLED (00510) #2261), plus whether they are an admin. The answer is no-store. 401 when signed out, 404 while the flag is off.
  • DELETE /api/oauth/connections/[id] ends one of the person's own live connections and every token it has (revokeGrant(…, 'person')), and logs revoked_by_person. Someone else's connection, one already ended, or a malformed id gets 404.
  • The tables stay the server's (00510: RLS with no policy). The routes check the signed-in person, then read and write as the service role for that person.
  • web/src/lib/mcp-oauth/known-apps.ts is the recognised apps' list. It is identical to the file in the consent PR (feature/mcp-oauth-consent), so the two PRs merge cleanly in either order.
  • web/messages/en.json: settings.connectedApps.*, settings.apiKeys_mcpEndpointHintSignIn and settings.apiKeys_planNoteSignIn.
  • No migration and no dependency change.

Tests

  • web/src/app/api/oauth/connections/route.test.ts (6 tests): only the person's own live connections are listed; a known app is named by its host; trial and ended plans; 401 and 404; Disconnect revokes and logs; someone else's, a revoked one or a bad id is 404.
  • web/src/components/settings/connected-apps-card.test.tsx (5 tests): both kinds of app with their pills and wording; Disconnect behind the confirmation, with the DELETE, the toast and the list loaded again; the empty state with the trial note and Choose a plan; an ended plan for a member; nothing at all while the flag is off.
  • api-keys-section.test.tsx mocks @/i18n/navigation, which the card's Choose a plan link uses. Its tests are otherwise unchanged and pass.

No Help or docs change: nothing is switched on. Help and docs come with PR 7.

Related issue

Part of #2141

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd web && npx vitest run src/app/api/oauth/connections src/components/settings.
  2. With MCP_OAUTH_ENABLED=true and a connection in oauth_grants (from the consent PR, or inserted by hand), open Settings › MCP & API Keys: the Connected apps card lists it.
  3. Disconnect it: the app's next MCP call answers 401 and asks to connect again.
  4. With the flag off, the card is gone and the endpoint box reads as before.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — see help/README.md: nothing is switched on; Help comes with PR 7

Checks run:

  • yarn build passes (with CI's placeholder env).
  • Tests, after merging upstream/main: src/components/settings, the Settings page's tests, src/app/api/oauth, src/app/api/mcp, src/lib/mcp-oauth, src/lib/mcp, both mcp-auth tests, subscription-guard-coverage and embed-hints: 101 files, 949 tests passed.

Generated by Claude Code

PR 6 of MCP over OAuth (ansvisor#2141), stacked on feature/mcp-oauth-tokens
(ansvisor#2261): it needs only the data model. Still behind MCP_OAUTH_ENABLED:
while it is off the list answers 404 and the card doesn't show.

- Settings › MCP & API Keys gets a Connected apps card above the keys
  (the approved mockup's screens 7 to 9): each app the person connected
  by signing in, Recognised (claude.ai, chatgpt.com, by where its code
  goes) or Not checked, Read and changes or Read only, where it goes
  back to, when it was connected and last used, and Disconnect behind a
  confirmation. The empty state says how to connect; in the free trial
  or on an ended plan a note says why connections don't work, with
  Choose a plan for an admin. While app sign-in is on, the endpoint box
  says Claude and ChatGPT connect by signing in.
- GET /api/oauth/connections lists the signed-in person's own live
  connections (not revoked, used within 30 days) and their plan's
  access; DELETE /api/oauth/connections/[id] ends one of their own and
  every token it has, logged (revoked_by_person). Someone else's, or one
  already ended, is 404. The tables stay the server's (00510).
- known-apps.ts holds the recognised apps, identical to the consent
  page's (PR 4), so the two branches merge cleanly.

Part of ansvisor#2141.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@gkhngyk
gkhngyk merged commit dd437ef into ansvisor:main Nov 10, 2026
13 checks passed
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.

3 participants