Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(profile-ui): show and revoke mcp-server OAuth grants in connected accounts

Diego Zacarias9717b3867de9
diff --git a/profile-ui/app/components/__tests__/ConnectedAccounts.test.tsx b/profile-ui/app/components/__tests__/ConnectedAccounts.test.tsx
new file mode 100644
index 000000000..2e9babeb8
--- /dev/null
+++ b/profile-ui/app/components/__tests__/ConnectedAccounts.test.tsx
@@ -0,0 +1,132 @@
+import React from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import '@testing-library/jest-dom/vitest'
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import Page from '../../connected-accounts/page'
+
+const api = vi.hoisted(() => ({
+ apiGet: vi.fn(),
+ apiSend: vi.fn(),
+}))
+
+const toast = vi.hoisted(() => ({ showToast: vi.fn() }))
+
+// Real listConnectedAccounts/revokeConnectedAccount run against these mocks; the
+// wire shape below is the frozen GrantView contract the backend emits.
+vi.mock('@lib/api', () => ({
+ apiGet: api.apiGet,
+ apiSend: api.apiSend,
+ isSilentApiError: () => false,
+}))
+
+vi.mock('@components/AuthGate', () => ({
+ AuthGate: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+}))
+
+vi.mock('@components/ProfileShell', () => ({
+ ProfileShell: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+}))
+
+vi.mock('@components/Toast', () => ({
+ useToast: () => toast,
+}))
+
+const recipeGrant = {
+ ownerKind: 'recipe',
+ recipeNamespace: 'team-ns',
+ recipeName: 'calendar-plugin',
+ oauthClientId: 'google',
+ provider: 'google',
+ background: true,
+ updatedAt: '2026-09-20T00:00:00.000Z',
+}
+
+// mcp-server grant on the remote lane. Name deliberately free of the substring
+// "remote" so the assertion proves the raw provider token is hidden, not masked
+// by the server name.
+const remoteMcpServerGrant = {
+ ownerKind: 'mcpserver',
+ recipeNamespace: 'servers-ns',
+ recipeName: 'acme-crm',
+ mcpServerName: 'acme-crm',
+ oauthClientId: 'https://acme.example.com/oauth/callback',
+ provider: 'remote',
+ background: false,
+ updatedAt: '2026-09-20T00:00:00.000Z',
+}
+
+beforeEach(() => {
+ api.apiGet.mockReset()
+ api.apiSend.mockReset()
+ toast.showToast.mockReset()
+})
+
+afterEach(cleanup)
+
+describe('Connected accounts — mixed owner rendering', () => {
+ it('renders recipe and mcp-server grants with an owner-kind type label', async () => {
+ api.apiGet.mockResolvedValue({ grants: [recipeGrant, remoteMcpServerGrant] })
+
+ render(<Page />)
+
+ expect(await screen.findByText('calendar-plugin')).toBeInTheDocument()
+ expect(screen.getByText('acme-crm')).toBeInTheDocument()
+
+ // Owner-kind labels are derived from ownerKind, never from the name.
+ expect(screen.getByText(/Plugin/)).toBeInTheDocument()
+ expect(screen.getByText(/MCP server/)).toBeInTheDocument()
+ // Recipe provider still shows.
+ expect(screen.getByText(/google/)).toBeInTheDocument()
+ })
+
+ it('hides the raw remote provider token for the mcp-server grant', async () => {
+ api.apiGet.mockResolvedValue({ grants: [remoteMcpServerGrant] })
+
+ render(<Page />)
+
+ await screen.findByText('acme-crm')
+ // The synthetic 'remote' provider token must never surface in the UI.
+ expect(document.body.textContent).not.toMatch(/remote/i)
+ })
+
+ it('shows a baked mcp-server provider instead of the type label alone', async () => {
+ api.apiGet.mockResolvedValue({
+ grants: [{ ...remoteMcpServerGrant, provider: 'clickup' }],
+ })
+
+ render(<Page />)
+
+ await screen.findByText('acme-crm')
+ expect(screen.getByText(/clickup/)).toBeInTheDocument()
+ })
+
+ it('revokes an mcp-server grant through its owner-kind lane and drops it from the list', async () => {
+ api.apiGet
+ .mockResolvedValueOnce({ grants: [recipeGrant, remoteMcpServerGrant] })
+ .mockResolvedValue({ grants: [recipeGrant] })
+ api.apiSend.mockResolvedValue(null)
+
+ render(<Page />)
+
+ await screen.findByText('acme-crm')
+
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for acme-crm' }))
+ const menu = await screen.findByRole('menu')
+ fireEvent.click(within(menu).getByRole('menuitem', { name: 'Revoke' }))
+
+ await waitFor(() => expect(api.apiSend).toHaveBeenCalledTimes(1))
+ const [method, path, body, query] = api.apiSend.mock.calls[0]
+ expect(method).toBe('DELETE')
+ expect(path).toBe(
+ `/api/v1/oauth/grants/servers-ns/acme-crm/${encodeURIComponent(
+ 'https://acme.example.com/oauth/callback'
+ )}`
+ )
+ expect(body).toBeUndefined()
+ expect(query).toEqual({ ownerKind: 'mcpserver' })
+
+ // Observable result (T4): the revoked grant is gone from the rendered list.
+ await waitFor(() => expect(screen.queryByText('acme-crm')).not.toBeInTheDocument())
+ expect(screen.getByText('calendar-plugin')).toBeInTheDocument()
+ })
+})
diff --git a/profile-ui/app/connected-accounts/page.tsx b/profile-ui/app/connected-accounts/page.tsx
index c1589391a..4d5fe516d 100644
--- a/profile-ui/app/connected-accounts/page.tsx
+++ b/profile-ui/app/connected-accounts/page.tsx
@@ -10,6 +10,9 @@ import { useToast } from '@components/Toast'
import { isSilentApiError } from '@lib/api'
import {
type ConnectedAccount,
+ connectedAccountKey,
+ connectedAccountName,
+ describeGrantSource,
listConnectedAccounts,
revokeConnectedAccount,
} from '@lib/connectedAccounts'
@@ -37,7 +40,7 @@ function ConnectedAccountsContent() {
}, [])
async function revoke(a: ConnectedAccount) {
- const key = `${a.recipeName}/${a.oauthClientId}`
+ const key = connectedAccountKey(a)
setBusy(key)
try {
await revokeConnectedAccount(a)
@@ -84,21 +87,24 @@ function ConnectedAccountsContent() {
) : (
<RecordList className="stack">
{accounts.map(a => {
- const key = `${a.recipeName}/${a.oauthClientId}`
+ const key = connectedAccountKey(a)
+ const name = connectedAccountName(a)
+ const { typeLabel, detail } = describeGrantSource(a)
return (
<RecordListRow key={key} className="member-row">
<div className="member-summary">
<div>
<div>
- <strong>{a.recipeName}</strong>
+ <strong>{name}</strong>
</div>
<div className="small muted">
- {a.provider}
+ {typeLabel}
+ {detail ? ` · ${detail}` : ''}
{a.background ? ' · background access' : ''}
</div>
</div>
<RowActionMenu
- ariaLabel={`Actions for ${a.recipeName}`}
+ ariaLabel={`Actions for ${name}`}
actions={[
{
key: 'revoke',
diff --git a/profile-ui/lib/connectedAccounts.ts b/profile-ui/lib/connectedAccounts.ts
index 5d90a8160..1465031f4 100644
--- a/profile-ui/lib/connectedAccounts.ts
+++ b/profile-ui/lib/connectedAccounts.ts
@@ -1,22 +1,65 @@
import { apiGet, apiSend } from './api'
+export type OAuthOwnerKind = 'recipe' | 'mcpserver'
+
export interface ConnectedAccount {
+ ownerKind: OAuthOwnerKind
recipeNamespace: string
recipeName: string
oauthClientId: string
provider: string
background: boolean
updatedAt: string
+ // Present only when ownerKind === 'mcpserver'; equals recipeName.
+ mcpServerName?: string
+}
+
+export interface GrantSource {
+ // Owner-kind label, never inferred from the resource name.
+ typeLabel: string
+ // Provider detail to show as the row subtitle, or null when the provider is a
+ // raw remote-lane token that would be meaningless to the user (the server
+ // name already identifies the grant).
+ detail: string | null
+}
+
+// mcp-server grants on the remote/generic lane carry a synthetic provider token
+// (see fase-7.2 DEC-R2 §2). It is not a recognizable third-party account name,
+// so it must not surface raw in the UI.
+const RAW_MCP_SERVER_PROVIDERS = new Set(['remote', 'generic'])
+
+export function connectedAccountKey(a: ConnectedAccount): string {
+ return `${a.ownerKind}/${a.recipeNamespace}/${a.recipeName}/${a.oauthClientId}`
+}
+
+export function connectedAccountName(a: ConnectedAccount): string {
+ return a.mcpServerName ?? a.recipeName
+}
+
+export function describeGrantSource(a: ConnectedAccount): GrantSource {
+ if (a.ownerKind === 'mcpserver') {
+ const showsRawProvider = RAW_MCP_SERVER_PROVIDERS.has(a.provider)
+ return { typeLabel: 'MCP server', detail: showsRawProvider ? null : a.provider }
+ }
+ return { typeLabel: 'Plugin', detail: a.provider }
}
export async function listConnectedAccounts(): Promise<ConnectedAccount[]> {
- const res = (await apiGet('/api/v1/oauth/grants')) as { grants: ConnectedAccount[] }
- return Array.isArray(res.grants) ? res.grants : []
+ const res = (await apiGet('/api/v1/oauth/grants')) as { grants?: ConnectedAccount[] }
+ const grants = Array.isArray(res.grants) ? res.grants : []
+ // Default to the recipe lane when ownerKind is absent, preserving the
+ // pre-owner-generalization behavior for any grant that predates the field.
+ return grants.map(g => ({
+ ...g,
+ ownerKind: g.ownerKind === 'mcpserver' ? 'mcpserver' : 'recipe',
+ }))
}
export async function revokeConnectedAccount(a: ConnectedAccount): Promise<void> {
await apiSend(
'DELETE',
- `/api/v1/oauth/grants/${encodeURIComponent(a.recipeNamespace)}/${encodeURIComponent(a.recipeName)}/${encodeURIComponent(a.oauthClientId)}`
+ `/api/v1/oauth/grants/${encodeURIComponent(a.recipeNamespace)}/${encodeURIComponent(a.recipeName)}/${encodeURIComponent(a.oauthClientId)}`,
+ undefined,
+ { ownerKind: a.ownerKind }
)
}
diff --git a/profile-ui/package.json b/profile-ui/package.json
index 766abfa1a..b95888f85 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.140",
+ "version": "0.1.141",
"private": true,
"scripts": {
"dev": "next dev",
diff --git a/profile-ui/test/connectedAccounts.test.ts b/profile-ui/test/connectedAccounts.test.ts
new file mode 100644
index 000000000..8cc4ce72c
--- /dev/null
+++ b/profile-ui/test/connectedAccounts.test.ts
@@ -0,0 +1,119 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+import { EXTERNAL_REST_API_BASE_URL } from '../app/constants/api'
+import {
+ type ConnectedAccount,
+ describeGrantSource,
+ listConnectedAccounts,
+ revokeConnectedAccount,
+} from '../lib/connectedAccounts'
+
+const recipeGrant: ConnectedAccount = {
+ ownerKind: 'recipe',
+ recipeNamespace: 'team-ns',
+ recipeName: 'calendar-plugin',
+ oauthClientId: 'google',
+ provider: 'google',
+ background: true,
+ updatedAt: '2026-09-20T00:00:00.000Z',
+}
+
+// mcp-server grant on the remote lane: oauthClientId is a self-URL that must be
+// URL-encoded segment-by-segment, and provider is the raw 'remote' token.
+const mcpServerGrant: ConnectedAccount = {
+ ownerKind: 'mcpserver',
+ recipeNamespace: 'servers-ns',
+ recipeName: 'acme-remote',
+ mcpServerName: 'acme-remote',
+ oauthClientId: 'https://acme.example.com/oauth/callback',
+ provider: 'remote',
+ background: false,
+ updatedAt: '2026-09-20T00:00:00.000Z',
+}
+
+test('revokeConnectedAccount routes an mcpserver grant with ?ownerKind=mcpserver and encoded segments', async () => {
+ const previousFetch = globalThis.fetch
+ let request: { url: string; init?: RequestInit } | undefined
+ globalThis.fetch = (async (input, init) => {
+ request = { url: String(input), init }
+ return new Response(null, { status: 204 })
+ }) as typeof fetch
+ try {
+ await revokeConnectedAccount(mcpServerGrant)
+ assert.ok(request)
+ assert.equal(request.init?.method, 'DELETE')
+ const expected =
+ `${EXTERNAL_REST_API_BASE_URL}/api/v1/oauth/grants/` +
+ `${encodeURIComponent('servers-ns')}/${encodeURIComponent('acme-remote')}/` +
+ `${encodeURIComponent('https://acme.example.com/oauth/callback')}` +
+ `?ownerKind=mcpserver`
+ assert.equal(request.url, expected)
+ // The raw self-URL must be percent-encoded, never sent as path separators.
+ assert.ok(request.url.includes('https%3A%2F%2Facme.example.com%2Foauth%2Fcallback'))
+ } finally {
+ globalThis.fetch = previousFetch
+ }
+})
+
+test('revokeConnectedAccount keeps the recipe lane byte-compatible with ?ownerKind=recipe', async () => {
+ const previousFetch = globalThis.fetch
+ let request: { url: string; init?: RequestInit } | undefined
+ globalThis.fetch = (async (input, init) => {
+ request = { url: String(input), init }
+ return new Response(null, { status: 204 })
+ }) as typeof fetch
+ try {
+ await revokeConnectedAccount(recipeGrant)
+ assert.ok(request)
+ assert.equal(request.init?.method, 'DELETE')
+ assert.equal(
+ request.url,
+ `${EXTERNAL_REST_API_BASE_URL}/api/v1/oauth/grants/team-ns/calendar-plugin/google?ownerKind=recipe`
+ )
+ } finally {
+ globalThis.fetch = previousFetch
+ }
+})
+
+test('describeGrantSource hides the raw remote/generic provider token for mcp-server grants', () => {
+ assert.deepEqual(describeGrantSource(mcpServerGrant), {
+ typeLabel: 'MCP server',
+ detail: null,
+ })
+ assert.deepEqual(describeGrantSource({ ...mcpServerGrant, provider: 'generic' }), {
+ typeLabel: 'MCP server',
+ detail: null,
+ })
+})
+
+test('describeGrantSource shows a baked mcp-server provider and the recipe provider', () => {
+ assert.deepEqual(describeGrantSource({ ...mcpServerGrant, provider: 'clickup' }), {
+ typeLabel: 'MCP server',
+ detail: 'clickup',
+ })
+ assert.deepEqual(describeGrantSource(recipeGrant), {
+ typeLabel: 'Plugin',
+ detail: 'google',
+ })
+})
+
+test('listConnectedAccounts defaults a missing ownerKind to recipe', async () => {
+ const previousFetch = globalThis.fetch
+ globalThis.fetch = (async () =>
+ new Response(
+ JSON.stringify({
+ grants: [
+ { recipeNamespace: 'ns', recipeName: 'legacy', oauthClientId: 'c', provider: 'p' },
+ { ...mcpServerGrant },
+ ],
+ }),
+ { status: 200, headers: { 'content-type': 'application/json' } }
+ )) as typeof fetch
+ try {
+ const accounts = await listConnectedAccounts()
+ assert.equal(accounts[0]?.ownerKind, 'recipe')
+ assert.equal(accounts[1]?.ownerKind, 'mcpserver')
+ } finally {
+ globalThis.fetch = previousFetch
+ }
+})