Add MCP server upload and editor
This commit is contained in:
@@ -79,6 +79,10 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
|||||||
const [customCommand, setCustomCommand] = useState("npx")
|
const [customCommand, setCustomCommand] = useState("npx")
|
||||||
const [customArgs, setCustomArgs] = useState("-y\n@modelcontextprotocol/server-memory")
|
const [customArgs, setCustomArgs] = useState("-y\n@modelcontextprotocol/server-memory")
|
||||||
const [customEnv, setCustomEnv] = useState("")
|
const [customEnv, setCustomEnv] = useState("")
|
||||||
|
const [uploadFileName, setUploadFileName] = useState("")
|
||||||
|
const [uploadText, setUploadText] = useState("")
|
||||||
|
const [editingServerId, setEditingServerId] = useState<string | null>(null)
|
||||||
|
const [editorText, setEditorText] = useState("")
|
||||||
const [registrySearch, setRegistrySearch] = useState("github")
|
const [registrySearch, setRegistrySearch] = useState("github")
|
||||||
const [registryResults, setRegistryResults] = useState<McpCatalogEntry[]>([])
|
const [registryResults, setRegistryResults] = useState<McpCatalogEntry[]>([])
|
||||||
const [registryLoading, setRegistryLoading] = useState(false)
|
const [registryLoading, setRegistryLoading] = useState(false)
|
||||||
@@ -151,6 +155,97 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
|||||||
}, `${server.name} sandbox access updated.`)
|
}, `${server.name} sandbox access updated.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function editableServerJson(server: McpServerInstall) {
|
||||||
|
return JSON.stringify({
|
||||||
|
id: server.id,
|
||||||
|
name: server.name,
|
||||||
|
summary: server.summary,
|
||||||
|
websiteUrl: server.websiteUrl || "",
|
||||||
|
transport: server.transport,
|
||||||
|
command: server.command,
|
||||||
|
args: server.args,
|
||||||
|
env: server.env,
|
||||||
|
tags: server.tags,
|
||||||
|
enabled: server.enabled,
|
||||||
|
accessMode: server.accessMode,
|
||||||
|
allowedSandboxIds: server.allowedSandboxIds,
|
||||||
|
source: server.source,
|
||||||
|
}, null, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function serverPayloadFromJson(text: string, fallbackId = "uploaded-server") {
|
||||||
|
const parsed = JSON.parse(text)
|
||||||
|
const firstMcpEntry = parsed?.mcpServers && typeof parsed.mcpServers === "object"
|
||||||
|
? Object.entries(parsed.mcpServers)[0]
|
||||||
|
: null
|
||||||
|
const id = firstMcpEntry?.[0] || parsed?.id || parsed?.name || fallbackId
|
||||||
|
const body = firstMcpEntry?.[1] && typeof firstMcpEntry[1] === "object" ? firstMcpEntry[1] as Record<string, unknown> : parsed
|
||||||
|
const command = typeof body?.command === "string"
|
||||||
|
? body.command
|
||||||
|
: typeof body?.url === "string"
|
||||||
|
? body.url
|
||||||
|
: typeof parsed?.command === "string"
|
||||||
|
? parsed.command
|
||||||
|
: typeof parsed?.url === "string"
|
||||||
|
? parsed.url
|
||||||
|
: ""
|
||||||
|
const transport = body?.url || parsed?.transport === "http" ? "http" : "stdio"
|
||||||
|
|
||||||
|
return {
|
||||||
|
action: "install",
|
||||||
|
id,
|
||||||
|
name: parsed?.name || id,
|
||||||
|
summary: parsed?.summary || "Uploaded MCP server",
|
||||||
|
websiteUrl: parsed?.websiteUrl || "",
|
||||||
|
transport,
|
||||||
|
command,
|
||||||
|
args: Array.isArray(body?.args) ? body.args : Array.isArray(parsed?.args) ? parsed.args : [],
|
||||||
|
env: typeof body?.env === "object" && body.env ? body.env : typeof body?.headers === "object" && body.headers ? body.headers : parsed?.env || {},
|
||||||
|
tags: Array.isArray(parsed?.tags) ? parsed.tags : ["uploaded"],
|
||||||
|
source: parsed?.source || "custom",
|
||||||
|
enabled: typeof parsed?.enabled === "boolean" ? parsed.enabled : true,
|
||||||
|
accessMode: parsed?.accessMode,
|
||||||
|
allowedSandboxIds: parsed?.allowedSandboxIds,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function chooseUploadFile(file: File | null) {
|
||||||
|
if (!file) return
|
||||||
|
setUploadFileName(file.name)
|
||||||
|
setUploadText(await file.text())
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadServer() {
|
||||||
|
try {
|
||||||
|
if (!uploadText.trim()) {
|
||||||
|
setMessage("Choose a JSON MCP server file before uploading.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const fallbackId = uploadFileName.replace(/\.[^.]+$/, "") || "uploaded-server"
|
||||||
|
await postUpdate(serverPayloadFromJson(uploadText, fallbackId), `${fallbackId} uploaded.`)
|
||||||
|
setUploadText("")
|
||||||
|
setUploadFileName("")
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error instanceof Error ? error.message : "Failed to upload MCP server JSON")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEditingServer(server: McpServerInstall) {
|
||||||
|
setEditingServerId(server.id)
|
||||||
|
setEditorText(editableServerJson(server))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveEditedServer() {
|
||||||
|
try {
|
||||||
|
const payload = serverPayloadFromJson(editorText, editingServerId || "edited-server")
|
||||||
|
await postUpdate(payload, `${String(payload.name || payload.id)} updated.`)
|
||||||
|
setEditingServerId(null)
|
||||||
|
setEditorText("")
|
||||||
|
} catch (error) {
|
||||||
|
setMessage(error instanceof Error ? error.message : "Failed to save MCP server JSON")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function searchRegistry() {
|
async function searchRegistry() {
|
||||||
const query = registrySearch.trim()
|
const query = registrySearch.trim()
|
||||||
try {
|
try {
|
||||||
@@ -492,6 +587,7 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
|||||||
<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" />
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="mt-5 flex flex-wrap items-center gap-3">
|
||||||
<button
|
<button
|
||||||
onClick={() => postUpdate({
|
onClick={() => postUpdate({
|
||||||
action: "install",
|
action: "install",
|
||||||
@@ -506,10 +602,28 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
|||||||
source: "custom",
|
source: "custom",
|
||||||
}, `${customName} installed.`)}
|
}, `${customName} installed.`)}
|
||||||
disabled={saving}
|
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"
|
className="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
|
Install Custom Server
|
||||||
</button>
|
</button>
|
||||||
|
<label className="action-button cursor-pointer px-4 py-2">
|
||||||
|
Choose JSON
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept="application/json,.json"
|
||||||
|
onChange={(event) => chooseUploadFile(event.target.files?.[0] || null)}
|
||||||
|
className="sr-only"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
onClick={uploadServer}
|
||||||
|
disabled={saving || !uploadText.trim()}
|
||||||
|
className="action-button px-4 py-2"
|
||||||
|
>
|
||||||
|
Upload Server
|
||||||
|
</button>
|
||||||
|
{uploadFileName && <span className="text-xs font-mono text-[var(--foreground-dim)]">{uploadFileName}</span>}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -536,6 +650,9 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
|||||||
</div>
|
</div>
|
||||||
<p className="mt-3 break-all font-mono text-[11px] text-[var(--foreground-dim)]">{server.command} {server.args.join(" ")}</p>
|
<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">
|
<div className="mt-4 flex gap-2">
|
||||||
|
<button onClick={() => startEditingServer(server)} disabled={saving} className="action-button flex-1 px-3 py-2">
|
||||||
|
Edit
|
||||||
|
</button>
|
||||||
<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">
|
<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"}
|
{server.enabled ? "Disable" : "Enable"}
|
||||||
</button>
|
</button>
|
||||||
@@ -543,6 +660,28 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
|||||||
Remove
|
Remove
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{editingServerId === server.id && (
|
||||||
|
<div className="mt-4 border-t border-[var(--border-subtle)] pt-4">
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<FieldLabel>Server JSON</FieldLabel>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button onClick={() => { setEditingServerId(null); setEditorText("") }} disabled={saving} className="action-button px-3 py-2">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button onClick={saveEditedServer} disabled={saving || !editorText.trim()} className="rounded-sm bg-[var(--nvidia-green)] px-3 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
value={editorText}
|
||||||
|
onChange={(event) => setEditorText(event.target.value)}
|
||||||
|
rows={16}
|
||||||
|
spellCheck={false}
|
||||||
|
className="field-control mt-3 min-h-80 w-full resize-y px-3 py-2 text-xs font-mono leading-5"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -87,6 +87,11 @@ assert.match(registryRouteSource, /normalizeRegistryEntry/, 'MCP registry search
|
|||||||
assert.match(registryRouteSource, /packageInstall/, 'MCP registry search should support package-backed stdio installs')
|
assert.match(registryRouteSource, /packageInstall/, 'MCP registry search should support package-backed stdio installs')
|
||||||
assert.match(registryRouteSource, /remoteInstall/, 'MCP registry search should support remote HTTP installs')
|
assert.match(registryRouteSource, /remoteInstall/, 'MCP registry search should support remote HTTP installs')
|
||||||
assert.match(panelSource, /Install Custom Server/, 'MCP page must expose a custom server install action')
|
assert.match(panelSource, /Install Custom Server/, 'MCP page must expose a custom server install action')
|
||||||
|
assert.match(panelSource, /Upload Server/, 'MCP custom server accordion must support uploaded server JSON')
|
||||||
|
assert.match(panelSource, /serverPayloadFromJson/, 'MCP page must parse uploaded and edited server JSON')
|
||||||
|
assert.match(panelSource, /mcpServers/, 'MCP page upload must support common MCP client JSON')
|
||||||
|
assert.match(panelSource, /startEditingServer/, 'MCP installed server list must expose edit state')
|
||||||
|
assert.match(panelSource, /Server JSON/, 'MCP installed server editor must render an inline JSON file editor')
|
||||||
assert.match(panelSource, /Registry Search/, 'MCP page must expose official registry search')
|
assert.match(panelSource, /Registry Search/, 'MCP page must expose official registry search')
|
||||||
assert.match(panelSource, /\/api\/mcp\/registry/, 'MCP page must query the registry search API')
|
assert.match(panelSource, /\/api\/mcp\/registry/, 'MCP page must query the registry search API')
|
||||||
assert.match(panelSource, /const REGISTRY_PAGE_SIZE = 4/, 'MCP registry search should page results four at a time')
|
assert.match(panelSource, /const REGISTRY_PAGE_SIZE = 4/, 'MCP registry search should page results four at a time')
|
||||||
|
|||||||
Reference in New Issue
Block a user