OIDC Configuration
diff --git a/web/components/mcp-settings.tsx b/web/components/mcp-settings.tsx
new file mode 100644
index 0000000..6d8f30d
--- /dev/null
+++ b/web/components/mcp-settings.tsx
@@ -0,0 +1,250 @@
+'use client'
+
+// Settings → MCP: Notion-style connections UI for OUTBOUND MCP servers.
+// Superbrain dials these as a client (internal/mcpclient) so its AI can use
+// their tools; this surface manages them. House disciplines visible here:
+// secrets are write-only (never prefilled; the mask round-trips unchanged),
+// every mutating PATCH carries the row version (409 reloads), and plan or
+// policy refusals surface the server's message — the UI never guesses.
+
+import { useCallback, useEffect, useState } from 'react'
+import { Button } from '@/components/ui/button'
+import { Input } from '@/components/ui/input'
+import { Badge } from '@/components/ui/badge'
+import { Switch } from '@/components/ui/switch'
+import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
+import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
+import { Loader2, PlugZap, Plus, Trash2, FlaskConical } from 'lucide-react'
+import { toast } from 'sonner'
+
+const KEY_MASK = '••••••••'
+
+type McpConnection = {
+ id: string; name: string; url: string; transport: string; authKind: string
+ headerName: string; secret: string; enabled: boolean; version: number
+}
+type TestResult = { ok: boolean; count?: number; tools?: { name: string; description: string }[]; error?: string }
+
+type FormState = {
+ id: string | null; version: number
+ name: string; url: string; transport: string; authKind: string; headerName: string
+ secret: string; hasStoredSecret: boolean
+}
+
+const emptyForm: FormState = {
+ id: null, version: 0, name: '', url: '', transport: 'streamable-http',
+ authKind: 'none', headerName: '', secret: '', hasStoredSecret: false,
+}
+
+async function api(path: string, init?: RequestInit): Promise
{
+ return fetch(path, { headers: { 'Content-Type': 'application/json' }, cache: 'no-store', ...init })
+}
+
+export function McpSettings() {
+ const [connections, setConnections] = useState([])
+ const [loading, setLoading] = useState(true)
+ const [form, setForm] = useState(null)
+ const [saving, setSaving] = useState(false)
+ const [testing, setTesting] = useState(null)
+ const [results, setResults] = useState>({})
+
+ const reload = useCallback(() =>
+ api('/api/mcp/connections')
+ .then(r => r.json())
+ .then(data => setConnections(Array.isArray(data?.connections) ? data.connections : []))
+ .catch(() => toast.error('Could not load MCP connections'))
+ .finally(() => setLoading(false)), [])
+
+ useEffect(() => { reload() }, [reload])
+
+ const openCreate = () => setForm({ ...emptyForm })
+ const openEdit = (c: McpConnection) => setForm({
+ id: c.id, version: c.version, name: c.name, url: c.url, transport: c.transport,
+ authKind: c.authKind, headerName: c.headerName, secret: '', hasStoredSecret: c.secret === KEY_MASK,
+ })
+
+ const save = async () => {
+ if (!form) return
+ const body: Record = {
+ name: form.name.trim(), url: form.url.trim(), transport: form.transport,
+ authKind: form.authKind, headerName: form.headerName.trim(),
+ }
+ // Write-only secret: send only what the user typed; the mask (or an
+ // empty field) tells the server to keep the stored value.
+ if (form.secret) body.secret = form.secret
+ setSaving(true)
+ try {
+ const res = form.id
+ ? await api(`/api/mcp/connections/${form.id}`, { method: 'PATCH', body: JSON.stringify({ ...body, version: form.version }) })
+ : await api('/api/mcp/connections', { method: 'POST', body: JSON.stringify(body) })
+ const data = await res.json().catch(() => null)
+ if (res.status === 409) {
+ toast.error('Connection changed elsewhere — reloaded')
+ await reload()
+ setForm(null)
+ return
+ }
+ if (!res.ok) { toast.error(data?.error ?? 'Could not save the connection'); return }
+ toast.success(form.id ? 'Connection updated' : 'Connection added')
+ setForm(null)
+ await reload()
+ } catch { toast.error('Could not save the connection') }
+ finally { setSaving(false) }
+ }
+
+ const test = async (c: McpConnection) => {
+ setTesting(c.id)
+ setResults(prev => ({ ...prev, [c.id]: undefined as unknown as TestResult }))
+ try {
+ const res = await api(`/api/mcp/connections/${c.id}/test`, { method: 'POST', body: '{}' })
+ const data = await res.json().catch(() => null)
+ setResults(prev => ({ ...prev, [c.id]: data as TestResult }))
+ if (res.ok && data?.ok) toast.success(`${data.count} tool${data.count === 1 ? '' : 's'} available`)
+ } catch { setResults(prev => ({ ...prev, [c.id]: { ok: false, error: 'Network error' } })) }
+ finally { setTesting(null) }
+ }
+
+ const toggle = async (c: McpConnection) => {
+ const res = await api(`/api/mcp/connections/${c.id}`, {
+ method: 'PATCH', body: JSON.stringify({ enabled: !c.enabled, version: c.version }),
+ })
+ if (res.status === 409) { toast.error('Connection changed elsewhere — reloaded'); await reload(); return }
+ if (!res.ok) { toast.error((await res.json().catch(() => null))?.error ?? 'Could not update'); return }
+ await reload()
+ }
+
+ const remove = async (c: McpConnection) => {
+ const res = await api(`/api/mcp/connections/${c.id}`, { method: 'DELETE' })
+ if (res.ok) { toast.success(`Removed ${c.name}`); await reload() }
+ else toast.error((await res.json().catch(() => null))?.error ?? 'Could not remove')
+ }
+
+ if (loading) {
+ return (
+
+ Loading MCP connections…
+
+ )
+ }
+
+ return (
+
+
+
+
MCP connections
+
+ Connect Superbrain’s AI to external MCP servers (Streamable HTTP or SSE).
+ Credentials are encrypted at rest and never shown again after saving.
+
+
+
+
+
+ {connections.length === 0 ? (
+
No MCP connections yet.
+ ) : (
+
+ )}
+
+
+
+ )
+}