Add MCP broker access controls
This commit is contained in:
@@ -0,0 +1,563 @@
|
||||
"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<string, string>
|
||||
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<string, unknown>
|
||||
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 <label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{children}</label>
|
||||
}
|
||||
|
||||
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<McpCatalogEntry[]>([])
|
||||
const [servers, setServers] = useState<McpServerInstall[]>([])
|
||||
const [config, setConfig] = useState<Record<string, unknown>>({ mcpServers: {} })
|
||||
const [customName, setCustomName] = useState("custom-tools")
|
||||
const [customSummary, setCustomSummary] = useState("Custom MCP server")
|
||||
const [customTransport, setCustomTransport] = useState<McpTransport>("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<McpCatalogEntry[]>([])
|
||||
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<string, unknown>, 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 (
|
||||
<div className="space-y-6">
|
||||
<div className="panel overflow-hidden">
|
||||
<div className="panel-header flex items-start justify-between gap-6 p-6 max-md:flex-col">
|
||||
<div>
|
||||
<p className="font-mono text-[10px] uppercase tracking-wider text-[var(--nvidia-green)]">Model Context Protocol</p>
|
||||
<h1 className="mt-1 text-xl font-semibold uppercase tracking-wider text-[var(--foreground)]">MCP CONFIGURATION</h1>
|
||||
<p className="mt-2 max-w-3xl text-sm text-[var(--foreground-dim)]">
|
||||
Install MCP server definitions for local tools, files, and remote context providers.
|
||||
</p>
|
||||
</div>
|
||||
<button onClick={load} disabled={loading || saving} className="action-button px-4 py-2">
|
||||
Refresh
|
||||
</button>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-px bg-[var(--border-subtle)] sm:grid-cols-3">
|
||||
<div className="bg-[var(--surface-raised)] p-4">
|
||||
<p className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Installed</p>
|
||||
<p className="mt-1 font-mono text-sm text-[var(--foreground)]">{servers.length} servers</p>
|
||||
</div>
|
||||
<div className="bg-[var(--surface-raised)] p-4">
|
||||
<p className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Enabled</p>
|
||||
<p className="mt-1 font-mono text-sm text-[var(--foreground)]">{enabledCount} active</p>
|
||||
</div>
|
||||
<div className="bg-[var(--surface-raised)] p-4">
|
||||
<p className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Catalog</p>
|
||||
<p className="mt-1 font-mono text-sm text-[var(--foreground)]">{catalog.length} presets</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{message && (
|
||||
<div className="panel p-4 text-xs text-[var(--foreground-dim)] whitespace-pre-wrap">
|
||||
{message}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{loading ? (
|
||||
<div className="panel p-8 text-xs uppercase tracking-wider text-[var(--foreground-dim)]">Loading MCP servers...</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_400px]">
|
||||
<section className="space-y-6">
|
||||
<div className="panel p-6">
|
||||
<div className="border-b border-[var(--border-subtle)] pb-4">
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">MCP Security</h2>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Control which installed MCP servers are available to sandboxes.</p>
|
||||
</div>
|
||||
<div className="mt-5 space-y-4">
|
||||
{servers.length === 0 ? (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-xs text-[var(--foreground-dim)]">
|
||||
Install an MCP server before configuring sandbox access.
|
||||
</div>
|
||||
) : servers.map((server) => (
|
||||
<div key={server.id} className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
|
||||
<div className="flex items-start justify-between gap-4 max-lg:flex-col">
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<h3 className="truncate text-sm font-mono font-semibold text-[var(--foreground)]">{server.name}</h3>
|
||||
<span className={`status-chip px-2 py-1 ${server.enabled ? "bg-[var(--status-running-bg)] text-[var(--status-running)]" : "bg-[var(--status-pending-bg)] text-[var(--status-pending)]"}`}>
|
||||
{server.enabled ? "enabled" : "disabled"}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-2 break-all font-mono text-[11px] text-[var(--foreground-dim)]">{server.command} {server.args.join(" ")}</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 gap-2 max-sm:w-full max-sm:[&>button]:flex-1">
|
||||
<button
|
||||
onClick={() => postUpdate({ action: "update-access", serverId: server.id, enabled: true }, `${server.name} enabled.`)}
|
||||
disabled={saving || server.enabled}
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
Enable
|
||||
</button>
|
||||
<button
|
||||
onClick={() => postUpdate({ action: "update-access", serverId: server.id, enabled: false }, `${server.name} disabled.`)}
|
||||
disabled={saving || !server.enabled}
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
Disable
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid grid-cols-1 gap-3 lg:grid-cols-[240px_minmax(0,1fr)]">
|
||||
<div className="space-y-2">
|
||||
<FieldLabel>Availability</FieldLabel>
|
||||
<select
|
||||
value={server.accessMode}
|
||||
onChange={(event) => postUpdate({
|
||||
action: "update-access",
|
||||
serverId: server.id,
|
||||
accessMode: event.target.value,
|
||||
}, `${server.name} availability updated.`)}
|
||||
disabled={saving}
|
||||
className="field-control w-full px-3 py-2 text-xs font-mono uppercase tracking-wider"
|
||||
>
|
||||
<option value="disabled">Disabled</option>
|
||||
<option value="allow_all">Allow All</option>
|
||||
<option value="allow_only">Allow Only</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className={server.accessMode === "allow_only" ? "space-y-2" : "opacity-50"}>
|
||||
<FieldLabel>Allowed Sandboxes</FieldLabel>
|
||||
{sandboxes.length === 0 ? (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 text-xs text-[var(--foreground-dim)]">
|
||||
No sandboxes detected.
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-2 md:grid-cols-2">
|
||||
{sandboxes.map((sandbox) => (
|
||||
<label key={sandbox.id} className="flex items-center justify-between gap-3 rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 text-xs">
|
||||
<span className="min-w-0">
|
||||
<span className="block truncate font-mono text-[var(--foreground)]">{sandbox.name}</span>
|
||||
<span className="mt-1 block truncate text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{sandbox.status}</span>
|
||||
</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={sandboxAllowed(server, sandbox)}
|
||||
disabled={saving || server.accessMode !== "allow_only"}
|
||||
onChange={(event) => toggleServerSandbox(server, sandbox, event.target.checked)}
|
||||
className="h-4 w-4 accent-[var(--nvidia-green)]"
|
||||
/>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel p-6">
|
||||
<div className="flex items-start justify-between gap-4 border-b border-[var(--border-subtle)] pb-4 max-md:flex-col">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Registry Search</h2>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Search the Official MCP Registry and install compatible stdio or remote HTTP servers.</p>
|
||||
</div>
|
||||
<a href="https://registry.modelcontextprotocol.io/" target="_blank" rel="noreferrer" className="action-button px-3 py-2">
|
||||
Open Registry
|
||||
</a>
|
||||
</div>
|
||||
<div className="mt-5 flex gap-3 max-sm:flex-col">
|
||||
<input
|
||||
value={registrySearch}
|
||||
onChange={(event) => 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"
|
||||
/>
|
||||
<button onClick={searchRegistry} disabled={registryLoading || saving} className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50">
|
||||
{registryLoading ? "Searching..." : "Search"}
|
||||
</button>
|
||||
</div>
|
||||
{registryResults.length > 0 && (
|
||||
<>
|
||||
<div className="mt-5 flex items-center justify-between gap-3 border-t border-[var(--border-subtle)] pt-4 max-sm:flex-col max-sm:items-start">
|
||||
<p className="text-xs text-[var(--foreground-dim)]">
|
||||
Showing {((registryPage - 1) * REGISTRY_PAGE_SIZE) + 1}-{Math.min(registryPage * REGISTRY_PAGE_SIZE, registryResults.length)} of {registryResults.length}
|
||||
{lastRegistrySearch ? ` for "${lastRegistrySearch}"` : ""}
|
||||
</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
onClick={() => setRegistryPage((page) => Math.max(1, page - 1))}
|
||||
disabled={registryPage === 1}
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
Prev
|
||||
</button>
|
||||
<span className="min-w-16 text-center text-xs font-mono text-[var(--foreground-dim)]">
|
||||
{registryPage} / {registryPageCount}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => setRegistryPage((page) => Math.min(registryPageCount, page + 1))}
|
||||
disabled={registryPage === registryPageCount}
|
||||
className="action-button px-3 py-2"
|
||||
>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-4 grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
{pagedRegistryResults.map((entry) => {
|
||||
const installed = installedIds.has(entry.id)
|
||||
return (
|
||||
<div key={`${entry.id}-${entry.command}`} className="metric flex min-h-44 flex-col p-4">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<h3 className="truncate text-sm font-semibold text-[var(--foreground)]">{entry.name}</h3>
|
||||
<p className="mt-2 text-xs leading-5 text-[var(--foreground-dim)]">{entry.summary}</p>
|
||||
</div>
|
||||
<span className="status-chip bg-[var(--status-pending-bg)] px-2 py-1 text-[var(--status-pending)]">{entry.transport}</span>
|
||||
</div>
|
||||
<div className="mt-3 min-w-0 rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-2 font-mono text-[11px] text-[var(--foreground-dim)]">
|
||||
<span className="text-[var(--foreground)]">{entry.command}</span> {entry.args.join(" ")}
|
||||
</div>
|
||||
<div className="mt-auto flex items-center justify-between gap-3 pt-4">
|
||||
<p className="truncate text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{entry.tags.join(" / ")}</p>
|
||||
<button
|
||||
onClick={() => postUpdate({ action: "install", ...entry, source: "registry" }, installed ? `${entry.name} refreshed from registry.` : `${entry.name} installed from registry.`)}
|
||||
disabled={saving}
|
||||
className={installed ? "action-button px-3 py-2" : "rounded-sm bg-[var(--nvidia-green)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"}
|
||||
>
|
||||
{installed ? "Refresh" : "Install"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="panel p-6">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setCatalogOpen((open) => !open)}
|
||||
className="flex w-full items-center justify-between gap-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--nvidia-green)]"
|
||||
aria-expanded={catalogOpen}
|
||||
>
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Preconfigured Servers</h2>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Presets install as MCP command definitions; clients start them when needed.</p>
|
||||
</div>
|
||||
<span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] text-sm text-[var(--foreground)]">
|
||||
{catalogOpen ? "-" : "+"}
|
||||
</span>
|
||||
</button>
|
||||
{catalogOpen && (
|
||||
<div className="mt-5 grid grid-cols-1 gap-3 border-t border-[var(--border-subtle)] pt-5 md:grid-cols-2">
|
||||
{catalog.map((entry) => {
|
||||
const installed = installedIds.has(entry.id)
|
||||
return (
|
||||
<div key={entry.id} className="metric flex min-h-44 flex-col p-4">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">{entry.name}</h3>
|
||||
<p className="mt-2 text-xs leading-5 text-[var(--foreground-dim)]">{entry.summary}</p>
|
||||
{entry.websiteUrl && (
|
||||
<a href={entry.websiteUrl} target="_blank" rel="noreferrer" className="mt-2 inline-block text-[11px] font-mono uppercase tracking-wider text-[var(--nvidia-green)] hover:underline">
|
||||
Setup Guide
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
<span className="status-chip bg-[var(--status-pending-bg)] px-2 py-1 text-[var(--status-pending)]">{entry.transport}</span>
|
||||
</div>
|
||||
<div className="mt-3 min-w-0 rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-2 font-mono text-[11px] text-[var(--foreground-dim)]">
|
||||
<span className="text-[var(--foreground)]">{entry.command}</span> {entry.args.join(" ")}
|
||||
</div>
|
||||
<div className="mt-auto flex items-center justify-between gap-3 pt-4">
|
||||
<p className="truncate text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{entry.tags.join(" / ")}</p>
|
||||
<button
|
||||
onClick={() => postUpdate({ action: "install", id: entry.id }, installed ? `${entry.name} refreshed.` : `${entry.name} installed.`)}
|
||||
disabled={saving}
|
||||
className={installed ? "action-button px-3 py-2" : "rounded-sm bg-[var(--nvidia-green)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"}
|
||||
>
|
||||
{installed ? "Refresh" : "Install"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="panel p-6">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setCustomOpen((open) => !open)}
|
||||
className="flex w-full items-center justify-between gap-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--nvidia-green)]"
|
||||
aria-expanded={customOpen}
|
||||
>
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Custom Server</h2>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Add a server command that is not in the catalog.</p>
|
||||
</div>
|
||||
<span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] text-sm text-[var(--foreground)]">
|
||||
{customOpen ? "-" : "+"}
|
||||
</span>
|
||||
</button>
|
||||
{customOpen && (
|
||||
<div className="mt-5 border-t border-[var(--border-subtle)] pt-5">
|
||||
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<FieldLabel>Name</FieldLabel>
|
||||
<input value={customName} onChange={(event) => setCustomName(event.target.value)} className="field-control w-full px-3 py-2 text-sm font-mono" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<FieldLabel>Transport</FieldLabel>
|
||||
<select value={customTransport} onChange={(event) => setCustomTransport(event.target.value as McpTransport)} className="field-control w-full px-3 py-2 text-sm font-mono">
|
||||
<option value="stdio">stdio</option>
|
||||
<option value="http">http</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<FieldLabel>Summary</FieldLabel>
|
||||
<input value={customSummary} onChange={(event) => setCustomSummary(event.target.value)} className="field-control w-full px-3 py-2 text-sm" />
|
||||
</div>
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<FieldLabel>{customTransport === "http" ? "URL" : "Command"}</FieldLabel>
|
||||
<input value={customCommand} onChange={(event) => 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" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<FieldLabel>Args</FieldLabel>
|
||||
<textarea value={customArgs} onChange={(event) => setCustomArgs(event.target.value)} rows={6} className="field-control w-full resize-y px-3 py-2 text-sm font-mono" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<FieldLabel>{customTransport === "http" ? "Headers" : "Env"}</FieldLabel>
|
||||
<textarea value={customEnv} onChange={(event) => setCustomEnv(event.target.value)} rows={6} placeholder={customTransport === "http" ? "Authorization=Bearer token" : "API_KEY=value\nBASE_URL=http://localhost:3000"} className="field-control w-full resize-y px-3 py-2 text-sm font-mono" />
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => postUpdate({
|
||||
action: "install",
|
||||
id: customName,
|
||||
name: customName,
|
||||
summary: customSummary,
|
||||
transport: customTransport,
|
||||
command: customCommand,
|
||||
args: parseLines(customArgs),
|
||||
env: parseEnv(customEnv),
|
||||
tags: ["custom"],
|
||||
source: "custom",
|
||||
}, `${customName} installed.`)}
|
||||
disabled={saving}
|
||||
className="mt-5 rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"
|
||||
>
|
||||
Install Custom Server
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<aside className="space-y-6">
|
||||
<div className="panel p-6">
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Installed Servers</h2>
|
||||
<div className="mt-4 space-y-3">
|
||||
{servers.length === 0 ? (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-xs text-[var(--foreground-dim)]">
|
||||
No MCP servers installed yet.
|
||||
</div>
|
||||
) : servers.map((server) => (
|
||||
<div key={server.id} className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<h3 className="truncate text-sm font-mono font-semibold text-[var(--foreground)]">{server.name}</h3>
|
||||
<p className="mt-1 text-[11px] text-[var(--foreground-dim)]">{server.source} / {server.transport}</p>
|
||||
</div>
|
||||
<span className={`status-chip px-2 py-1 ${server.enabled ? "bg-[var(--status-running-bg)] text-[var(--status-running)]" : "bg-[var(--status-pending-bg)] text-[var(--status-pending)]"}`}>
|
||||
{server.enabled ? "enabled" : "disabled"}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-3 break-all font-mono text-[11px] text-[var(--foreground-dim)]">{server.command} {server.args.join(" ")}</p>
|
||||
<div className="mt-4 flex gap-2">
|
||||
<button onClick={() => postUpdate({ action: server.enabled ? "disable" : "enable", serverId: server.id }, `${server.name} ${server.enabled ? "disabled" : "enabled"}.`)} disabled={saving} className="action-button flex-1 px-3 py-2">
|
||||
{server.enabled ? "Disable" : "Enable"}
|
||||
</button>
|
||||
<button onClick={() => postUpdate({ action: "uninstall", serverId: server.id }, `${server.name} removed.`)} disabled={saving} className="action-button flex-1 px-3 py-2">
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="panel p-6">
|
||||
<h2 className="text-sm font-semibold uppercase tracking-wider text-[var(--foreground)]">Client JSON</h2>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Enabled servers exported in common MCP client format.</p>
|
||||
<pre className="mt-4 max-h-96 overflow-auto rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4 text-[11px] leading-5 text-[var(--foreground-dim)]">
|
||||
{configText}
|
||||
</pre>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+238
-17
@@ -27,7 +27,16 @@ interface SandboxListProps {
|
||||
onInventoryRefresh: () => Promise<SandboxInventoryItem[]>
|
||||
}
|
||||
|
||||
type DrawerKey = 'operations' | 'files' | 'inference' | 'policy' | 'archive'
|
||||
type DrawerKey = 'operations' | 'files' | 'inference' | 'policy' | 'archive' | 'mcp'
|
||||
type McpServerAccess = {
|
||||
id: string
|
||||
name: string
|
||||
command: string
|
||||
args: string[]
|
||||
enabled: boolean
|
||||
accessMode: 'disabled' | 'allow_all' | 'allow_only'
|
||||
allowedSandboxIds: string[]
|
||||
}
|
||||
type NetworkRuleRequest = {
|
||||
chunkId: string
|
||||
status: string
|
||||
@@ -78,7 +87,7 @@ function DrawerSection({
|
||||
type="button"
|
||||
onClick={onToggle}
|
||||
aria-expanded={open}
|
||||
className="flex w-full items-center justify-between gap-4 p-5 text-left"
|
||||
className="flex w-full items-center justify-between gap-4 p-5 text-left transition-colors hover:bg-[var(--surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--nvidia-green)] max-sm:p-4"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<h4 className="text-sm font-semibold text-[var(--foreground)] uppercase tracking-wider">{title}</h4>
|
||||
@@ -95,7 +104,7 @@ function DrawerSection({
|
||||
</svg>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="border-t border-[var(--border-subtle)] p-6">
|
||||
<div className="border-t border-[var(--border-subtle)] p-6 max-sm:p-4">
|
||||
{children}
|
||||
</div>
|
||||
)}
|
||||
@@ -117,12 +126,17 @@ export default function SandboxList({
|
||||
const [permissionMessage, setPermissionMessage] = useState('')
|
||||
const [permissionFeeds, setPermissionFeeds] = useState<Record<string, PermissionFeed>>({})
|
||||
const [grantingSandboxId, setGrantingSandboxId] = useState<string | null>(null)
|
||||
const [mcpServers, setMcpServers] = useState<McpServerAccess[]>([])
|
||||
const [mcpMessage, setMcpMessage] = useState('')
|
||||
const [mcpUpdatingServerId, setMcpUpdatingServerId] = useState<string | null>(null)
|
||||
const [mcpSyncing, setMcpSyncing] = useState(false)
|
||||
const [openDrawers, setOpenDrawers] = useState<Record<DrawerKey, boolean>>({
|
||||
operations: true,
|
||||
files: false,
|
||||
inference: false,
|
||||
policy: false,
|
||||
archive: false,
|
||||
mcp: false,
|
||||
})
|
||||
const [telemetry, setTelemetry] = useState<TelemetryData>({
|
||||
cpu: 0, memory: 0, disk: 0, timestamp: new Date().toISOString()
|
||||
@@ -164,6 +178,30 @@ export default function SandboxList({
|
||||
}
|
||||
}, [sandboxes])
|
||||
|
||||
useEffect(() => {
|
||||
let active = true
|
||||
const loadMcpAccess = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/mcp', { cache: 'no-store' })
|
||||
const data = await response.json()
|
||||
if (!response.ok) throw new Error(data.error || 'Failed to load MCP access')
|
||||
if (active) setMcpServers(Array.isArray(data.servers) ? data.servers : [])
|
||||
} catch (error) {
|
||||
if (active) {
|
||||
setMcpServers([])
|
||||
setMcpMessage(error instanceof Error ? error.message : 'Failed to load MCP access')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadMcpAccess()
|
||||
const interval = window.setInterval(loadMcpAccess, 12000)
|
||||
return () => {
|
||||
active = false
|
||||
window.clearInterval(interval)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const fetchTelemetry = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/telemetry/combined')
|
||||
@@ -197,6 +235,84 @@ export default function SandboxList({
|
||||
setOpenDrawers((current) => ({ ...current, [key]: !current[key] }))
|
||||
}
|
||||
|
||||
const sandboxCanAccessMcpServer = (sandbox: SandboxInventoryItem, server: McpServerAccess) => {
|
||||
if (!server.enabled || server.accessMode === 'disabled') return false
|
||||
if (server.accessMode === 'allow_all') return true
|
||||
return server.allowedSandboxIds.includes(sandbox.id) || server.allowedSandboxIds.includes(sandbox.name)
|
||||
}
|
||||
|
||||
const allowedMcpServersForSandbox = (sandbox: SandboxInventoryItem) => (
|
||||
mcpServers.filter((server) => sandboxCanAccessMcpServer(sandbox, server))
|
||||
)
|
||||
|
||||
const updateMcpServerAccess = async (
|
||||
server: McpServerAccess,
|
||||
body: Partial<Pick<McpServerAccess, 'enabled' | 'accessMode' | 'allowedSandboxIds'>>,
|
||||
success: string,
|
||||
) => {
|
||||
try {
|
||||
setMcpUpdatingServerId(server.id)
|
||||
setMcpMessage('')
|
||||
const response = await fetch('/api/mcp', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'update-access', serverId: server.id, ...body }),
|
||||
})
|
||||
const data = await response.json()
|
||||
if (!response.ok) throw new Error(data.error || 'Failed to update MCP access')
|
||||
setMcpServers(Array.isArray(data.servers) ? data.servers : [])
|
||||
setMcpMessage(success)
|
||||
} catch (error) {
|
||||
setMcpMessage(error instanceof Error ? error.message : 'Failed to update MCP access')
|
||||
} finally {
|
||||
setMcpUpdatingServerId(null)
|
||||
}
|
||||
}
|
||||
|
||||
const syncMcpManifest = async (sandbox: SandboxInventoryItem) => {
|
||||
try {
|
||||
setMcpSyncing(true)
|
||||
setMcpMessage(`Issuing MCP broker config for ${sandbox.name}...`)
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/mcp`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ sandboxName: sandbox.name }),
|
||||
})
|
||||
const data = await response.json()
|
||||
if (!response.ok) throw new Error(data.error || 'Failed to issue MCP broker config')
|
||||
setMcpMessage(data.note || 'MCP broker config issued.')
|
||||
} catch (error) {
|
||||
setMcpMessage(error instanceof Error ? error.message : 'Failed to issue MCP broker config')
|
||||
} finally {
|
||||
setMcpSyncing(false)
|
||||
}
|
||||
}
|
||||
|
||||
const enableMcpForSandbox = (sandbox: SandboxInventoryItem, server: McpServerAccess) => {
|
||||
const current = new Set(server.allowedSandboxIds)
|
||||
current.add(sandbox.id)
|
||||
return updateMcpServerAccess(server, {
|
||||
enabled: true,
|
||||
accessMode: server.accessMode === 'allow_all' ? 'allow_all' : 'allow_only',
|
||||
allowedSandboxIds: Array.from(current),
|
||||
}, `${server.name} enabled for ${sandbox.name}.`).then(() => syncMcpManifest(sandbox))
|
||||
}
|
||||
|
||||
const revokeMcpForSandbox = (sandbox: SandboxInventoryItem, server: McpServerAccess) => {
|
||||
const current = new Set(server.allowedSandboxIds)
|
||||
current.delete(sandbox.id)
|
||||
current.delete(sandbox.name)
|
||||
if (server.accessMode === 'allow_all') {
|
||||
for (const item of sandboxes) {
|
||||
if (item.id !== sandbox.id) current.add(item.id)
|
||||
}
|
||||
}
|
||||
return updateMcpServerAccess(server, {
|
||||
accessMode: 'allow_only',
|
||||
allowedSandboxIds: Array.from(current),
|
||||
}, `${server.name} revoked from ${sandbox.name}.`).then(() => syncMcpManifest(sandbox))
|
||||
}
|
||||
|
||||
const resolvePermissionRequest = async (sandbox: SandboxInventoryItem, action: 'approve' | 'reject', chunkId: string) => {
|
||||
if (!chunkId) return
|
||||
try {
|
||||
@@ -234,7 +350,7 @@ export default function SandboxList({
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-end justify-between gap-4">
|
||||
<div className="flex items-end justify-between gap-4 max-sm:flex-col max-sm:items-start">
|
||||
<div>
|
||||
<p className="text-[10px] font-mono uppercase tracking-wider text-[var(--nvidia-green)]">
|
||||
Inventory
|
||||
@@ -252,16 +368,21 @@ export default function SandboxList({
|
||||
{sandboxes.map((sandbox) => (
|
||||
<div
|
||||
key={sandbox.id}
|
||||
className={`group overflow-hidden rounded border text-left transition-all ${
|
||||
className={`group overflow-hidden rounded border text-left transition-all duration-150 ${
|
||||
isDestroyMode
|
||||
? 'border-[var(--status-stopped)] bg-[var(--status-stopped-bg)] hover:shadow-[0_18px_60px_rgba(220,38,38,0.16)]'
|
||||
: selectedSandboxId === sandbox.id
|
||||
? 'border-[var(--nvidia-green)] bg-[var(--surface-hover)] shadow-[var(--shadow-glow)]'
|
||||
: 'border-[var(--border-subtle)] bg-[var(--surface-raised)] shadow-[var(--shadow-soft)] hover:border-[var(--nvidia-green)] hover:bg-[var(--surface-hover)]'
|
||||
: 'border-[var(--border-subtle)] bg-[var(--surface-raised)] shadow-[var(--shadow-soft)] hover:-translate-y-0.5 hover:border-[var(--nvidia-green)] hover:bg-[var(--surface-hover)]'
|
||||
}`}
|
||||
>
|
||||
<button type="button" onClick={() => onSandboxSelect(sandbox.id)} className="w-full p-4 text-left">
|
||||
<div className="flex items-center justify-between gap-3 mb-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onSandboxSelect(sandbox.id)}
|
||||
className="w-full p-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--nvidia-green)]"
|
||||
aria-pressed={selectedSandboxId === sandbox.id}
|
||||
>
|
||||
<div className="mb-3 flex items-start justify-between gap-3">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
{(() => {
|
||||
const feed = permissionFeeds[sandbox.id]
|
||||
@@ -276,7 +397,7 @@ export default function SandboxList({
|
||||
<span className="h-2.5 w-2.5 rounded-full bg-[var(--status-running)]" title={`Policy status: ${feed?.latest?.status || 'ok'}`} />
|
||||
)
|
||||
})()}
|
||||
<span className={`text-sm font-mono font-semibold truncate ${
|
||||
<span className={`truncate font-mono text-sm font-semibold ${
|
||||
isDestroyMode ? 'text-[var(--status-stopped)]' : 'text-[var(--foreground)]'
|
||||
}`}>
|
||||
{sandbox.name}
|
||||
@@ -284,6 +405,24 @@ export default function SandboxList({
|
||||
{sandbox.isDefault ? (
|
||||
<span className="rounded-full border border-[var(--border-subtle)] px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-[var(--foreground-dim)]">default</span>
|
||||
) : null}
|
||||
{(() => {
|
||||
const hasMcpAccess = allowedMcpServersForSandbox(sandbox).length > 0
|
||||
return (
|
||||
<span
|
||||
className={`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-sm border ${
|
||||
hasMcpAccess
|
||||
? 'border-[var(--nvidia-green)] bg-[var(--status-running-bg)] text-[var(--nvidia-green)]'
|
||||
: 'border-[var(--border-subtle)] bg-[var(--background-tertiary)] text-[var(--foreground-dim)] opacity-55'
|
||||
}`}
|
||||
title={hasMcpAccess ? 'MCP access allowed' : 'No MCP access allowed'}
|
||||
aria-label={hasMcpAccess ? 'MCP access allowed' : 'No MCP access allowed'}
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M7 8h10M7 16h10M9 4h6a2 2 0 012 2v12a2 2 0 01-2 2H9a2 2 0 01-2-2V6a2 2 0 012-2z" />
|
||||
</svg>
|
||||
</span>
|
||||
)
|
||||
})()}
|
||||
</div>
|
||||
<div className={`status-chip shrink-0 px-2.5 py-1 ${
|
||||
isDestroyMode
|
||||
@@ -300,15 +439,15 @@ export default function SandboxList({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<div className="space-y-1.5">
|
||||
{([
|
||||
['Attach Target', sandbox.ip, '180px'],
|
||||
['Namespace', sandbox.namespace, '120px'],
|
||||
['Host Alias', sandbox.sshHostAlias || 'N/A', '140px'],
|
||||
['Sandbox ID', sandbox.id, '140px'],
|
||||
] as Array<[string, string, string]>).map(([label, value, width]) => (
|
||||
<div key={label} className="flex items-center justify-between gap-3">
|
||||
<span className="text-[10px] uppercase text-[var(--foreground-dim)]">{label}</span>
|
||||
<div key={label} className="grid grid-cols-[6.5rem_minmax(0,1fr)] items-center gap-3">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{label}</span>
|
||||
<span className="text-xs font-mono truncate text-[var(--foreground)]" style={{ maxWidth: width }} title={value}>{value}</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -324,7 +463,7 @@ export default function SandboxList({
|
||||
event.currentTarget.value = ''
|
||||
resolvePermissionRequest(sandbox, 'approve', value)
|
||||
}}
|
||||
className="w-full rounded border border-[var(--border-subtle)] bg-[var(--background-tertiary)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-[var(--foreground)] focus:outline-none focus:ring-1 focus:ring-[var(--nvidia-green)]"
|
||||
className="field-control w-full px-3 py-2 font-mono text-xs uppercase tracking-wider"
|
||||
>
|
||||
<option value="">
|
||||
{grantingSandboxId === sandbox.id
|
||||
@@ -359,7 +498,7 @@ export default function SandboxList({
|
||||
onToggle={() => toggleDrawer('operations')}
|
||||
>
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center gap-3 flex-wrap">
|
||||
<div className="flex flex-wrap items-center gap-3 max-sm:[&>button]:w-full">
|
||||
<button
|
||||
onClick={async () => {
|
||||
try {
|
||||
@@ -410,7 +549,7 @@ export default function SandboxList({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="grid grid-cols-2 gap-4 md:grid-cols-4">
|
||||
<div className="metric p-4">
|
||||
<p className="text-[10px] text-[var(--foreground-dim)] uppercase tracking-wider">CPU</p>
|
||||
<p className="text-xl font-mono text-[var(--nvidia-green)] mt-1">{telemetry.cpu.toFixed(1)}%</p>
|
||||
@@ -449,6 +588,88 @@ export default function SandboxList({
|
||||
<SandboxInferencePanel sandbox={selectedSandbox} embedded showHeader={false} />
|
||||
</DrawerSection>
|
||||
|
||||
<DrawerSection
|
||||
title="Allowed MCP Server Access"
|
||||
summary="Enable, disable, or revoke MCP servers for this sandbox."
|
||||
open={openDrawers.mcp}
|
||||
onToggle={() => toggleDrawer('mcp')}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between gap-4 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 max-sm:flex-col max-sm:items-start">
|
||||
<div>
|
||||
<h4 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Sandbox Manifest</h4>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">
|
||||
Writes <span className="font-mono text-[var(--foreground)]">/sandbox/openshell_control_mcp.md</span> with broker URL and sandbox token only.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
disabled={mcpSyncing}
|
||||
onClick={() => syncMcpManifest(selectedSandbox)}
|
||||
className="action-button px-3 py-2 max-sm:w-full"
|
||||
>
|
||||
{mcpSyncing ? 'Issuing...' : 'Issue Broker Config'}
|
||||
</button>
|
||||
</div>
|
||||
{mcpMessage && (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3 text-xs text-[var(--foreground-dim)]">
|
||||
{mcpMessage}
|
||||
</div>
|
||||
)}
|
||||
{mcpServers.length === 0 ? (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-xs text-[var(--foreground-dim)]">
|
||||
No MCP servers are installed yet.
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-3 lg:grid-cols-2">
|
||||
{mcpServers.map((server) => {
|
||||
const hasAccess = sandboxCanAccessMcpServer(selectedSandbox, server)
|
||||
const updating = mcpUpdatingServerId === server.id
|
||||
return (
|
||||
<div key={server.id} className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<h4 className="truncate text-sm font-mono font-semibold text-[var(--foreground)]">{server.name}</h4>
|
||||
<p className="mt-1 break-all font-mono text-[11px] text-[var(--foreground-dim)]">{server.command} {server.args.join(' ')}</p>
|
||||
</div>
|
||||
<span className={`status-chip px-2 py-1 ${hasAccess ? 'bg-[var(--status-running-bg)] text-[var(--status-running)]' : 'bg-[var(--status-pending-bg)] text-[var(--status-pending)]'}`}>
|
||||
{hasAccess ? 'allowed' : 'blocked'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-4 flex gap-2 max-sm:flex-col">
|
||||
<button
|
||||
type="button"
|
||||
disabled={updating || hasAccess}
|
||||
onClick={() => enableMcpForSandbox(selectedSandbox, server)}
|
||||
className="action-button flex-1 px-3 py-2"
|
||||
>
|
||||
Enable
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={updating || !server.enabled}
|
||||
onClick={() => updateMcpServerAccess(server, { enabled: false }, `${server.name} disabled globally.`)}
|
||||
className="action-button flex-1 px-3 py-2"
|
||||
>
|
||||
Disable
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={updating || !hasAccess}
|
||||
onClick={() => revokeMcpForSandbox(selectedSandbox, server)}
|
||||
className="action-button flex-1 px-3 py-2"
|
||||
>
|
||||
Revoke
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DrawerSection>
|
||||
|
||||
<DrawerSection
|
||||
title="Sandbox Policy"
|
||||
summary="Approve or reject network requests raised by the sandbox."
|
||||
@@ -469,7 +690,7 @@ export default function SandboxList({
|
||||
|
||||
return pending.map((request) => (
|
||||
<div key={request.chunkId} className="rounded-sm border border-amber-400/60 bg-amber-400/10 p-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="flex items-start justify-between gap-4 max-md:flex-col">
|
||||
<div className="min-w-0 space-y-2">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="text-xs font-mono font-semibold text-[var(--foreground)]">
|
||||
@@ -486,7 +707,7 @@ export default function SandboxList({
|
||||
{request.binary || request.binaries.join(', ') || 'unknown binary'} / {request.chunkId}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-2">
|
||||
<div className="flex shrink-0 items-center gap-2 max-md:w-full max-md:[&>button]:flex-1">
|
||||
<button
|
||||
type="button"
|
||||
disabled={grantingSandboxId === selectedSandbox.id}
|
||||
|
||||
+36
-16
@@ -3,7 +3,7 @@
|
||||
interface SidebarProps {
|
||||
sandboxesRunning: number
|
||||
sandboxesTotal: number
|
||||
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards'
|
||||
activeView: 'settings' | 'sandboxes' | 'help' | 'wizards' | 'mcp'
|
||||
isCreateMode: boolean
|
||||
isDestroyMode: boolean
|
||||
onSandboxesClick: () => void
|
||||
@@ -11,6 +11,7 @@ interface SidebarProps {
|
||||
onDestroyClick: () => void
|
||||
onTerminalClick: () => void
|
||||
onSettingsClick: () => void
|
||||
onMcpClick: () => void
|
||||
onWizardsClick: () => void
|
||||
onHelpClick: () => void
|
||||
onExitMode: () => void
|
||||
@@ -29,18 +30,19 @@ export default function Sidebar({
|
||||
onDestroyClick,
|
||||
onTerminalClick,
|
||||
onSettingsClick,
|
||||
onMcpClick,
|
||||
onWizardsClick,
|
||||
onHelpClick,
|
||||
onExitMode,
|
||||
onLogout,
|
||||
terminalDisabled = false,
|
||||
}: SidebarProps) {
|
||||
const navItemClass = (active = false, danger = false) => `w-full flex items-center gap-3 px-3 py-2.5 rounded transition-colors ${
|
||||
const navItemClass = (active = false, danger = false) => `w-full flex items-center gap-3 rounded px-3 py-2.5 text-left transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--nvidia-green)] max-lg:min-w-24 max-lg:flex-col max-lg:justify-center max-lg:gap-1 max-lg:px-2 max-lg:py-2 ${
|
||||
active
|
||||
? danger
|
||||
? 'bg-[var(--status-stopped)] text-white shadow-[0_10px_28px_rgba(220,38,38,0.18)]'
|
||||
: 'bg-[var(--nvidia-green)] text-black shadow-[0_10px_28px_rgba(118,185,0,0.18)]'
|
||||
: 'hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]'
|
||||
: 'text-[var(--foreground-dim)] hover:bg-[var(--background-tertiary)] hover:text-[var(--foreground)]'
|
||||
}`
|
||||
|
||||
return (
|
||||
@@ -62,98 +64,116 @@ export default function Sidebar({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 p-2 max-lg:grid max-lg:grid-cols-4 max-lg:gap-1 max-lg:overflow-x-auto">
|
||||
<nav className="flex-1 p-2 max-lg:flex max-lg:gap-1 max-lg:overflow-x-auto max-lg:[scrollbar-width:none]">
|
||||
<button
|
||||
onClick={onSandboxesClick}
|
||||
className={navItemClass(activeView === 'sandboxes' && !isCreateMode && !isDestroyMode)}
|
||||
aria-current={activeView === 'sandboxes' && !isCreateMode && !isDestroyMode ? 'page' : undefined}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
|
||||
</svg>
|
||||
<span className="text-sm">Sandboxes</span>
|
||||
<span className="text-sm max-lg:text-[11px]">Sandboxes</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onCreateClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(isCreateMode)}`}
|
||||
aria-pressed={isCreateMode}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
<span className="text-sm">Create Sandbox</span>
|
||||
<span className="text-sm max-lg:text-[11px] max-lg:leading-tight">Create</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onDestroyClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(isDestroyMode, true)}`}
|
||||
aria-pressed={isDestroyMode}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M4 7h16" />
|
||||
</svg>
|
||||
<span className="text-sm">Destroy Sandbox</span>
|
||||
<span className="text-sm max-lg:text-[11px] max-lg:leading-tight">Destroy</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onTerminalClick}
|
||||
disabled={terminalDisabled}
|
||||
className="mt-1 max-lg:mt-0 w-full flex items-center gap-3 px-3 py-2.5 rounded transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:text-[var(--foreground)] disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
title={terminalDisabled ? 'Select a sandbox to open the operator terminal' : 'Open operator terminal'}
|
||||
className="mt-1 flex w-full items-center gap-3 rounded px-3 py-2.5 text-[var(--foreground-dim)] transition-all hover:bg-[var(--background-tertiary)] hover:text-[var(--foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--nvidia-green)] disabled:cursor-not-allowed disabled:opacity-40 max-lg:mt-0 max-lg:min-w-24 max-lg:flex-col max-lg:justify-center max-lg:gap-1 max-lg:px-2 max-lg:py-2"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M4 17l6-6-6-6m8 14h8" />
|
||||
</svg>
|
||||
<span className="text-sm">Operator Terminal</span>
|
||||
<span className="text-sm max-lg:text-[11px] max-lg:leading-tight">Terminal</span>
|
||||
</button>
|
||||
|
||||
{(isCreateMode || isDestroyMode) && (
|
||||
<button
|
||||
onClick={onExitMode}
|
||||
className="mt-1 w-full flex items-center gap-3 px-3 py-2.5 rounded bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:bg-[var(--background-panel)] transition-colors max-lg:col-span-2"
|
||||
className="mt-1 flex w-full items-center gap-3 rounded bg-[var(--background-tertiary)] px-3 py-2.5 text-[var(--foreground-dim)] transition-colors hover:bg-[var(--background-panel)] max-lg:mt-0 max-lg:min-w-24 max-lg:flex-col max-lg:justify-center max-lg:gap-1 max-lg:px-2 max-lg:py-2"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
<span className="text-sm">Cancel</span>
|
||||
<span className="text-sm max-lg:text-[11px]">Cancel</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={onSettingsClick}
|
||||
className={`mt-4 max-lg:mt-0 ${navItemClass(activeView === 'settings')}`}
|
||||
aria-current={activeView === 'settings' ? 'page' : undefined}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 6v6l4 2m5-2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
<span className="text-sm">Inference Endpoints</span>
|
||||
<span className="text-sm max-lg:text-[11px] max-lg:leading-tight">Inference</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onWizardsClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'wizards')}`}
|
||||
aria-current={activeView === 'wizards' ? 'page' : undefined}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 3l2.2 4.8L19 10l-4.8 2.2L12 17l-2.2-4.8L5 10l4.8-2.2L12 3zm6 12l.9 2.1L21 18l-2.1.9L18 21l-.9-2.1L15 18l2.1-.9L18 15z" />
|
||||
</svg>
|
||||
<span className="text-sm">Wizards</span>
|
||||
<span className="text-sm max-lg:text-[11px]">Wizards</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onMcpClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'mcp')}`}
|
||||
aria-current={activeView === 'mcp' ? 'page' : undefined}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M7 8h10M7 16h10M9 4h6a2 2 0 012 2v12a2 2 0 01-2 2H9a2 2 0 01-2-2V6a2 2 0 012-2z" />
|
||||
</svg>
|
||||
<span className="text-sm max-lg:text-[11px]">MCP</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onHelpClick}
|
||||
className={`mt-1 max-lg:mt-0 ${navItemClass(activeView === 'help')}`}
|
||||
aria-current={activeView === 'help' ? 'page' : undefined}
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M9.09 9a3 3 0 115.82 1c-.64.85-1.91 1.26-2.41 2.32V13m-.5 4h.01M12 3a9 9 0 100 18 9 9 0 000-18z" />
|
||||
</svg>
|
||||
<span className="text-sm">Help</span>
|
||||
<span className="text-sm max-lg:text-[11px]">Help</span>
|
||||
</button>
|
||||
|
||||
<a
|
||||
href="/setup-account"
|
||||
className="mt-1 max-lg:mt-0 w-full flex items-center gap-3 px-3 py-2.5 rounded transition-colors hover:bg-[var(--background-tertiary)] text-[var(--foreground-dim)] hover:text-[var(--foreground)]"
|
||||
className="mt-1 flex w-full items-center gap-3 rounded px-3 py-2.5 text-[var(--foreground-dim)] transition-colors hover:bg-[var(--background-tertiary)] hover:text-[var(--foreground)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--nvidia-green)] max-lg:mt-0 max-lg:min-w-24 max-lg:flex-col max-lg:justify-center max-lg:gap-1 max-lg:px-2 max-lg:py-2"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path strokeLinecap="square" strokeLinejoin="miter" strokeWidth={2} d="M12 12a4 4 0 100-8 4 4 0 000 8zm-7 9a7 7 0 0114 0" />
|
||||
</svg>
|
||||
<span className="text-sm">Setup Account</span>
|
||||
<span className="text-sm max-lg:text-[11px] max-lg:leading-tight">Account</span>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user