@prenta/admin 2.15.0 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/__tests__/components/presence-indicator.render.test.d.ts +2 -0
  3. package/dist/__tests__/components/presence-indicator.render.test.d.ts.map +1 -0
  4. package/dist/__tests__/components/presence-indicator.render.test.js +97 -0
  5. package/dist/__tests__/components/presence-indicator.render.test.js.map +1 -0
  6. package/dist/__tests__/views/audit-media.test.js +6 -2
  7. package/dist/__tests__/views/audit-media.test.js.map +1 -1
  8. package/dist/__tests__/views/mcp-connect.render.test.js +54 -4
  9. package/dist/__tests__/views/mcp-connect.render.test.js.map +1 -1
  10. package/dist/__tests__/views/mcp-consent.render.test.d.ts +2 -0
  11. package/dist/__tests__/views/mcp-consent.render.test.d.ts.map +1 -0
  12. package/dist/__tests__/views/mcp-consent.render.test.js +112 -0
  13. package/dist/__tests__/views/mcp-consent.render.test.js.map +1 -0
  14. package/dist/components/PresenceIndicator.d.ts.map +1 -1
  15. package/dist/components/PresenceIndicator.js +10 -1
  16. package/dist/components/PresenceIndicator.js.map +1 -1
  17. package/dist/lib/notifications-client.d.ts +1 -1
  18. package/dist/prenta-admin.css +1 -1
  19. package/dist/views/McpConsent.d.ts.map +1 -1
  20. package/dist/views/McpConsent.js +21 -3
  21. package/dist/views/McpConsent.js.map +1 -1
  22. package/dist/views/Settings.js +1 -1
  23. package/dist/views/Settings.js.map +1 -1
  24. package/dist/views/settings/McpConnectTab.d.ts +2 -1
  25. package/dist/views/settings/McpConnectTab.d.ts.map +1 -1
  26. package/dist/views/settings/McpConnectTab.js +95 -4
  27. package/dist/views/settings/McpConnectTab.js.map +1 -1
  28. package/package.json +3 -3
  29. package/src/__tests__/components/presence-indicator.render.test.tsx +114 -0
  30. package/src/__tests__/views/audit-media.test.tsx +6 -2
  31. package/src/__tests__/views/mcp-connect.render.test.tsx +79 -5
  32. package/src/__tests__/views/mcp-consent.render.test.tsx +124 -0
  33. package/src/components/PresenceIndicator.tsx +10 -1
  34. package/src/lib/notifications-client.ts +1 -1
  35. package/src/views/McpConsent.tsx +37 -10
  36. package/src/views/Settings.tsx +1 -1
  37. package/src/views/settings/McpConnectTab.tsx +232 -16
@@ -0,0 +1,124 @@
1
+ // @vitest-environment happy-dom
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react'
4
+
5
+ const cmsApiMock = vi.fn()
6
+ vi.mock('../../lib/api.js', () => ({
7
+ cmsApi: (...args: unknown[]) => cmsApiMock(...args),
8
+ }))
9
+
10
+ import { McpConsent } from '../../views/McpConsent.js'
11
+
12
+ const assignMock = vi.fn()
13
+
14
+ beforeEach(() => {
15
+ cmsApiMock.mockReset()
16
+ assignMock.mockReset()
17
+ Object.defineProperty(window, 'location', {
18
+ value: { ...window.location, assign: assignMock },
19
+ writable: true,
20
+ configurable: true,
21
+ })
22
+ })
23
+
24
+ describe('McpConsent', () => {
25
+ it('auto-submits consent and redirects without a click when autoApprove is true', async () => {
26
+ cmsApiMock.mockImplementation(async (endpoint: string, options?: { method?: string }) => {
27
+ if (endpoint === '/mcp/oauth/transactions/txn-auto' && !options?.method) {
28
+ return {
29
+ data: {
30
+ clientName: 'Claude',
31
+ clientId: 'https://claude.ai/oauth/client.json',
32
+ redirectHost: 'claude.ai',
33
+ scope: 'content',
34
+ autoApprove: true,
35
+ autoApproveReason: 'trusted_client',
36
+ },
37
+ status: 200,
38
+ }
39
+ }
40
+ if (endpoint === '/mcp/oauth/consent' && options?.method === 'POST') {
41
+ return {
42
+ data: { redirectUrl: 'https://claude.ai/api/mcp/auth_callback?code=abc' },
43
+ status: 200,
44
+ }
45
+ }
46
+ return { data: {}, status: 200 }
47
+ })
48
+
49
+ render(<McpConsent currentPath="/mcp/consent?txn=txn-auto" />)
50
+
51
+ await waitFor(() => {
52
+ expect(cmsApiMock).toHaveBeenCalledWith('/mcp/oauth/consent', {
53
+ method: 'POST',
54
+ body: JSON.stringify({ txn: 'txn-auto', allow: true, auto: true }),
55
+ })
56
+ })
57
+ expect(assignMock).toHaveBeenCalledWith('https://claude.ai/api/mcp/auth_callback?code=abc')
58
+ // Manual Allow button is not shown while auto-approving succeeds.
59
+ expect(screen.queryByRole('button', { name: 'Allow' })).toBeNull()
60
+ })
61
+
62
+ it('falls back to manual Allow / Deny buttons if auto-approve POST fails', async () => {
63
+ cmsApiMock.mockImplementation(async (endpoint: string, options?: { method?: string }) => {
64
+ if (endpoint === '/mcp/oauth/transactions/txn-fallback' && !options?.method) {
65
+ return {
66
+ data: {
67
+ clientName: 'Claude',
68
+ clientId: 'https://claude.ai/oauth/client.json',
69
+ redirectHost: 'claude.ai',
70
+ scope: 'content',
71
+ autoApprove: true,
72
+ autoApproveReason: 'existing_grant',
73
+ },
74
+ status: 200,
75
+ }
76
+ }
77
+ if (endpoint === '/mcp/oauth/consent' && options?.method === 'POST') {
78
+ return { error: 'Client is not eligible for auto-approval', status: 403 }
79
+ }
80
+ return { data: {}, status: 200 }
81
+ })
82
+
83
+ render(<McpConsent currentPath="/mcp/consent?txn=txn-fallback" />)
84
+
85
+ expect(await screen.findByRole('button', { name: 'Allow' })).toBeTruthy()
86
+ expect(screen.getByRole('button', { name: 'Deny' })).toBeTruthy()
87
+ })
88
+
89
+ it('requires a manual click when autoApprove is false', async () => {
90
+ cmsApiMock.mockImplementation(async (endpoint: string, options?: { method?: string }) => {
91
+ if (endpoint === '/mcp/oauth/transactions/txn-manual' && !options?.method) {
92
+ return {
93
+ data: {
94
+ clientName: 'Custom Connector',
95
+ clientId: 'https://custom.example/client.json',
96
+ redirectHost: 'custom.example',
97
+ scope: 'content',
98
+ autoApprove: false,
99
+ autoApproveReason: null,
100
+ },
101
+ status: 200,
102
+ }
103
+ }
104
+ if (endpoint === '/mcp/oauth/consent' && options?.method === 'POST') {
105
+ return { data: { redirectUrl: 'https://custom.example/cb?code=xyz' }, status: 200 }
106
+ }
107
+ return { data: {}, status: 200 }
108
+ })
109
+
110
+ render(<McpConsent currentPath="/mcp/consent?txn=txn-manual" />)
111
+
112
+ const allow = await screen.findByRole('button', { name: 'Allow' })
113
+ expect(assignMock).not.toHaveBeenCalled()
114
+
115
+ fireEvent.click(allow)
116
+ await waitFor(() => {
117
+ expect(cmsApiMock).toHaveBeenCalledWith('/mcp/oauth/consent', {
118
+ method: 'POST',
119
+ body: JSON.stringify({ txn: 'txn-manual', allow: true }),
120
+ })
121
+ })
122
+ expect(assignMock).toHaveBeenCalledWith('https://custom.example/cb?code=xyz')
123
+ })
124
+ })
@@ -13,6 +13,9 @@ interface PresenceIndicatorProps {
13
13
  currentUserId?: string
14
14
  }
15
15
 
16
+ /** `EventSource.CLOSED`: the browser has given up and will not reconnect. */
17
+ const EVENT_SOURCE_CLOSED = 2
18
+
16
19
  /** The avatar palette (tokens.json `--avatar-*`): white initials clear 4.5:1 on each. */
17
20
  const COLORS = Array.from({ length: 8 }, (_, i) => `var(--avatar-${i + 1})`)
18
21
 
@@ -37,7 +40,13 @@ export function PresenceIndicator({ documentId, currentUserId }: PresenceIndicat
37
40
  })
38
41
 
39
42
  es.onerror = () => {
40
- es.close()
43
+ // The server ends the stream on purpose after a bounded lifetime
44
+ // (20 s on Vercel), and the browser reports that as an error
45
+ // before reconnecting on its own. Leave the connection and the
46
+ // current list alone: the first event after the reconnect carries
47
+ // the full list again. Only a connection the browser has given up
48
+ // on (an HTTP error status) is final, and then the list is stale.
49
+ if (es.readyState === EVENT_SOURCE_CLOSED) setUsers([])
41
50
  }
42
51
 
43
52
  heartbeatRef.current = setInterval(() => {
@@ -131,7 +131,7 @@ export async function markAllNotificationsRead(): Promise<NotificationOutcome<nu
131
131
  * poll loop in the notification bell.
132
132
  *
133
133
  * The browser's native `EventSource` handles reconnection for us — on
134
- * a server-initiated close (the stream caps at ~4 minutes by design),
134
+ * a server-initiated close (the stream caps its own lifetime by design),
135
135
  * the connection re-opens automatically. We DO NOT abort the poll
136
136
  * fallback in callers: SSE is a latency-win, the poll is what keeps
137
137
  * multi-node deployments correct (each node only pushes to its own
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
 
3
- import { useEffect, useState } from 'react'
3
+ import { useEffect, useRef, useState } from 'react'
4
4
  import { Loader2 } from 'lucide-react'
5
5
  import { cmsApi } from '../lib/api.js'
6
6
  import { parseRouteQuery } from '../router/index.js'
@@ -10,13 +10,17 @@ type ConsentDetails = {
10
10
  clientId: string
11
11
  redirectHost: string
12
12
  scope: string
13
+ autoApprove?: boolean
14
+ autoApproveReason?: 'trusted_client' | 'existing_grant' | null
13
15
  }
14
16
 
15
17
  export function McpConsent({ currentPath }: { currentPath: string }) {
16
18
  const txn = parseRouteQuery(currentPath).get('txn') ?? ''
17
19
  const [details, setDetails] = useState<ConsentDetails | null>(null)
20
+ const [autoApproving, setAutoApproving] = useState(false)
18
21
  const [error, setError] = useState('')
19
22
  const [busy, setBusy] = useState(false)
23
+ const autoSubmittedTxnRef = useRef<string | null>(null)
20
24
 
21
25
  useEffect(() => {
22
26
  if (!txn) {
@@ -24,14 +28,31 @@ export function McpConsent({ currentPath }: { currentPath: string }) {
24
28
  return
25
29
  }
26
30
  let cancelled = false
27
- cmsApi<ConsentDetails>(`/mcp/oauth/transactions/${encodeURIComponent(txn)}`).then((res) => {
28
- if (cancelled) return
29
- if (res.error || !res.data) {
30
- setError(res.error ?? 'This connection request expired.')
31
- return
32
- }
33
- setDetails(res.data)
34
- })
31
+ cmsApi<ConsentDetails>(`/mcp/oauth/transactions/${encodeURIComponent(txn)}`).then(
32
+ async (res) => {
33
+ if (cancelled) return
34
+ if (res.error || !res.data) {
35
+ setError(res.error ?? 'This connection request expired.')
36
+ return
37
+ }
38
+ setDetails(res.data)
39
+ if (res.data.autoApprove && autoSubmittedTxnRef.current !== txn) {
40
+ autoSubmittedTxnRef.current = txn
41
+ setAutoApproving(true)
42
+ const consentRes = await cmsApi<{ redirectUrl: string }>('/mcp/oauth/consent', {
43
+ method: 'POST',
44
+ body: JSON.stringify({ txn, allow: true, auto: true }),
45
+ })
46
+ if (cancelled) return
47
+ if (consentRes.error || !consentRes.data?.redirectUrl) {
48
+ setAutoApproving(false)
49
+ setError(consentRes.error ?? 'Could not auto-approve connection.')
50
+ return
51
+ }
52
+ window.location.assign(consentRes.data.redirectUrl)
53
+ }
54
+ },
55
+ )
35
56
  return () => {
36
57
  cancelled = true
37
58
  }
@@ -62,8 +83,14 @@ export function McpConsent({ currentPath }: { currentPath: string }) {
62
83
  Loading the request
63
84
  </p>
64
85
  )}
86
+ {details && autoApproving && (
87
+ <p className="text-muted-foreground mt-4 flex items-center gap-2 text-sm">
88
+ <Loader2 className="animate-spin" size={16} aria-hidden="true" />
89
+ Connecting <span className="text-foreground font-medium">{details.clientName}</span>…
90
+ </p>
91
+ )}
65
92
  {error && <p className="text-destructive mt-4 text-sm">{error}</p>}
66
- {details && (
93
+ {details && !autoApproving && (
67
94
  <div className="mt-4 space-y-4">
68
95
  <p className="text-foreground text-base">
69
96
  <span className="font-medium">{details.clientName}</span> wants to edit content on
@@ -280,7 +280,7 @@ export function Settings({
280
280
  className: 'space-y-4',
281
281
  },
282
282
  users: { body: <UsersView onNavigate={onNavigate} embedded currentPath={currentPath} /> },
283
- mcp: { body: <McpConnectTab onNavigate={onNavigate} /> },
283
+ mcp: { body: <McpConnectTab onNavigate={onNavigate} role={session?.user?.role} /> },
284
284
  'api-keys': { body: <ApiKeysView onNavigate={onNavigate} embedded /> },
285
285
  updates: { body: <UpdatesTab role={session?.user?.role} />, className: 'space-y-4' },
286
286
  }
@@ -1,12 +1,13 @@
1
1
  'use client'
2
2
 
3
3
  import * as Tabs from '@radix-ui/react-tabs'
4
- import { Copy, Loader2 } from 'lucide-react'
5
- import { useEffect, useState } from 'react'
4
+ import { Copy, Loader2, Plus, Trash2 } from 'lucide-react'
5
+ import { useEffect, useState, type FormEvent } from 'react'
6
6
  import { toast } from 'sonner'
7
7
 
8
+ import { Switch } from '../../components/ui/Toggle.js'
8
9
  import { cmsApi } from '../../lib/api.js'
9
- import { SettingsCard } from './components.js'
10
+ import { SettingsCard, SettingsControlRow } from './components.js'
10
11
  import { mcpClientGuides, type McpClientGuide, type McpClientId } from './mcp-connect.js'
11
12
 
12
13
  type Grant = {
@@ -16,6 +17,38 @@ type Grant = {
16
17
  revokedAt: string | null
17
18
  }
18
19
 
20
+ type TrustedClientEntry = {
21
+ value: string
22
+ source: 'config' | 'settings'
23
+ }
24
+
25
+ type McpSettingsData = {
26
+ autoApproveReconnect: boolean
27
+ autoApproveReconnectFromConfig: boolean
28
+ trustedClients: TrustedClientEntry[]
29
+ }
30
+
31
+ function isClientMatchedByTrusted(clientId: string, entries: TrustedClientEntry[]): boolean {
32
+ let clientOrigin = ''
33
+ try {
34
+ clientOrigin = new URL(clientId).origin
35
+ } catch {
36
+ return false
37
+ }
38
+ const normalizedClient = clientId.replace(/\/+$/, '')
39
+ return entries.some((entry) => {
40
+ try {
41
+ const entryUrl = new URL(entry.value)
42
+ if (entryUrl.pathname === '/' && entry.value === entryUrl.origin) {
43
+ return clientOrigin === entryUrl.origin
44
+ }
45
+ return normalizedClient === entry.value
46
+ } catch {
47
+ return false
48
+ }
49
+ })
50
+ }
51
+
19
52
  async function copyText(value: string, label: string) {
20
53
  try {
21
54
  await navigator.clipboard.writeText(value)
@@ -92,11 +125,25 @@ function ClientPanel({ guide, onCreateKey }: { guide: McpClientGuide; onCreateKe
92
125
  * there" setup other site builders use. The URL comes from the server so the
93
126
  * Host header is never trusted.
94
127
  */
95
- export function McpConnectTab({ onNavigate }: { onNavigate?: (path: string) => void }) {
128
+ export function McpConnectTab({
129
+ onNavigate,
130
+ role,
131
+ }: {
132
+ onNavigate?: (path: string) => void
133
+ role?: string
134
+ }) {
135
+ const canManage = role === 'SUPER_ADMIN' || role === 'ADMIN'
96
136
  const [mcpUrl, setMcpUrl] = useState('')
97
137
  const [loadError, setLoadError] = useState<string | null>(null)
98
138
  const [loading, setLoading] = useState(true)
99
139
  const [grants, setGrants] = useState<Grant[]>([])
140
+ const [settings, setSettings] = useState<McpSettingsData>({
141
+ autoApproveReconnect: true,
142
+ autoApproveReconnectFromConfig: false,
143
+ trustedClients: [],
144
+ })
145
+ const [newTrustedInput, setNewTrustedInput] = useState('')
146
+ const [savingSettings, setSavingSettings] = useState(false)
100
147
  const [client, setClient] = useState<McpClientId>('claude-code')
101
148
 
102
149
  function loadGrants() {
@@ -105,6 +152,12 @@ export function McpConnectTab({ onNavigate }: { onNavigate?: (path: string) => v
105
152
  })
106
153
  }
107
154
 
155
+ function loadSettings() {
156
+ void cmsApi<McpSettingsData>('/mcp/oauth/settings').then((res) => {
157
+ if (res.data) setSettings(res.data)
158
+ })
159
+ }
160
+
108
161
  useEffect(() => {
109
162
  let cancelled = false
110
163
  void cmsApi<{ mcpUrl: string }>('/mcp/oauth/setup').then((res) => {
@@ -119,11 +172,64 @@ export function McpConnectTab({ onNavigate }: { onNavigate?: (path: string) => v
119
172
  setMcpUrl(res.data.mcpUrl)
120
173
  })
121
174
  loadGrants()
175
+ loadSettings()
122
176
  return () => {
123
177
  cancelled = true
124
178
  }
125
179
  }, [])
126
180
 
181
+ async function persistMcpSettings(nextReconnect: boolean, nextDbTrusted: string[]) {
182
+ setSavingSettings(true)
183
+ const res = await cmsApi<McpSettingsData>('/mcp/oauth/settings', {
184
+ method: 'PUT',
185
+ body: JSON.stringify({
186
+ autoApproveReconnect: nextReconnect,
187
+ trustedClients: nextDbTrusted,
188
+ }),
189
+ })
190
+ setSavingSettings(false)
191
+ if (res.error || !res.data) {
192
+ toast.error(res.error ?? 'Could not save MCP settings')
193
+ return false
194
+ }
195
+ setSettings(res.data)
196
+ toast.success('MCP settings saved')
197
+ return true
198
+ }
199
+
200
+ function dbTrustedValues(): string[] {
201
+ return settings.trustedClients.filter((e) => e.source === 'settings').map((e) => e.value)
202
+ }
203
+
204
+ async function handleToggleReconnect(next: boolean) {
205
+ if (!canManage || savingSettings) return
206
+ await persistMcpSettings(next, dbTrustedValues())
207
+ }
208
+
209
+ async function handleAddTrusted(e: FormEvent) {
210
+ e.preventDefault()
211
+ const trimmed = newTrustedInput.trim()
212
+ if (!trimmed || !canManage || savingSettings) return
213
+ const ok = await persistMcpSettings(settings.autoApproveReconnect, [
214
+ ...dbTrustedValues(),
215
+ trimmed,
216
+ ])
217
+ if (ok) setNewTrustedInput('')
218
+ }
219
+
220
+ async function handleRemoveTrusted(value: string) {
221
+ if (!canManage || savingSettings) return
222
+ await persistMcpSettings(
223
+ settings.autoApproveReconnect,
224
+ dbTrustedValues().filter((v) => v !== value),
225
+ )
226
+ }
227
+
228
+ async function handleTrustConnectedClient(clientId: string) {
229
+ if (!canManage || savingSettings) return
230
+ await persistMcpSettings(settings.autoApproveReconnect, [...dbTrustedValues(), clientId])
231
+ }
232
+
127
233
  async function revoke(id: string) {
128
234
  const res = await cmsApi<{ note: string }>(`/mcp/oauth/grants/${encodeURIComponent(id)}`, {
129
235
  method: 'DELETE',
@@ -185,6 +291,93 @@ export function McpConnectTab({ onNavigate }: { onNavigate?: (path: string) => v
185
291
  </Tabs.Root>
186
292
  )}
187
293
 
294
+ <SettingsCard
295
+ title="Auto-approve"
296
+ description="Skip the manual Allow click for reconnects or explicitly trusted HTTPS client origins and CIMD URLs."
297
+ >
298
+ <div className="space-y-5">
299
+ <SettingsControlRow
300
+ label="Auto-approve reconnects"
301
+ description={
302
+ settings.autoApproveReconnectFromConfig
303
+ ? 'Managed in prenta.config.ts (mcp.autoApproveReconnect).'
304
+ : 'Automatically allow an app when you have already approved it and have not revoked its access.'
305
+ }
306
+ control={
307
+ <Switch
308
+ aria-label="Auto-approve reconnects"
309
+ checked={settings.autoApproveReconnect}
310
+ disabled={!canManage || savingSettings || settings.autoApproveReconnectFromConfig}
311
+ onCheckedChange={(checked) => void handleToggleReconnect(checked)}
312
+ />
313
+ }
314
+ />
315
+
316
+ <div className="border-border space-y-3 border-t pt-4">
317
+ <div>
318
+ <h3 className="text-foreground text-sm font-medium">Trusted clients</h3>
319
+ <p className="text-muted-foreground mt-0.5 text-xs">
320
+ Enter an HTTPS origin (e.g. <span className="font-mono">https://claude.ai</span>) or
321
+ an exact client metadata URL to grant editorial access without a consent click.
322
+ </p>
323
+ </div>
324
+
325
+ {settings.trustedClients.length === 0 ? (
326
+ <p className="text-muted-foreground text-sm">No trusted clients configured.</p>
327
+ ) : (
328
+ <ul className="space-y-2">
329
+ {settings.trustedClients.map((entry) => (
330
+ <li
331
+ key={`${entry.source}:${entry.value}`}
332
+ className="border-border flex items-center justify-between gap-3 rounded-md border px-3 py-2 text-sm"
333
+ >
334
+ <span className="min-w-0 truncate font-mono text-xs">{entry.value}</span>
335
+ {entry.source === 'config' ? (
336
+ <span className="bg-muted text-muted-foreground shrink-0 rounded px-2 py-0.5 text-xs font-medium whitespace-nowrap">
337
+ Config
338
+ </span>
339
+ ) : canManage ? (
340
+ <button
341
+ type="button"
342
+ disabled={savingSettings}
343
+ aria-label={`Remove ${entry.value}`}
344
+ onClick={() => void handleRemoveTrusted(entry.value)}
345
+ className="text-muted-foreground hover:text-destructive inline-flex shrink-0 items-center gap-1 text-xs font-medium disabled:opacity-50"
346
+ >
347
+ <Trash2 size={13} aria-hidden="true" />
348
+ Remove
349
+ </button>
350
+ ) : null}
351
+ </li>
352
+ ))}
353
+ </ul>
354
+ )}
355
+
356
+ {canManage && (
357
+ <form onSubmit={(e) => void handleAddTrusted(e)} className="flex flex-wrap gap-2">
358
+ <input
359
+ type="url"
360
+ value={newTrustedInput}
361
+ onChange={(e) => setNewTrustedInput(e.target.value)}
362
+ placeholder="https://claude.ai"
363
+ aria-label="Trusted client HTTPS URL"
364
+ disabled={savingSettings}
365
+ className="border-border bg-input-background text-foreground focus-visible:ring-ring min-w-[240px] flex-1 rounded-md border px-3 py-1.5 font-mono text-xs focus-visible:ring-2 focus-visible:outline-none disabled:opacity-50"
366
+ />
367
+ <button
368
+ type="submit"
369
+ disabled={!newTrustedInput.trim() || savingSettings}
370
+ className="border-border text-foreground hover:bg-accent inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50"
371
+ >
372
+ <Plus size={14} aria-hidden="true" />
373
+ Add trusted client
374
+ </button>
375
+ </form>
376
+ )}
377
+ </div>
378
+ </div>
379
+ </SettingsCard>
380
+
188
381
  <SettingsCard
189
382
  title="Connected apps"
190
383
  description="Revoke stops new requests immediately. An access token already issued can keep working for up to 15 minutes."
@@ -193,18 +386,41 @@ export function McpConnectTab({ onNavigate }: { onNavigate?: (path: string) => v
193
386
  <p className="text-muted-foreground text-sm">No apps connected yet.</p>
194
387
  ) : (
195
388
  <ul className="space-y-2">
196
- {grants.map((grant) => (
197
- <li key={grant.id} className="flex items-center justify-between gap-3 text-sm">
198
- <span className="min-w-0 truncate">{grant.clientId}</span>
199
- <button
200
- type="button"
201
- className="text-destructive focus-visible:ring-ring shrink-0 font-medium hover:underline focus-visible:ring-2 focus-visible:outline-none"
202
- onClick={() => void revoke(grant.id)}
203
- >
204
- Revoke
205
- </button>
206
- </li>
207
- ))}
389
+ {grants.map((grant) => {
390
+ const alreadyTrusted = isClientMatchedByTrusted(
391
+ grant.clientId,
392
+ settings.trustedClients,
393
+ )
394
+ return (
395
+ <li key={grant.id} className="flex items-center justify-between gap-3 text-sm">
396
+ <span className="min-w-0 truncate font-mono text-xs">{grant.clientId}</span>
397
+ <div className="flex shrink-0 items-center gap-3">
398
+ {alreadyTrusted ? (
399
+ <span className="bg-muted text-muted-foreground rounded px-2 py-0.5 text-xs font-medium whitespace-nowrap">
400
+ Trusted
401
+ </span>
402
+ ) : canManage ? (
403
+ <button
404
+ type="button"
405
+ disabled={savingSettings}
406
+ aria-label={`Trust ${grant.clientId}`}
407
+ onClick={() => void handleTrustConnectedClient(grant.clientId)}
408
+ className="text-primary focus-visible:ring-ring font-medium hover:underline focus-visible:ring-2 focus-visible:outline-none disabled:opacity-50"
409
+ >
410
+ Trust
411
+ </button>
412
+ ) : null}
413
+ <button
414
+ type="button"
415
+ className="text-destructive focus-visible:ring-ring font-medium hover:underline focus-visible:ring-2 focus-visible:outline-none"
416
+ onClick={() => void revoke(grant.id)}
417
+ >
418
+ Revoke
419
+ </button>
420
+ </div>
421
+ </li>
422
+ )
423
+ })}
208
424
  </ul>
209
425
  )}
210
426
  </SettingsCard>