"use client" import { useEffect, useMemo, useState } from "react" type McpTransport = "stdio" | "http" type McpCatalogEntry = { id: string name: string summary: string websiteUrl?: string transport: McpTransport command: string args: string[] env: Record tags: string[] } type McpServerInstall = McpCatalogEntry & { installedAt: string updatedAt: string source: "catalog" | "custom" | "registry" enabled: boolean accessMode: "disabled" | "allow_all" | "allow_only" allowedSandboxIds: string[] } type McpResponse = { catalog: McpCatalogEntry[] servers: McpServerInstall[] config: Record error?: string } type McpSandbox = { id: string name: string status: string } type McpConfigurationPanelProps = { sandboxes?: McpSandbox[] } const REGISTRY_PAGE_SIZE = 4 function FieldLabel({ children }: { children: React.ReactNode }) { return } function parseLines(value: string) { return value .split(/\r?\n/) .map((line) => line.trim()) .filter(Boolean) } function parseEnv(value: string) { return Object.fromEntries( parseLines(value) .map((line) => { const [key, ...rest] = line.split("=") return [key?.trim() || "", rest.join("=").trim()] }) .filter(([key]) => Boolean(key)), ) } export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurationPanelProps) { const [loading, setLoading] = useState(true) const [saving, setSaving] = useState(false) const [message, setMessage] = useState("") const [catalog, setCatalog] = useState([]) const [servers, setServers] = useState([]) const [config, setConfig] = useState>({ mcpServers: {} }) const [customName, setCustomName] = useState("custom-tools") const [customSummary, setCustomSummary] = useState("Custom MCP server") const [customTransport, setCustomTransport] = useState("stdio") const [customCommand, setCustomCommand] = useState("npx") const [customArgs, setCustomArgs] = useState("-y\n@modelcontextprotocol/server-memory") const [customEnv, setCustomEnv] = useState("") const [registrySearch, setRegistrySearch] = useState("github") const [registryResults, setRegistryResults] = useState([]) const [registryLoading, setRegistryLoading] = useState(false) const [registryPage, setRegistryPage] = useState(1) const [lastRegistrySearch, setLastRegistrySearch] = useState("") const [catalogOpen, setCatalogOpen] = useState(false) const [customOpen, setCustomOpen] = useState(false) const installedIds = useMemo(() => new Set(servers.map((server) => server.id)), [servers]) const enabledCount = servers.filter((server) => server.enabled).length const configText = JSON.stringify(config, null, 2) const registryPageCount = Math.max(1, Math.ceil(registryResults.length / REGISTRY_PAGE_SIZE)) const pagedRegistryResults = registryResults.slice( (registryPage - 1) * REGISTRY_PAGE_SIZE, registryPage * REGISTRY_PAGE_SIZE, ) async function load() { try { setLoading(true) const response = await fetch("/api/mcp", { cache: "no-store" }) const data = await response.json() as McpResponse if (!response.ok) throw new Error(data.error || "Failed to load MCP configuration") setCatalog(Array.isArray(data.catalog) ? data.catalog : []) setServers(Array.isArray(data.servers) ? data.servers : []) setConfig(data.config || { mcpServers: {} }) setMessage("") } catch (error) { setMessage(error instanceof Error ? error.message : "Failed to load MCP configuration") } finally { setLoading(false) } } async function postUpdate(body: Record, success: string) { try { setSaving(true) const response = await fetch("/api/mcp", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }) const data = await response.json() as McpResponse if (!response.ok) throw new Error(data.error || "Failed to update MCP configuration") setCatalog(Array.isArray(data.catalog) ? data.catalog : catalog) setServers(Array.isArray(data.servers) ? data.servers : []) setConfig(data.config || { mcpServers: {} }) setMessage(success) } catch (error) { setMessage(error instanceof Error ? error.message : "Failed to update MCP configuration") } finally { setSaving(false) } } function sandboxAllowed(server: McpServerInstall, sandbox: McpSandbox) { return server.allowedSandboxIds.includes(sandbox.id) || server.allowedSandboxIds.includes(sandbox.name) } function toggleServerSandbox(server: McpServerInstall, sandbox: McpSandbox, allowed: boolean) { const current = new Set(server.allowedSandboxIds) current.delete(sandbox.id) current.delete(sandbox.name) if (allowed) current.add(sandbox.id) return postUpdate({ action: "update-access", serverId: server.id, accessMode: "allow_only", allowedSandboxIds: Array.from(current), }, `${server.name} sandbox access updated.`) } async function searchRegistry() { const query = registrySearch.trim() try { setRegistryLoading(true) setRegistryResults([]) setRegistryPage(1) setLastRegistrySearch(query) const params = new URLSearchParams({ search: query, limit: "24" }) const response = await fetch(`/api/mcp/registry?${params}`, { cache: "no-store" }) const data = await response.json() if (!response.ok) throw new Error(data.error || "Failed to search MCP registry") const results = Array.isArray(data.results) ? data.results : [] setRegistryResults(results) setMessage(results.length > 0 ? `Found ${results.length} registry server${results.length === 1 ? "" : "s"}.` : "No registry servers matched that search.") } catch (error) { setRegistryResults([]) setMessage(error instanceof Error ? error.message : "Failed to search MCP registry") } finally { setRegistryLoading(false) } } useEffect(() => { load() }, []) return (

Model Context Protocol

MCP CONFIGURATION

Install MCP server definitions for local tools, files, and remote context providers.

Installed

{servers.length} servers

Enabled

{enabledCount} active

Catalog

{catalog.length} presets

{message && (
{message}
)} {loading ? (
Loading MCP servers...
) : (

MCP Security

Control which installed MCP servers are available to sandboxes.

{servers.length === 0 ? (
Install an MCP server before configuring sandbox access.
) : servers.map((server) => (

{server.name}

{server.enabled ? "enabled" : "disabled"}

{server.command} {server.args.join(" ")}

Availability
Allowed Sandboxes {sandboxes.length === 0 ? (
No sandboxes detected.
) : (
{sandboxes.map((sandbox) => ( ))}
)}
))}

Registry Search

Search the Official MCP Registry and install compatible stdio or remote HTTP servers.

Open Registry
setRegistrySearch(event.target.value)} onKeyDown={(event) => { if (event.key === "Enter") searchRegistry() }} placeholder="Search GitHub, Slack, filesystem, Postgres..." className="field-control min-w-0 flex-1 px-3 py-2 text-sm" />
{registryResults.length > 0 && ( <>

Showing {((registryPage - 1) * REGISTRY_PAGE_SIZE) + 1}-{Math.min(registryPage * REGISTRY_PAGE_SIZE, registryResults.length)} of {registryResults.length} {lastRegistrySearch ? ` for "${lastRegistrySearch}"` : ""}

{registryPage} / {registryPageCount}
{pagedRegistryResults.map((entry, index) => { const installed = installedIds.has(entry.id) return (

{entry.name}

{entry.summary}

{entry.transport}
{entry.command} {entry.args.join(" ")}

{entry.tags.join(" / ")}

) })}
)}
{catalogOpen && (
{catalog.map((entry) => { const installed = installedIds.has(entry.id) return (

{entry.name}

{entry.summary}

{entry.websiteUrl && ( Setup Guide )}
{entry.transport}
{entry.command} {entry.args.join(" ")}

{entry.tags.join(" / ")}

) })}
)}
{customOpen && (
Name setCustomName(event.target.value)} className="field-control w-full px-3 py-2 text-sm font-mono" />
Transport
Summary setCustomSummary(event.target.value)} className="field-control w-full px-3 py-2 text-sm" />
{customTransport === "http" ? "URL" : "Command"} setCustomCommand(event.target.value)} placeholder={customTransport === "http" ? "https://mcp.example.com/mcp" : "npx, uvx, node, python"} className="field-control w-full px-3 py-2 text-sm font-mono" />
Args