Refine MCP server install wizard flow

This commit is contained in:
Codex
2026-04-29 16:24:23 +00:00
parent fba5f64164
commit 4ece66c4e4
5 changed files with 555 additions and 175 deletions
+213 -32
View File
@@ -15,6 +15,7 @@ const UPLOAD_DIR = path.join(STORE_DIR, "mcp-server-uploads")
const MAX_UPLOAD_BYTES = Number.parseInt(process.env.MCP_SERVER_UPLOAD_MAX_BYTES || String(128 * 1024 * 1024), 10)
const INSTALL_TIMEOUT_MS = Number.parseInt(process.env.MCP_SERVER_DEPENDENCY_INSTALL_TIMEOUT_MS || String(5 * 60 * 1000), 10)
const ENTRY_MODES = new Set(["file", "python-module", "console-script"])
const UPLOAD_MODES = new Set(["stage", "preflight", "install-staged"])
function slugify(value: string) {
return value
@@ -48,6 +49,11 @@ function normalizeEntryMode(value: unknown) {
return ENTRY_MODES.has(mode) ? mode : "file"
}
function normalizeUploadMode(value: unknown) {
const mode = String(value || "").trim()
return UPLOAD_MODES.has(mode) ? mode : ""
}
function normalizeRelativePath(value: string) {
const normalized = path.posix.normalize(value.replace(/\\/g, "/")).replace(/^\/+/, "")
if (!normalized || normalized === "." || normalized.startsWith("../") || normalized.includes("/../")) {
@@ -85,6 +91,16 @@ async function pathExists(candidate: string) {
}
}
async function ensureUploadRoot(id: string) {
const root = path.resolve(UPLOAD_DIR, id)
const uploadRoot = path.resolve(UPLOAD_DIR)
if (root !== uploadRoot && !root.startsWith(`${uploadRoot}${path.sep}`)) {
throw new Error("staged upload id must stay inside the MCP upload directory")
}
if (!await pathExists(root)) throw new Error("staged MCP server upload was not found")
return root
}
async function findFileByName(root: string, fileName: string): Promise<string | null> {
const entries = await readdir(root, { withFileTypes: true }).catch(() => [])
for (const entry of entries) {
@@ -239,6 +255,67 @@ async function launchCommandForUpload(
return { command: bootstrap.command, args: [entrypointPath, ...extraArgs] }
}
async function buildUploadCandidate({
root,
id,
name,
summary,
runtime,
entryMode,
entrypoint,
args,
env,
}: {
root: string
id: string
name: string
summary: string
runtime: string
entryMode: string
entrypoint: string
args: string[]
env: Record<string, string>
}) {
const entrypointPath = entryMode === "file" ? await resolveEntryPath(root, entrypoint) : null
const projectRoot = await resolveProjectRoot(root, entrypointPath)
const bootstrap = await bootstrapUploadedServer(projectRoot, runtime, entrypoint)
const launch = await launchCommandForUpload(projectRoot, bootstrap, entryMode, entrypoint, entrypointPath, args)
const candidate = {
id,
name,
summary,
transport: "stdio",
command: launch.command,
args: launch.args,
env,
tags: ["uploaded", "custom"],
source: "custom",
enabled: true,
} satisfies {
id: string
name: string
summary: string
transport: "stdio"
command: string
args: string[]
env: Record<string, string>
tags: string[]
source: "custom"
enabled: boolean
}
return { candidate, projectRoot, bootstrap }
}
function installCandidateFrom(candidate: Awaited<ReturnType<typeof buildUploadCandidate>>["candidate"]): McpServerInstall {
return {
...candidate,
installedAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
accessMode: "disabled",
allowedSandboxIds: [],
}
}
async function writeDirectoryUpload(form: FormData, root: string) {
const files = form.getAll("files")
const paths = form.getAll("paths").map((item) => String(item || ""))
@@ -290,6 +367,7 @@ async function writeArchiveUpload(form: FormData, root: string) {
export async function POST(request: Request) {
try {
const form = await request.formData()
const mode = normalizeUploadMode(form.get("mode"))
const name = String(form.get("name") || "uploaded-server").trim()
const id = slugify(String(form.get("id") || name))
const summary = String(form.get("summary") || "Uploaded MCP server").trim()
@@ -303,6 +381,110 @@ export async function POST(request: Request) {
if (!runtime) throw new Error("runtime command is required")
if (!entrypoint) throw new Error("entrypoint is required")
if (mode === "preflight" || mode === "install-staged") {
const root = await ensureUploadRoot(id)
const { candidate: initialCandidate, projectRoot, bootstrap } = await buildUploadCandidate({
root,
id,
name,
summary,
runtime,
entryMode,
entrypoint,
args: parseLines(form.get("args")),
env: parseEnv(form.get("env")),
})
let candidate = initialCandidate
if (mode === "preflight") {
let preflight = await preflightMcpServer(installCandidateFrom(candidate))
let repair: McpPreflightRepairResult | null = null
if (!preflight.ok && repairEnabled) {
try {
repair = await repairUploadedMcpServerWithLlm({
uploadRoot: root,
projectRoot,
server: installCandidateFrom(candidate),
preflight,
dependencyLogs: bootstrap.logs,
sandboxId: sandboxId || null,
})
if (repair.updatedServer) {
candidate = {
...candidate,
command: repair.updatedServer.command,
args: repair.updatedServer.args,
env: repair.updatedServer.env,
}
}
if (repair.ok) {
preflight = await preflightMcpServer(installCandidateFrom(candidate))
}
} catch (error) {
repair = {
attempted: true,
ok: false,
provider: "openai-compatible",
model: "",
baseUrl: process.env.MCP_PREFLIGHT_LLM_BASE_URL || process.env.OPENAI_BASE_URL || process.env.VLLM_BASE_URL || "",
summary: "LLM-assisted repair could not complete.",
changes: [],
error: error instanceof Error ? error.message : "MCP repair failed",
}
}
}
return NextResponse.json({
ok: true,
stagedUpload: {
id,
name,
summary,
runtime,
entryMode,
entrypoint,
uploadRoot: root,
projectRoot,
},
candidate,
dependencyInstall: {
kind: bootstrap.kind,
logs: bootstrap.logs,
},
preflight,
repair,
})
}
const command = String(form.get("command") || candidate.command).trim()
const commandArgs = parseLines(form.get("commandArgs"))
const suppliedArgs = commandArgs.length > 0 ? commandArgs : candidate.args
const installEnvText = String(form.get("installEnv") || "")
const suppliedEnv = installEnvText ? parseEnv(installEnvText) : candidate.env
const preflightOk = String(form.get("preflightOk") || "true") !== "false"
const server = await installMcpServer({
...candidate,
command: command || candidate.command,
args: suppliedArgs,
env: suppliedEnv,
enabled: preflightOk,
tags: preflightOk ? candidate.tags : [...candidate.tags, "preflight-failed"],
})
return NextResponse.json({
ok: true,
server,
uploadRoot: root,
projectRoot,
dependencyInstall: {
kind: bootstrap.kind,
logs: bootstrap.logs,
},
...(await listMcpServers()),
})
}
await rm(root, { recursive: true, force: true })
await mkdir(root, { recursive: true, mode: 0o700 })
@@ -310,41 +492,40 @@ export async function POST(request: Request) {
const uploadedArchive = uploadedDirectory ? false : await writeArchiveUpload(form, root)
if (!uploadedDirectory && !uploadedArchive) throw new Error("choose a directory, .zip, .tgz, .tar.gz, or .tar server upload")
const entrypointPath = entryMode === "file" ? await resolveEntryPath(root, entrypoint) : null
const projectRoot = await resolveProjectRoot(root, entrypointPath)
const bootstrap = await bootstrapUploadedServer(projectRoot, runtime, entrypoint)
const launch = await launchCommandForUpload(projectRoot, bootstrap, entryMode, entrypoint, entrypointPath, parseLines(form.get("args")))
let candidate = {
if (mode === "stage") {
const entrypointPath = entryMode === "file" ? await resolveEntryPath(root, entrypoint).catch(() => null) : null
const projectRoot = entrypointPath ? await resolveProjectRoot(root, entrypointPath) : await resolveProjectRoot(root, null)
return NextResponse.json({
ok: true,
stagedUpload: {
id,
name,
summary,
runtime,
entryMode,
entrypoint,
uploadRoot: root,
projectRoot,
selectedBundle: uploadedArchive ? "archive" : "directory",
},
})
}
const built = await buildUploadCandidate({
root,
id,
name,
summary,
transport: "stdio",
command: launch.command,
args: launch.args,
runtime,
entryMode,
entrypoint,
args: parseLines(form.get("args")),
env: parseEnv(form.get("env")),
tags: ["uploaded", "custom"],
source: "custom",
enabled: true,
} satisfies {
id: string
name: string
summary: string
transport: "stdio"
command: string
args: string[]
env: Record<string, string>
tags: string[]
source: "custom"
enabled: boolean
}
const installCandidate = (): McpServerInstall => ({
...candidate,
installedAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
accessMode: "disabled",
allowedSandboxIds: [],
})
let preflight = await preflightMcpServer(installCandidate())
let candidate = built.candidate
const projectRoot = built.projectRoot
const bootstrap = built.bootstrap
let preflight = await preflightMcpServer(installCandidateFrom(candidate))
let repair: McpPreflightRepairResult | null = null
if (!preflight.ok && repairEnabled) {
@@ -352,7 +533,7 @@ export async function POST(request: Request) {
repair = await repairUploadedMcpServerWithLlm({
uploadRoot: root,
projectRoot,
server: installCandidate(),
server: installCandidateFrom(candidate),
preflight,
dependencyLogs: bootstrap.logs,
sandboxId: sandboxId || null,
@@ -366,7 +547,7 @@ export async function POST(request: Request) {
}
}
if (repair.ok) {
preflight = await preflightMcpServer(installCandidate())
preflight = await preflightMcpServer(installCandidateFrom(candidate))
}
} catch (error) {
repair = {
+246 -136
View File
@@ -83,6 +83,18 @@ type McpInstallSuggestion = {
notes?: string
}
type StagedMcpUpload = {
id: string
name: string
summary: string
runtime: string
entryMode: "file" | "python-module" | "console-script"
entrypoint: string
uploadRoot: string
projectRoot: string
selectedBundle?: string
}
type McpSandbox = {
id: string
name: string
@@ -94,8 +106,14 @@ type McpConfigurationPanelProps = {
}
const REGISTRY_PAGE_SIZE = 4
const WIZARD_STEPS = ["basics", "launch", "upload", "review"] as const
const WIZARD_STEPS = ["upload", "preflight", "review", "install"] as const
type WizardStep = typeof WIZARD_STEPS[number]
const WIZARD_STEP_LABELS: Record<WizardStep, string> = {
upload: "Upload Server Files",
preflight: "Preflight Check",
review: "Review",
install: "Install",
}
function FieldLabel({ children }: { children: React.ReactNode }) {
return <label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{children}</label>
@@ -157,6 +175,12 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
const [uploadEntrypoint, setUploadEntrypoint] = useState("server.py")
const [uploadRepair, setUploadRepair] = useState(true)
const [repairSandboxId, setRepairSandboxId] = useState("")
const [stagedUpload, setStagedUpload] = useState<StagedMcpUpload | null>(null)
const [wizardPreflight, setWizardPreflight] = useState<McpPreflightResult | null>(null)
const [wizardRepair, setWizardRepair] = useState<McpPreflightRepairResult | null>(null)
const [wizardCandidate, setWizardCandidate] = useState<McpCatalogEntry | null>(null)
const [wizardDependencyInstall, setWizardDependencyInstall] = useState<{ kind?: string; logs?: string[] } | null>(null)
const [wizardInstallResult, setWizardInstallResult] = useState<McpServerInstall | null>(null)
const [installPrompt, setInstallPrompt] = useState("")
const [installAssistNotes, setInstallAssistNotes] = useState("")
const [editingServerId, setEditingServerId] = useState<string | null>(null)
@@ -178,7 +202,7 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
const [repoOpen, setRepoOpen] = useState(true)
const [catalogOpen, setCatalogOpen] = useState(false)
const [customOpen, setCustomOpen] = useState(false)
const [wizardStep, setWizardStep] = useState<WizardStep>("basics")
const [wizardStep, setWizardStep] = useState<WizardStep>("upload")
const installedIds = useMemo(() => new Set(servers.map((server) => server.id)), [servers])
const enabledCount = servers.filter((server) => server.enabled).length
@@ -322,7 +346,7 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
const data = await response.json() as { suggestion?: McpInstallSuggestion; error?: string }
if (!response.ok || !data.suggestion) throw new Error(data.error || "Failed to draft MCP install")
applyInstallSuggestion(data.suggestion)
setWizardStep("launch")
setWizardStep("upload")
setMessage("Install wizard fields drafted from the running LLM endpoint.")
} catch (error) {
setMessage(error instanceof Error ? error.message : "Failed to draft MCP install")
@@ -501,6 +525,7 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
return withRelativePath.webkitRelativePath || file.name
}))
if (files.length > 0) setUploadArchive(null)
resetWizardPreflightState()
}
function chooseUploadArchive(file: File | null) {
@@ -509,6 +534,16 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
setUploadFiles([])
setUploadPaths([])
}
resetWizardPreflightState()
}
function resetWizardPreflightState() {
setStagedUpload(null)
setWizardPreflight(null)
setWizardRepair(null)
setWizardCandidate(null)
setWizardDependencyInstall(null)
setWizardInstallResult(null)
}
function summarizePreflight(preflight: McpPreflightResult) {
@@ -553,24 +588,29 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
}
}
async function uploadServer() {
function appendWizardMetadata(form: FormData) {
form.set("id", customName)
form.set("name", customName)
form.set("summary", customSummary)
form.set("runtime", uploadRuntime)
form.set("entryMode", uploadEntryMode)
form.set("entrypoint", uploadEntrypoint)
form.set("args", customArgs)
form.set("env", customEnv)
form.set("repair", uploadRepair ? "true" : "false")
if (repairSandboxId) form.set("sandboxId", repairSandboxId)
}
async function stageUploadServer() {
try {
if (!uploadArchive && uploadFiles.length === 0) {
setMessage("Choose a server directory or archive before uploading.")
return
return false
}
setSaving(true)
const form = new FormData()
form.set("id", customName)
form.set("name", customName)
form.set("summary", customSummary)
form.set("runtime", uploadRuntime)
form.set("entryMode", uploadEntryMode)
form.set("entrypoint", uploadEntrypoint)
form.set("args", customArgs)
form.set("env", customEnv)
form.set("repair", uploadRepair ? "true" : "false")
if (repairSandboxId) form.set("sandboxId", repairSandboxId)
form.set("mode", "stage")
appendWizardMetadata(form)
if (uploadArchive) {
form.set("archive", uploadArchive)
} else {
@@ -580,30 +620,113 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
})
}
const response = await fetch("/api/mcp/upload", { method: "POST", body: form })
const data = await response.json() as McpResponse & { dependencyInstall?: { kind?: string; logs?: string[] }; preflight?: McpPreflightResult; repair?: McpPreflightRepairResult; server?: McpServerInstall }
if (!response.ok) throw new Error(data.error || "Failed to upload MCP server")
const data = await response.json() as { stagedUpload?: StagedMcpUpload; error?: string }
if (!response.ok || !data.stagedUpload) throw new Error(data.error || "Failed to upload MCP server files")
setStagedUpload(data.stagedUpload)
setWizardPreflight(null)
setWizardRepair(null)
setWizardCandidate(null)
setWizardDependencyInstall(null)
setWizardInstallResult(null)
setMessage(`${data.stagedUpload.name} files uploaded. Continue to preflight when ready.`)
return true
} catch (error) {
setMessage(error instanceof Error ? error.message : "Failed to upload MCP server files")
return false
} finally {
setSaving(false)
}
}
async function startWizardPreflightChecks() {
try {
if (!stagedUpload) {
setMessage("Upload server files before starting preflight checks.")
return
}
setSaving(true)
const form = new FormData()
form.set("mode", "preflight")
appendWizardMetadata(form)
const response = await fetch("/api/mcp/upload", { method: "POST", body: form })
const data = await response.json() as {
stagedUpload?: StagedMcpUpload
candidate?: McpCatalogEntry
dependencyInstall?: { kind?: string; logs?: string[] }
preflight?: McpPreflightResult
repair?: McpPreflightRepairResult
error?: string
}
if (!response.ok || !data.preflight || !data.candidate) throw new Error(data.error || "Failed to preflight MCP server")
setStagedUpload(data.stagedUpload || stagedUpload)
setWizardCandidate(data.candidate)
setWizardDependencyInstall(data.dependencyInstall || null)
setWizardPreflight(data.preflight)
setWizardRepair(data.repair || null)
const installKind = data.dependencyInstall?.kind || "generic"
const installLogCount = data.dependencyInstall?.logs?.filter(Boolean).length || 0
setMessage(`Preflight ${data.preflight.ok ? "passed" : "found failures"}. ${installKind === "generic" ? "No dependency bootstrap was needed." : `${installKind} dependencies bootstrapped${installLogCount > 0 ? ` with ${installLogCount} install step${installLogCount === 1 ? "" : "s"}` : ""}.`}${summarizeRepair(data.repair)}\n${summarizePreflight(data.preflight)}`)
} catch (error) {
setMessage(error instanceof Error ? error.message : "Failed to preflight MCP server")
} finally {
setSaving(false)
}
}
async function installStagedUpload() {
try {
if (!stagedUpload || !wizardCandidate) {
setMessage("Run preflight before installing this MCP server.")
return
}
setSaving(true)
const form = new FormData()
form.set("mode", "install-staged")
appendWizardMetadata(form)
form.set("command", wizardCandidate.command)
form.set("commandArgs", wizardCandidate.args.join("\n"))
form.set("installEnv", envToText(wizardCandidate.env))
form.set("preflightOk", wizardPreflight?.ok ? "true" : "false")
const response = await fetch("/api/mcp/upload", { method: "POST", body: form })
const data = await response.json() as McpResponse & { server?: McpServerInstall; error?: string }
if (!response.ok || !data.server) throw new Error(data.error || "Failed to install staged MCP server")
setCatalog(Array.isArray(data.catalog) ? data.catalog : catalog)
setServers(Array.isArray(data.servers) ? data.servers : [])
setConfig(data.config || { mcpServers: {} })
if (data.preflight && data.server?.id) {
setPreflightResults((current) => ({ ...current, [data.server!.id]: data.preflight as McpPreflightResult }))
setWizardInstallResult(data.server)
if (wizardPreflight) {
setPreflightResults((current) => ({ ...current, [data.server!.id]: wizardPreflight }))
}
setUploadFiles([])
setUploadPaths([])
setUploadArchive(null)
const installKind = data.dependencyInstall?.kind || "generic"
const installLogCount = data.dependencyInstall?.logs?.filter(Boolean).length || 0
const preflightNote = data.preflight
? `\nPreflight ${data.preflight.ok ? "passed" : "failed; server saved disabled"}.\n${summarizePreflight(data.preflight)}`
: ""
setMessage(`${customName} uploaded. ${installKind === "generic" ? "No dependency bootstrap was needed." : `${installKind} dependencies bootstrapped${installLogCount > 0 ? ` with ${installLogCount} install step${installLogCount === 1 ? "" : "s"}` : ""}.`}${summarizeRepair(data.repair)}${preflightNote}`)
setMessage(`${data.server.name} installed${data.server.enabled ? "." : " disabled because preflight did not pass."}`)
} catch (error) {
setMessage(error instanceof Error ? error.message : "Failed to upload MCP server")
setMessage(error instanceof Error ? error.message : "Failed to install staged MCP server")
} finally {
setSaving(false)
}
}
async function handleWizardNext() {
if (wizardStep === "upload") {
const staged = stagedUpload ? true : await stageUploadServer()
if (staged) nextWizardStep()
return
}
if (wizardStep === "preflight") {
if (!wizardPreflight) {
setMessage("Start preflight checks before reviewing this MCP server.")
return
}
nextWizardStep()
return
}
if (wizardStep === "review") {
nextWizardStep()
}
}
function startEditingServer(server: McpServerInstall) {
setEditingServerId(server.id)
setEditorText(editableServerJson(server))
@@ -960,72 +1083,34 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
{customOpen && (
<div className="mt-5 border-t border-[var(--border-subtle)] pt-5">
<div className="mb-5 grid grid-cols-2 gap-2 md:grid-cols-4">
{(["basics", "launch", "upload", "review"] as const).map((step) => (
{WIZARD_STEPS.map((step) => (
<button
key={step}
type="button"
onClick={() => setWizardStep(step)}
className={`rounded-sm border px-3 py-2 text-xs font-mono uppercase tracking-wider ${wizardStep === step ? "border-[var(--nvidia-green)] bg-[var(--status-running-bg)] text-[var(--foreground)]" : "border-[var(--border-subtle)] bg-[var(--background)] text-[var(--foreground-dim)]"}`}
>
{step}
{WIZARD_STEP_LABELS[step]}
</button>
))}
</div>
{wizardStep === "basics" && (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div className="space-y-2 md:col-span-2">
<div className="flex items-center gap-2"><FieldLabel>Assist Install</FieldLabel><FieldHint>Describe the MCP server and the running LLM endpoint will draft the install fields.</FieldHint></div>
<textarea value={installPrompt} onChange={(event) => setInstallPrompt(event.target.value)} rows={4} placeholder="Install the GitHub MCP server with npx, or prepare this uploaded Python MCP bundle." className="field-control w-full resize-y px-3 py-2 text-sm" />
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Name</FieldLabel><FieldHint>Stable display name and default id for this MCP server.</FieldHint></div>
<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">
<div className="flex items-center gap-2"><FieldLabel>Transport</FieldLabel><FieldHint>Use stdio for local commands, HTTP for remote streamable MCP endpoints.</FieldHint></div>
<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">
<div className="flex items-center gap-2"><FieldLabel>Summary</FieldLabel><FieldHint>Short note shown in the installed server list.</FieldHint></div>
<input value={customSummary} onChange={(event) => setCustomSummary(event.target.value)} className="field-control w-full px-3 py-2 text-sm" />
</div>
{installAssistNotes && (
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 text-xs text-[var(--foreground-dim)] md:col-span-2">
{installAssistNotes}
</div>
)}
</div>
)}
{wizardStep === "launch" && (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div className="space-y-2 md:col-span-2">
<div className="flex items-center gap-2"><FieldLabel>{customTransport === "http" ? "URL" : "Command"}</FieldLabel><FieldHint>{customTransport === "http" ? "Full remote MCP endpoint URL." : "Executable available to the controller, such as npx, uvx, node, or python."}</FieldHint></div>
<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">
<div className="flex items-center gap-2"><FieldLabel>Args</FieldLabel><FieldHint>One argument per line, passed to the command in order.</FieldHint></div>
<textarea value={customArgs} onChange={(event) => setCustomArgs(event.target.value)} rows={8} className="field-control w-full resize-y px-3 py-2 text-sm font-mono" />
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>{customTransport === "http" ? "Headers" : "Env"}</FieldLabel><FieldHint>KEY=value lines. HTTP entries become headers; stdio entries become environment variables.</FieldHint></div>
<textarea value={customEnv} onChange={(event) => setCustomEnv(event.target.value)} rows={8} 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>
)}
{wizardStep === "upload" && (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Server Name</FieldLabel><FieldHint>Stable display name and default id for this uploaded MCP server.</FieldHint></div>
<input value={customName} onChange={(event) => { setCustomName(event.target.value); resetWizardPreflightState() }} className="field-control w-full px-3 py-2 text-sm font-mono" />
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Summary</FieldLabel><FieldHint>Short note shown in the installed server list.</FieldHint></div>
<input value={customSummary} onChange={(event) => { setCustomSummary(event.target.value); resetWizardPreflightState() }} className="field-control w-full px-3 py-2 text-sm" />
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Upload Runtime</FieldLabel><FieldHint>Runtime used to bootstrap uploaded bundles before preflight.</FieldHint></div>
<input value={uploadRuntime} onChange={(event) => setUploadRuntime(event.target.value)} placeholder="python3, node, uv, uvx" className="field-control w-full px-3 py-2 text-sm font-mono" />
<input value={uploadRuntime} onChange={(event) => { setUploadRuntime(event.target.value); resetWizardPreflightState() }} placeholder="python3, node, uv, uvx" className="field-control w-full px-3 py-2 text-sm font-mono" />
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Upload Launch Mode</FieldLabel><FieldHint>How the uploaded server should start after dependencies are installed.</FieldHint></div>
<select value={uploadEntryMode} onChange={(event) => setUploadEntryMode(event.target.value as "file" | "python-module" | "console-script")} className="field-control w-full px-3 py-2 text-sm font-mono">
<select value={uploadEntryMode} onChange={(event) => { setUploadEntryMode(event.target.value as "file" | "python-module" | "console-script"); resetWizardPreflightState() }} className="field-control w-full px-3 py-2 text-sm font-mono">
<option value="file">File</option>
<option value="python-module">Python module</option>
<option value="console-script">Console script</option>
@@ -1033,23 +1118,7 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
</div>
<div className="space-y-2 md:col-span-2">
<div className="flex items-center gap-2"><FieldLabel>Upload Entrypoint</FieldLabel><FieldHint>File path, Python module name, or installed console script to launch.</FieldHint></div>
<input value={uploadEntrypoint} onChange={(event) => setUploadEntrypoint(event.target.value)} placeholder={uploadEntryMode === "python-module" ? "isaac_mcp_poc.server" : uploadEntryMode === "console-script" ? "isaac-mcp-poc" : "server.py, src/server.py, index.js"} className="field-control w-full px-3 py-2 text-sm font-mono" />
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Preflight Repair</FieldLabel><FieldHint>When preflight fails, ask the running LLM endpoint for a bounded repair and run preflight again.</FieldHint></div>
<label className="flex min-h-10 items-center justify-between gap-3 rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs text-[var(--foreground)]">
<span>Use sandbox LLM on failed uploads</span>
<input type="checkbox" checked={uploadRepair} onChange={(event) => setUploadRepair(event.target.checked)} className="h-4 w-4 accent-[var(--nvidia-green)]" />
</label>
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Repair Route</FieldLabel><FieldHint>Optional sandbox whose configured model should be used for repair assistance.</FieldHint></div>
<select value={repairSandboxId} onChange={(event) => setRepairSandboxId(event.target.value)} disabled={!uploadRepair} className="field-control w-full px-3 py-2 text-sm font-mono">
<option value="">Default controller model</option>
{sandboxes.map((sandbox) => (
<option key={sandbox.id} value={sandbox.id}>{sandbox.name}</option>
))}
</select>
<input value={uploadEntrypoint} onChange={(event) => { setUploadEntrypoint(event.target.value); resetWizardPreflightState() }} placeholder={uploadEntryMode === "python-module" ? "isaac_mcp_poc.server" : uploadEntryMode === "console-script" ? "isaac-mcp-poc" : "server.py, src/server.py, index.js"} className="field-control w-full px-3 py-2 text-sm font-mono" />
</div>
<div className="flex flex-wrap items-center gap-3 md:col-span-2">
<label className="action-button cursor-pointer px-4 py-2">
@@ -1066,66 +1135,107 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
</span>
)}
</div>
{stagedUpload && (
<div className="rounded-sm border border-[var(--status-running)] bg-[var(--status-running-bg)] p-3 text-xs text-[var(--status-running)] md:col-span-2">
Uploaded to staged server workspace: {stagedUpload.name}
</div>
)}
</div>
)}
{wizardStep === "preflight" && (
<div className="space-y-4">
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>LLM Repair</FieldLabel><FieldHint>When preflight fails, ask the configured primary inference model for a bounded repair and run preflight again.</FieldHint></div>
<label className="flex min-h-10 items-center justify-between gap-3 rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-xs text-[var(--foreground)]">
<span>Attempt repairs on failures</span>
<input type="checkbox" checked={uploadRepair} onChange={(event) => setUploadRepair(event.target.checked)} className="h-4 w-4 accent-[var(--nvidia-green)]" />
</label>
</div>
<div className="space-y-2">
<div className="flex items-center gap-2"><FieldLabel>Inference Route</FieldLabel><FieldHint>Optional sandbox whose configured primary inference model should be used for preflight repair assistance.</FieldHint></div>
<select value={repairSandboxId} onChange={(event) => setRepairSandboxId(event.target.value)} disabled={!uploadRepair} className="field-control w-full px-3 py-2 text-sm font-mono">
<option value="">Default configured inference model</option>
{sandboxes.map((sandbox) => (
<option key={sandbox.id} value={sandbox.id}>{sandbox.name}</option>
))}
</select>
</div>
</div>
<button onClick={startWizardPreflightChecks} disabled={saving || !stagedUpload} className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50">
{saving ? "Running Preflight..." : "Start Preflight checks"}
</button>
{!stagedUpload && (
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-xs text-[var(--foreground-dim)]">
Upload server files before starting preflight checks.
</div>
)}
{wizardDependencyInstall && (
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4">
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Dependency Bootstrap</h3>
<p className="mt-2 text-xs text-[var(--foreground-dim)]">{wizardDependencyInstall.kind || "generic"} bootstrap{wizardDependencyInstall.logs?.length ? `, ${wizardDependencyInstall.logs.length} log item${wizardDependencyInstall.logs.length === 1 ? "" : "s"}` : ""}.</p>
</div>
)}
{wizardPreflight && (
<div className={`rounded-sm border p-4 text-xs ${wizardPreflight.ok ? "border-[var(--status-running)] bg-[var(--status-running-bg)] text-[var(--status-running)]" : "border-[var(--status-error)] bg-[var(--status-error-bg)] text-[var(--status-error)]"}`}>
<div className="font-mono uppercase tracking-wider">Preflight {wizardPreflight.ok ? "passed" : "found failures"} / {wizardPreflight.durationMs} ms</div>
<p className="mt-2 whitespace-pre-wrap text-[11px] leading-5">{summarizePreflight(wizardPreflight)}{summarizeRepair(wizardRepair)}</p>
</div>
)}
</div>
)}
{wizardStep === "review" && (
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4">
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Command Install</h3>
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Staged Upload</h3>
<pre className="mt-3 overflow-auto text-[11px] leading-5 text-[var(--foreground-dim)]">{JSON.stringify({
id: customName,
name: customName,
summary: customSummary,
transport: customTransport,
command: customCommand,
args: parseLines(customArgs),
env: parseEnv(customEnv),
selectedBundle: uploadArchive?.name || (uploadFiles.length > 0 ? `${uploadFiles.length} files` : stagedUpload?.selectedBundle || "staged"),
stagedUpload,
dependencyInstall: wizardDependencyInstall,
preflight: wizardPreflight ? {
ok: wizardPreflight.ok,
toolCount: wizardPreflight.toolCount,
tools: wizardPreflight.tools,
error: wizardPreflight.error || null,
} : null,
repair: wizardRepair,
}, null, 2)}</pre>
</div>
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4">
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Upload Install</h3>
<pre className="mt-3 overflow-auto text-[11px] leading-5 text-[var(--foreground-dim)]">{JSON.stringify({
selectedBundle: uploadArchive?.name || (uploadFiles.length > 0 ? `${uploadFiles.length} files` : "none"),
runtime: uploadRuntime,
entryMode: uploadEntryMode,
entrypoint: uploadEntrypoint,
repair: uploadRepair,
repairSandboxId: repairSandboxId || null,
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Broker Launch Definition</h3>
<pre className="mt-3 overflow-auto text-[11px] leading-5 text-[var(--foreground-dim)]">{JSON.stringify(wizardCandidate || {
status: "Run preflight checks to generate the launch definition.",
}, null, 2)}</pre>
</div>
</div>
)}
{wizardStep === "install" && (
<div className="space-y-4">
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-4">
<h3 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Ready To Install</h3>
<p className="mt-2 text-xs leading-5 text-[var(--foreground-dim)]">
{wizardCandidate
? `${wizardCandidate.name} will be installed ${wizardPreflight?.ok ? "enabled" : "disabled until preflight passes"}.`
: "Run preflight checks before installing this MCP server."}
</p>
</div>
<button onClick={installStagedUpload} disabled={saving || !wizardCandidate || Boolean(wizardInstallResult)} className="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50">
{wizardInstallResult ? "Installed" : saving ? "Installing..." : "Install Server"}
</button>
{wizardInstallResult && (
<div className="rounded-sm border border-[var(--status-running)] bg-[var(--status-running-bg)] p-4 text-xs text-[var(--status-running)]">
{wizardInstallResult.name} installed successfully.
</div>
)}
</div>
)}
<div className="mt-5 flex flex-wrap items-center gap-3">
<button onClick={previousWizardStep} disabled={saving || wizardStepIndex === 0} className="action-button px-4 py-2">Back</button>
<button onClick={nextWizardStep} disabled={saving || wizardStepIndex === WIZARD_STEPS.length - 1} className="action-button px-4 py-2">Next</button>
<button onClick={assistInstall} disabled={saving || !installPrompt.trim()} className="action-button px-4 py-2">Assist Install</button>
<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="rounded-sm bg-[var(--nvidia-green)] px-4 py-2 text-xs font-mono uppercase tracking-wider text-black disabled:opacity-50"
>
Install Server Command
</button>
<button
onClick={uploadServer}
disabled={saving || !hasUploadBundle}
className="action-button px-4 py-2"
>
Upload and Preflight
</button>
<button onClick={handleWizardNext} disabled={saving || wizardStepIndex === WIZARD_STEPS.length - 1 || (wizardStep === "upload" && !hasUploadBundle && !stagedUpload)} className="action-button px-4 py-2">Next</button>
</div>
</div>
)}
+16 -1
View File
@@ -47,6 +47,7 @@ const MAX_CONTEXT_FILE_BYTES = Number.parseInt(process.env.MCP_PREFLIGHT_REPAIR_
const MAX_CONTEXT_FILES = Number.parseInt(process.env.MCP_PREFLIGHT_REPAIR_MAX_FILES || "18", 10)
const MAX_REPAIR_FILE_BYTES = Number.parseInt(process.env.MCP_PREFLIGHT_REPAIR_MAX_OUTPUT_FILE_BYTES || String(512 * 1024), 10)
const REQUEST_TIMEOUT_MS = Number.parseInt(process.env.MCP_PREFLIGHT_REPAIR_TIMEOUT_MS || "60000", 10)
const MCP_SERVER_SPEC_PATH = path.join(process.cwd(), "mcp_server_specs.md")
function relativeInside(root: string, candidate: string) {
const fullPath = path.resolve(root, candidate)
@@ -104,6 +105,14 @@ async function readContextFiles(root: string) {
return context
}
async function readMcpServerSpec() {
return await readFile(MCP_SERVER_SPEC_PATH, "utf8").catch(() => [
"Uploaded MCP servers must initialize through the MCP broker and list tools successfully.",
"Python uploads must use a per-server .venv and local dependency installation.",
"Repairs must stay inside the uploaded server directory.",
].join("\n"))
}
async function resolveRepairRoute(sandboxId?: string | null) {
let explicitModel = ""
if (sandboxId) {
@@ -129,6 +138,7 @@ function extractJsonObject(value: string) {
async function requestRepairPlan(context: RepairContext, files: Awaited<ReturnType<typeof readContextFiles>>) {
const route = await resolveRepairRoute(context.sandboxId)
if (!route.model) throw new Error("No primary inference model is configured")
const mcpServerSpec = await readMcpServerSpec()
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
try {
@@ -149,7 +159,11 @@ async function requestRepairPlan(context: RepairContext, files: Awaited<ReturnTy
{
role: "system",
content: [
"You repair uploaded Model Context Protocol stdio servers.",
"You are inspecting an MCP server to ensure it is going to function with the MCP broker.",
"Review the files, run a preflight check on them as they stand, and perform any tasks required in the returned repair plan.",
"If Python dependencies are required, use the per-server virtualenv described in mcp_server_specs.md.",
"If there are failures, advise that failures exist and whether they can be resolved.",
"Read mcp_server_specs.md in the user payload to understand the requirements.",
"Return only JSON with optional files and launch keys.",
"Only modify files that are included in the context.",
"Do not invent dependencies unless required by the observed error.",
@@ -166,6 +180,7 @@ async function requestRepairPlan(context: RepairContext, files: Awaited<ReturnTy
},
preflight: context.preflight,
dependencyLogs: context.dependencyLogs || [],
mcp_server_specs_md: mcpServerSpec,
files,
expectedJson: {
summary: "short explanation",