Merge pull request #8 from mmckeen-nv/codex/mcp-registry-wizard-preflight
Codex/mcp registry wizard preflight
This commit is contained in:
@@ -0,0 +1,99 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
|
||||||
|
const REQUEST_TIMEOUT_MS = Number.parseInt(process.env.MCP_INSTALL_ASSIST_TIMEOUT_MS || "45000", 10)
|
||||||
|
const MODEL = process.env.MCP_PREFLIGHT_LLM_MODEL || process.env.OPENAI_MODEL || "gpt-4o-mini"
|
||||||
|
const BASE_URL = (process.env.MCP_PREFLIGHT_LLM_BASE_URL || process.env.OPENAI_BASE_URL || process.env.VLLM_BASE_URL || "http://localhost:8000/v1").replace(/\/+$/, "")
|
||||||
|
|
||||||
|
function extractJsonObject(value: string) {
|
||||||
|
const trimmed = value.trim()
|
||||||
|
if (trimmed.startsWith("{")) return trimmed
|
||||||
|
const match = trimmed.match(/\{[\s\S]*\}/)
|
||||||
|
if (!match) throw new Error("install assistant did not return JSON")
|
||||||
|
return match[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringArray(value: unknown) {
|
||||||
|
return Array.isArray(value)
|
||||||
|
? value.map((item) => String(item ?? "").trim()).filter(Boolean)
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringMap(value: unknown) {
|
||||||
|
if (!value || typeof value !== "object" || Array.isArray(value)) return {}
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(value)
|
||||||
|
.map(([key, item]) => [key.trim(), String(item ?? "").trim()])
|
||||||
|
.filter(([key]) => Boolean(key)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const controller = new AbortController()
|
||||||
|
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
|
||||||
|
try {
|
||||||
|
const body = await request.json().catch(() => ({}))
|
||||||
|
const prompt = typeof body?.prompt === "string" ? body.prompt.trim() : ""
|
||||||
|
if (!prompt) throw new Error("install prompt is required")
|
||||||
|
|
||||||
|
const response = await fetch(`${BASE_URL}/chat/completions`, {
|
||||||
|
method: "POST",
|
||||||
|
signal: controller.signal,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(process.env.MCP_PREFLIGHT_LLM_API_KEY || process.env.OPENAI_API_KEY
|
||||||
|
? { Authorization: `Bearer ${process.env.MCP_PREFLIGHT_LLM_API_KEY || process.env.OPENAI_API_KEY}` }
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: MODEL,
|
||||||
|
temperature: 0.1,
|
||||||
|
response_format: { type: "json_object" },
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: [
|
||||||
|
"You draft install metadata for Model Context Protocol servers.",
|
||||||
|
"Return only JSON with name, summary, transport, command, args, env, uploadRuntime, uploadEntryMode, uploadEntrypoint, and notes.",
|
||||||
|
"Use transport stdio for local commands and http for streamable HTTP endpoints.",
|
||||||
|
"Args must be an array of strings; env must be an object.",
|
||||||
|
"If the user describes an uploaded bundle, set upload fields but still provide the most likely runtime and entrypoint.",
|
||||||
|
].join(" "),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: JSON.stringify({
|
||||||
|
prompt,
|
||||||
|
current: body?.current || {},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
const data = await response.json().catch(() => null)
|
||||||
|
if (!response.ok) throw new Error(data?.error?.message || data?.error || `install assistant failed (${response.status})`)
|
||||||
|
const content = data?.choices?.[0]?.message?.content
|
||||||
|
if (typeof content !== "string" || !content.trim()) throw new Error("install assistant returned an empty response")
|
||||||
|
const suggestion = JSON.parse(extractJsonObject(content))
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
suggestion: {
|
||||||
|
name: typeof suggestion?.name === "string" ? suggestion.name : "",
|
||||||
|
summary: typeof suggestion?.summary === "string" ? suggestion.summary : "",
|
||||||
|
transport: suggestion?.transport === "http" ? "http" : "stdio",
|
||||||
|
command: typeof suggestion?.command === "string" ? suggestion.command : "",
|
||||||
|
args: stringArray(suggestion?.args),
|
||||||
|
env: stringMap(suggestion?.env),
|
||||||
|
uploadRuntime: typeof suggestion?.uploadRuntime === "string" ? suggestion.uploadRuntime : "",
|
||||||
|
uploadEntryMode: ["file", "python-module", "console-script"].includes(suggestion?.uploadEntryMode) ? suggestion.uploadEntryMode : "",
|
||||||
|
uploadEntrypoint: typeof suggestion?.uploadEntrypoint === "string" ? suggestion.uploadEntrypoint : "",
|
||||||
|
notes: typeof suggestion?.notes === "string" ? suggestion.notes : "",
|
||||||
|
},
|
||||||
|
model: MODEL,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Failed to assist MCP install"
|
||||||
|
return NextResponse.json({ error: message }, { status: /required/.test(message) ? 400 : 502 })
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
|
||||||
|
const REQUEST_TIMEOUT_MS = Number.parseInt(process.env.MCP_REGISTRY_ASSIST_TIMEOUT_MS || "45000", 10)
|
||||||
|
const MODEL = process.env.MCP_PREFLIGHT_LLM_MODEL || process.env.OPENAI_MODEL || "gpt-4o-mini"
|
||||||
|
const BASE_URL = (process.env.MCP_PREFLIGHT_LLM_BASE_URL || process.env.OPENAI_BASE_URL || process.env.VLLM_BASE_URL || "http://localhost:8000/v1").replace(/\/+$/, "")
|
||||||
|
|
||||||
|
function extractJsonObject(value: string) {
|
||||||
|
const trimmed = value.trim()
|
||||||
|
if (trimmed.startsWith("{")) return trimmed
|
||||||
|
const match = trimmed.match(/\{[\s\S]*\}/)
|
||||||
|
if (!match) throw new Error("registry assistant did not return JSON")
|
||||||
|
return match[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
const controller = new AbortController()
|
||||||
|
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
|
||||||
|
try {
|
||||||
|
const body = await request.json().catch(() => ({}))
|
||||||
|
const prompt = typeof body?.prompt === "string" ? body.prompt.trim() : ""
|
||||||
|
if (!prompt) throw new Error("registry prompt is required")
|
||||||
|
|
||||||
|
const response = await fetch(`${BASE_URL}/chat/completions`, {
|
||||||
|
method: "POST",
|
||||||
|
signal: controller.signal,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(process.env.MCP_PREFLIGHT_LLM_API_KEY || process.env.OPENAI_API_KEY
|
||||||
|
? { Authorization: `Bearer ${process.env.MCP_PREFLIGHT_LLM_API_KEY || process.env.OPENAI_API_KEY}` }
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: MODEL,
|
||||||
|
temperature: 0.1,
|
||||||
|
response_format: { type: "json_object" },
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: "Convert a user's MCP registry description into JSON with name, baseUrl, and description. The baseUrl must be the registry origin/root, not the /v0/servers path. Return only JSON.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: prompt,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
const data = await response.json().catch(() => null)
|
||||||
|
if (!response.ok) throw new Error(data?.error?.message || data?.error || `registry assistant failed (${response.status})`)
|
||||||
|
const content = data?.choices?.[0]?.message?.content
|
||||||
|
if (typeof content !== "string" || !content.trim()) throw new Error("registry assistant returned an empty response")
|
||||||
|
const suggestion = JSON.parse(extractJsonObject(content))
|
||||||
|
return NextResponse.json({
|
||||||
|
suggestion: {
|
||||||
|
name: typeof suggestion?.name === "string" ? suggestion.name : "",
|
||||||
|
baseUrl: typeof suggestion?.baseUrl === "string" ? suggestion.baseUrl : "",
|
||||||
|
description: typeof suggestion?.description === "string" ? suggestion.description : "",
|
||||||
|
},
|
||||||
|
model: MODEL,
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Failed to assist registry setup"
|
||||||
|
return NextResponse.json({ error: message }, { status: /required/.test(message) ? 400 : 502 })
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { NextResponse } from "next/server"
|
||||||
|
import { deleteMcpRegistry, listMcpRegistries, saveMcpRegistry } from "@/app/lib/mcpRegistryStore"
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
return NextResponse.json({ registries: await listMcpRegistries() })
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Failed to load MCP registries"
|
||||||
|
return NextResponse.json({ error: message }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = await request.json().catch(() => ({}))
|
||||||
|
const action = typeof body?.action === "string" ? body.action : "save"
|
||||||
|
|
||||||
|
if (action === "delete") {
|
||||||
|
const registryId = typeof body?.registryId === "string" ? body.registryId : ""
|
||||||
|
return NextResponse.json({ deleted: await deleteMcpRegistry(registryId), registries: await listMcpRegistries() })
|
||||||
|
}
|
||||||
|
|
||||||
|
const registry = await saveMcpRegistry({
|
||||||
|
id: body?.id,
|
||||||
|
name: body?.name,
|
||||||
|
baseUrl: body?.baseUrl,
|
||||||
|
description: body?.description,
|
||||||
|
})
|
||||||
|
return NextResponse.json({ registry, registries: await listMcpRegistries() })
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Failed to update MCP registries"
|
||||||
|
return NextResponse.json({ error: message }, { status: /required|URL|delete/.test(message) ? 400 : 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NextResponse } from "next/server"
|
import { NextResponse } from "next/server"
|
||||||
import type { McpCatalogEntry } from "@/app/lib/mcpServerStore"
|
import type { McpCatalogEntry } from "@/app/lib/mcpServerStore"
|
||||||
|
|
||||||
const REGISTRY_BASE_URL = process.env.MCP_REGISTRY_BASE_URL || "https://registry.modelcontextprotocol.io"
|
const DEFAULT_REGISTRY_BASE_URL = process.env.MCP_REGISTRY_BASE_URL || "https://registry.modelcontextprotocol.io"
|
||||||
|
|
||||||
type RegistryArgument = {
|
type RegistryArgument = {
|
||||||
value?: string
|
value?: string
|
||||||
@@ -126,7 +126,8 @@ export async function GET(request: Request) {
|
|||||||
const requestUrl = new URL(request.url)
|
const requestUrl = new URL(request.url)
|
||||||
const search = requestUrl.searchParams.get("search") || requestUrl.searchParams.get("q") || ""
|
const search = requestUrl.searchParams.get("search") || requestUrl.searchParams.get("q") || ""
|
||||||
const limit = Math.max(1, Math.min(Number.parseInt(requestUrl.searchParams.get("limit") || "12", 10) || 12, 30))
|
const limit = Math.max(1, Math.min(Number.parseInt(requestUrl.searchParams.get("limit") || "12", 10) || 12, 30))
|
||||||
const registryUrl = new URL("/v0/servers", REGISTRY_BASE_URL)
|
const baseUrl = requestUrl.searchParams.get("baseUrl") || DEFAULT_REGISTRY_BASE_URL
|
||||||
|
const registryUrl = new URL("/v0/servers", baseUrl)
|
||||||
registryUrl.searchParams.set("limit", String(limit))
|
registryUrl.searchParams.set("limit", String(limit))
|
||||||
registryUrl.searchParams.set("is_latest", "true")
|
registryUrl.searchParams.set("is_latest", "true")
|
||||||
if (search.trim()) registryUrl.searchParams.set("search", search.trim())
|
if (search.trim()) registryUrl.searchParams.set("search", search.trim())
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import os from "node:os"
|
|||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import { promisify } from "node:util"
|
import { promisify } from "node:util"
|
||||||
import { preflightMcpServer } from "@/app/lib/mcpPreflight"
|
import { preflightMcpServer } from "@/app/lib/mcpPreflight"
|
||||||
import { installMcpServer, listMcpServers } from "@/app/lib/mcpServerStore"
|
import { repairUploadedMcpServerWithLlm, type McpPreflightRepairResult } from "@/app/lib/mcpPreflightRepair"
|
||||||
|
import { installMcpServer, listMcpServers, type McpServerInstall } from "@/app/lib/mcpServerStore"
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
const HOME = process.env.HOME || "/tmp"
|
const HOME = process.env.HOME || "/tmp"
|
||||||
@@ -295,6 +296,8 @@ export async function POST(request: Request) {
|
|||||||
const runtime = String(form.get("runtime") || "python3").trim()
|
const runtime = String(form.get("runtime") || "python3").trim()
|
||||||
const entrypoint = String(form.get("entrypoint") || "server.py").trim()
|
const entrypoint = String(form.get("entrypoint") || "server.py").trim()
|
||||||
const entryMode = normalizeEntryMode(form.get("entryMode"))
|
const entryMode = normalizeEntryMode(form.get("entryMode"))
|
||||||
|
const sandboxId = String(form.get("sandboxId") || "").trim()
|
||||||
|
const repairEnabled = String(form.get("repair") || "true") !== "false"
|
||||||
const root = path.join(UPLOAD_DIR, id)
|
const root = path.join(UPLOAD_DIR, id)
|
||||||
|
|
||||||
if (!runtime) throw new Error("runtime command is required")
|
if (!runtime) throw new Error("runtime command is required")
|
||||||
@@ -311,7 +314,7 @@ export async function POST(request: Request) {
|
|||||||
const projectRoot = await resolveProjectRoot(root, entrypointPath)
|
const projectRoot = await resolveProjectRoot(root, entrypointPath)
|
||||||
const bootstrap = await bootstrapUploadedServer(projectRoot, runtime, entrypoint)
|
const bootstrap = await bootstrapUploadedServer(projectRoot, runtime, entrypoint)
|
||||||
const launch = await launchCommandForUpload(projectRoot, bootstrap, entryMode, entrypoint, entrypointPath, parseLines(form.get("args")))
|
const launch = await launchCommandForUpload(projectRoot, bootstrap, entryMode, entrypoint, entrypointPath, parseLines(form.get("args")))
|
||||||
const candidate = {
|
let candidate = {
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
summary,
|
summary,
|
||||||
@@ -322,7 +325,7 @@ export async function POST(request: Request) {
|
|||||||
tags: ["uploaded", "custom"],
|
tags: ["uploaded", "custom"],
|
||||||
source: "custom",
|
source: "custom",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
} as const satisfies {
|
} satisfies {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
summary: string
|
summary: string
|
||||||
@@ -334,13 +337,51 @@ export async function POST(request: Request) {
|
|||||||
source: "custom"
|
source: "custom"
|
||||||
enabled: boolean
|
enabled: boolean
|
||||||
}
|
}
|
||||||
const preflight = await preflightMcpServer({
|
const installCandidate = (): McpServerInstall => ({
|
||||||
...candidate,
|
...candidate,
|
||||||
installedAt: new Date().toISOString(),
|
installedAt: new Date().toISOString(),
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
accessMode: "disabled",
|
accessMode: "disabled",
|
||||||
allowedSandboxIds: [],
|
allowedSandboxIds: [],
|
||||||
})
|
})
|
||||||
|
let preflight = await preflightMcpServer(installCandidate())
|
||||||
|
let repair: McpPreflightRepairResult | null = null
|
||||||
|
|
||||||
|
if (!preflight.ok && repairEnabled) {
|
||||||
|
try {
|
||||||
|
repair = await repairUploadedMcpServerWithLlm({
|
||||||
|
uploadRoot: root,
|
||||||
|
projectRoot,
|
||||||
|
server: installCandidate(),
|
||||||
|
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(installCandidate())
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
repair = {
|
||||||
|
attempted: true,
|
||||||
|
ok: false,
|
||||||
|
provider: "openai-compatible",
|
||||||
|
model: process.env.MCP_PREFLIGHT_LLM_MODEL || process.env.OPENAI_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",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const server = await installMcpServer({
|
const server = await installMcpServer({
|
||||||
...candidate,
|
...candidate,
|
||||||
enabled: preflight.ok,
|
enabled: preflight.ok,
|
||||||
@@ -357,6 +398,7 @@ export async function POST(request: Request) {
|
|||||||
logs: bootstrap.logs,
|
logs: bootstrap.logs,
|
||||||
},
|
},
|
||||||
preflight,
|
preflight,
|
||||||
|
repair,
|
||||||
...(await listMcpServers()),
|
...(await listMcpServers()),
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,253 @@
|
|||||||
|
import { readdir, readFile, stat, writeFile } from "node:fs/promises"
|
||||||
|
import path from "node:path"
|
||||||
|
import { getSandboxInferenceConfig } from "./sandboxInferenceStore"
|
||||||
|
import type { McpPreflightResult } from "./mcpPreflight"
|
||||||
|
import type { McpServerInstall } from "./mcpServerStore"
|
||||||
|
|
||||||
|
export type McpPreflightRepairChange = {
|
||||||
|
type: "file" | "launch"
|
||||||
|
path?: string
|
||||||
|
summary: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type McpPreflightRepairResult = {
|
||||||
|
attempted: boolean
|
||||||
|
ok: boolean
|
||||||
|
provider: "openai-compatible"
|
||||||
|
model: string
|
||||||
|
baseUrl: string
|
||||||
|
summary: string
|
||||||
|
changes: McpPreflightRepairChange[]
|
||||||
|
error?: string
|
||||||
|
updatedServer?: Pick<McpServerInstall, "command" | "args" | "env">
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepairContext = {
|
||||||
|
uploadRoot: string
|
||||||
|
projectRoot: string
|
||||||
|
server: McpServerInstall
|
||||||
|
preflight: McpPreflightResult
|
||||||
|
dependencyLogs?: string[]
|
||||||
|
sandboxId?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
type LlmRepairResponse = {
|
||||||
|
summary?: string
|
||||||
|
files?: Array<{ path?: string; content?: string; summary?: string }>
|
||||||
|
launch?: {
|
||||||
|
command?: string
|
||||||
|
args?: string[]
|
||||||
|
env?: Record<string, string>
|
||||||
|
summary?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_CONTEXT_FILE_BYTES = Number.parseInt(process.env.MCP_PREFLIGHT_REPAIR_MAX_FILE_BYTES || String(40 * 1024), 10)
|
||||||
|
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 DEFAULT_MODEL = process.env.MCP_PREFLIGHT_LLM_MODEL || process.env.OPENAI_MODEL || "gpt-4o-mini"
|
||||||
|
const DEFAULT_BASE_URL = process.env.MCP_PREFLIGHT_LLM_BASE_URL || process.env.OPENAI_BASE_URL || process.env.VLLM_BASE_URL || "http://localhost:8000/v1"
|
||||||
|
|
||||||
|
function cleanBaseUrl(value: string) {
|
||||||
|
return value.replace(/\/+$/, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
function relativeInside(root: string, candidate: string) {
|
||||||
|
const fullPath = path.resolve(root, candidate)
|
||||||
|
if (fullPath !== root && !fullPath.startsWith(`${root}${path.sep}`)) {
|
||||||
|
throw new Error("repair path must stay inside the uploaded server")
|
||||||
|
}
|
||||||
|
return fullPath
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeRepairPath(value: string) {
|
||||||
|
const normalized = path.posix.normalize(value.replace(/\\/g, "/")).replace(/^\/+/, "")
|
||||||
|
if (!normalized || normalized === "." || normalized.startsWith("../") || normalized.includes("/../")) {
|
||||||
|
throw new Error("repair file path must be relative to the uploaded server")
|
||||||
|
}
|
||||||
|
return normalized
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLikelyUsefulFile(filePath: string) {
|
||||||
|
if (/(^|\/)(node_modules|\.venv|\.git|dist|build|__pycache__)(\/|$)/.test(filePath)) return false
|
||||||
|
return /\.(py|js|mjs|cjs|ts|json|toml|txt|md|yaml|yml)$/i.test(filePath)
|
||||||
|
|| /(^|\/)(requirements\.txt|package\.json|pyproject\.toml)$/.test(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function collectFiles(root: string, directory = root): Promise<string[]> {
|
||||||
|
const entries = await readdir(directory, { withFileTypes: true }).catch(() => [])
|
||||||
|
const files: string[] = []
|
||||||
|
for (const entry of entries) {
|
||||||
|
const fullPath = path.join(directory, entry.name)
|
||||||
|
const relative = path.relative(root, fullPath).replace(/\\/g, "/")
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
if (/(^|\/)(node_modules|\.venv|\.git|dist|build|__pycache__)(\/|$)/.test(relative)) continue
|
||||||
|
files.push(...await collectFiles(root, fullPath))
|
||||||
|
} else if (entry.isFile()) {
|
||||||
|
if (!isLikelyUsefulFile(relative)) continue
|
||||||
|
files.push(relative)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readContextFiles(root: string) {
|
||||||
|
const files = (await collectFiles(root)).slice(0, MAX_CONTEXT_FILES)
|
||||||
|
const context: Array<{ path: string; content: string; truncated: boolean }> = []
|
||||||
|
for (const file of files) {
|
||||||
|
const fullPath = relativeInside(root, file)
|
||||||
|
const stats = await stat(fullPath).catch(() => null)
|
||||||
|
if (!stats || stats.size > MAX_CONTEXT_FILE_BYTES * 2) continue
|
||||||
|
const content = await readFile(fullPath, "utf8").catch(() => "")
|
||||||
|
context.push({
|
||||||
|
path: file,
|
||||||
|
content: content.length > MAX_CONTEXT_FILE_BYTES ? content.slice(0, MAX_CONTEXT_FILE_BYTES) : content,
|
||||||
|
truncated: content.length > MAX_CONTEXT_FILE_BYTES,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolveRepairRoute(sandboxId?: string | null) {
|
||||||
|
if (sandboxId) {
|
||||||
|
const config = await getSandboxInferenceConfig(sandboxId)
|
||||||
|
const enabled = config.routes.filter((route) => route.enabled)
|
||||||
|
const primary = enabled.find((route) => route.id === config.primaryRouteId) || enabled[0]
|
||||||
|
if (primary?.model) {
|
||||||
|
return {
|
||||||
|
model: process.env.MCP_PREFLIGHT_LLM_MODEL || primary.model,
|
||||||
|
baseUrl: cleanBaseUrl(DEFAULT_BASE_URL),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
model: DEFAULT_MODEL,
|
||||||
|
baseUrl: cleanBaseUrl(DEFAULT_BASE_URL),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractJsonObject(value: string) {
|
||||||
|
const trimmed = value.trim()
|
||||||
|
if (trimmed.startsWith("{")) return trimmed
|
||||||
|
const match = trimmed.match(/\{[\s\S]*\}/)
|
||||||
|
if (!match) throw new Error("repair model did not return JSON")
|
||||||
|
return match[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
async function requestRepairPlan(context: RepairContext, files: Awaited<ReturnType<typeof readContextFiles>>) {
|
||||||
|
const route = await resolveRepairRoute(context.sandboxId)
|
||||||
|
const controller = new AbortController()
|
||||||
|
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS)
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${route.baseUrl}/chat/completions`, {
|
||||||
|
method: "POST",
|
||||||
|
signal: controller.signal,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(process.env.MCP_PREFLIGHT_LLM_API_KEY || process.env.OPENAI_API_KEY
|
||||||
|
? { Authorization: `Bearer ${process.env.MCP_PREFLIGHT_LLM_API_KEY || process.env.OPENAI_API_KEY}` }
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
model: route.model,
|
||||||
|
temperature: 0.1,
|
||||||
|
response_format: { type: "json_object" },
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
role: "system",
|
||||||
|
content: [
|
||||||
|
"You repair uploaded Model Context Protocol stdio servers.",
|
||||||
|
"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.",
|
||||||
|
"Prefer minimal, runnable fixes that let MCP initialize and list tools.",
|
||||||
|
].join(" "),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: "user",
|
||||||
|
content: JSON.stringify({
|
||||||
|
server: {
|
||||||
|
command: context.server.command,
|
||||||
|
args: context.server.args,
|
||||||
|
envKeys: Object.keys(context.server.env || {}),
|
||||||
|
},
|
||||||
|
preflight: context.preflight,
|
||||||
|
dependencyLogs: context.dependencyLogs || [],
|
||||||
|
files,
|
||||||
|
expectedJson: {
|
||||||
|
summary: "short explanation",
|
||||||
|
files: [{ path: "relative/path.py", content: "complete replacement content", summary: "what changed" }],
|
||||||
|
launch: { command: context.server.command, args: context.server.args, env: context.server.env, summary: "optional launch change" },
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
const data = await response.json().catch(() => null)
|
||||||
|
if (!response.ok) throw new Error(data?.error?.message || data?.error || `repair model request failed (${response.status})`)
|
||||||
|
const content = data?.choices?.[0]?.message?.content
|
||||||
|
if (typeof content !== "string" || !content.trim()) throw new Error("repair model returned an empty response")
|
||||||
|
return {
|
||||||
|
route,
|
||||||
|
plan: JSON.parse(extractJsonObject(content)) as LlmRepairResponse,
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeLaunch(server: McpServerInstall, launch?: LlmRepairResponse["launch"]) {
|
||||||
|
if (!launch || typeof launch !== "object") return null
|
||||||
|
const command = typeof launch.command === "string" && launch.command.trim() ? launch.command.trim() : server.command
|
||||||
|
const args = Array.isArray(launch.args)
|
||||||
|
? launch.args.map((arg) => String(arg ?? "").trim()).filter(Boolean)
|
||||||
|
: server.args
|
||||||
|
const env = launch.env && typeof launch.env === "object" && !Array.isArray(launch.env)
|
||||||
|
? Object.fromEntries(Object.entries(launch.env).map(([key, value]) => [key.trim(), String(value ?? "").trim()]).filter(([key]) => Boolean(key)))
|
||||||
|
: server.env
|
||||||
|
if (command === server.command && JSON.stringify(args) === JSON.stringify(server.args) && JSON.stringify(env) === JSON.stringify(server.env)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return { command, args, env, summary: launch.summary || "Adjusted launch metadata." }
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function repairUploadedMcpServerWithLlm(context: RepairContext): Promise<McpPreflightRepairResult> {
|
||||||
|
const files = await readContextFiles(context.projectRoot)
|
||||||
|
const { route, plan } = await requestRepairPlan(context, files)
|
||||||
|
const changes: McpPreflightRepairChange[] = []
|
||||||
|
|
||||||
|
for (const file of Array.isArray(plan.files) ? plan.files : []) {
|
||||||
|
if (typeof file?.path !== "string" || typeof file?.content !== "string") continue
|
||||||
|
if (Buffer.byteLength(file.content, "utf8") > MAX_REPAIR_FILE_BYTES) {
|
||||||
|
throw new Error(`repair output for ${file.path} is too large`)
|
||||||
|
}
|
||||||
|
const relative = normalizeRepairPath(file.path)
|
||||||
|
if (!files.some((contextFile) => contextFile.path === relative)) {
|
||||||
|
throw new Error(`repair model tried to edit a file outside provided context: ${relative}`)
|
||||||
|
}
|
||||||
|
await writeFile(relativeInside(context.projectRoot, relative), file.content, { mode: 0o600 })
|
||||||
|
changes.push({ type: "file", path: relative, summary: file.summary || `Updated ${relative}` })
|
||||||
|
}
|
||||||
|
|
||||||
|
const launch = normalizeLaunch(context.server, plan.launch)
|
||||||
|
if (launch) {
|
||||||
|
changes.push({ type: "launch", summary: launch.summary })
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
attempted: true,
|
||||||
|
ok: changes.length > 0,
|
||||||
|
provider: "openai-compatible",
|
||||||
|
model: route.model,
|
||||||
|
baseUrl: route.baseUrl,
|
||||||
|
summary: plan.summary || (changes.length > 0 ? "Applied LLM-assisted MCP repair." : "The repair model did not suggest changes."),
|
||||||
|
changes,
|
||||||
|
updatedServer: launch ? {
|
||||||
|
command: launch.command,
|
||||||
|
args: launch.args,
|
||||||
|
env: launch.env,
|
||||||
|
} : undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import { mkdir, readFile, writeFile } from "node:fs/promises"
|
||||||
|
import path from "node:path"
|
||||||
|
|
||||||
|
export type McpRegistry = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
baseUrl: string
|
||||||
|
description: string
|
||||||
|
addedAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type StoreShape = {
|
||||||
|
registries: McpRegistry[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const HOME = process.env.HOME || "/tmp"
|
||||||
|
const STORE_DIR = process.env.NEMOCLAW_DASHBOARD_STATE_DIR || path.join(HOME, ".nemoclaw-dashboard")
|
||||||
|
const STORE_PATH = path.join(STORE_DIR, "mcp-registries.json")
|
||||||
|
|
||||||
|
export const DEFAULT_MCP_REGISTRY: McpRegistry = {
|
||||||
|
id: "official",
|
||||||
|
name: "Official MCP Registry",
|
||||||
|
baseUrl: process.env.MCP_REGISTRY_BASE_URL || "https://registry.modelcontextprotocol.io",
|
||||||
|
description: "The public Model Context Protocol registry.",
|
||||||
|
addedAt: "default",
|
||||||
|
}
|
||||||
|
|
||||||
|
function slugify(value: string) {
|
||||||
|
return value
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9-]+/g, "-")
|
||||||
|
.replace(/^-+|-+$/g, "")
|
||||||
|
.slice(0, 64) || "mcp-registry"
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeRegistry(input: Partial<McpRegistry>, existing?: McpRegistry | null): McpRegistry {
|
||||||
|
const name = typeof input.name === "string" && input.name.trim() ? input.name.trim() : existing?.name || "MCP Registry"
|
||||||
|
const rawUrl = typeof input.baseUrl === "string" && input.baseUrl.trim() ? input.baseUrl.trim() : existing?.baseUrl || ""
|
||||||
|
if (!rawUrl) throw new Error("registry URL is required")
|
||||||
|
const parsed = new URL(rawUrl)
|
||||||
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "")
|
||||||
|
parsed.search = ""
|
||||||
|
parsed.hash = ""
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: slugify(input.id || existing?.id || name),
|
||||||
|
name,
|
||||||
|
baseUrl: parsed.toString().replace(/\/+$/, ""),
|
||||||
|
description: typeof input.description === "string" ? input.description.trim() : existing?.description || "",
|
||||||
|
addedAt: existing?.addedAt || new Date().toISOString(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readStore(): Promise<StoreShape | null> {
|
||||||
|
try {
|
||||||
|
const raw = await readFile(STORE_PATH, "utf8")
|
||||||
|
const parsed = JSON.parse(raw)
|
||||||
|
return parsed && typeof parsed === "object" && Array.isArray(parsed.registries)
|
||||||
|
? parsed
|
||||||
|
: null
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function writeStore(store: StoreShape) {
|
||||||
|
await mkdir(STORE_DIR, { recursive: true, mode: 0o700 })
|
||||||
|
await writeFile(STORE_PATH, JSON.stringify(store, null, 2), { mode: 0o600 })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listMcpRegistries() {
|
||||||
|
const store = await readStore()
|
||||||
|
return store?.registries || [DEFAULT_MCP_REGISTRY]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function saveMcpRegistry(input: Partial<McpRegistry>) {
|
||||||
|
const store = await readStore() || { registries: [DEFAULT_MCP_REGISTRY] }
|
||||||
|
const id = slugify(input.id || input.name || "mcp-registry")
|
||||||
|
const existing = store.registries.find((registry) => registry.id === id)
|
||||||
|
const next = normalizeRegistry({ ...input, id }, existing)
|
||||||
|
const filtered = store.registries.filter((registry) => registry.id !== next.id)
|
||||||
|
store.registries = [next, ...filtered]
|
||||||
|
await writeStore(store)
|
||||||
|
return next
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteMcpRegistry(registryId: string) {
|
||||||
|
const id = slugify(registryId)
|
||||||
|
const store = await readStore() || { registries: [DEFAULT_MCP_REGISTRY] }
|
||||||
|
store.registries = store.registries.filter((registry) => registry.id !== id)
|
||||||
|
await writeStore(store)
|
||||||
|
return { id }
|
||||||
|
}
|
||||||
@@ -14,11 +14,16 @@ const uploadRoutePath = path.join(root, 'app/api/mcp/upload/route.ts')
|
|||||||
const preflightRoutePath = path.join(root, 'app/api/mcp/preflight/route.ts')
|
const preflightRoutePath = path.join(root, 'app/api/mcp/preflight/route.ts')
|
||||||
const healthRoutePath = path.join(root, 'app/api/mcp/health/route.ts')
|
const healthRoutePath = path.join(root, 'app/api/mcp/health/route.ts')
|
||||||
const registryRoutePath = path.join(root, 'app/api/mcp/registry/route.ts')
|
const registryRoutePath = path.join(root, 'app/api/mcp/registry/route.ts')
|
||||||
|
const registriesRoutePath = path.join(root, 'app/api/mcp/registries/route.ts')
|
||||||
|
const registriesAssistRoutePath = path.join(root, 'app/api/mcp/registries/assist/route.ts')
|
||||||
|
const installAssistRoutePath = path.join(root, 'app/api/mcp/install-assist/route.ts')
|
||||||
|
const registryStorePath = path.join(root, 'app/lib/mcpRegistryStore.ts')
|
||||||
const brokerCapabilitiesRoutePath = path.join(root, 'app/api/mcp/broker/capabilities/route.ts')
|
const brokerCapabilitiesRoutePath = path.join(root, 'app/api/mcp/broker/capabilities/route.ts')
|
||||||
const brokerCallRoutePath = path.join(root, 'app/api/mcp/broker/call/route.ts')
|
const brokerCallRoutePath = path.join(root, 'app/api/mcp/broker/call/route.ts')
|
||||||
const sandboxMcpRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/mcp/route.ts')
|
const sandboxMcpRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/mcp/route.ts')
|
||||||
const brokerUrlPath = path.join(root, 'app/lib/mcpBrokerUrl.ts')
|
const brokerUrlPath = path.join(root, 'app/lib/mcpBrokerUrl.ts')
|
||||||
const preflightLibPath = path.join(root, 'app/lib/mcpPreflight.ts')
|
const preflightLibPath = path.join(root, 'app/lib/mcpPreflight.ts')
|
||||||
|
const preflightRepairLibPath = path.join(root, 'app/lib/mcpPreflightRepair.ts')
|
||||||
const middlewarePath = path.join(root, 'middleware.ts')
|
const middlewarePath = path.join(root, 'middleware.ts')
|
||||||
const panelPath = path.join(root, 'app/components/McpConfigurationPanel.tsx')
|
const panelPath = path.join(root, 'app/components/McpConfigurationPanel.tsx')
|
||||||
const helpPath = path.join(root, 'app/components/HelpPanel.tsx')
|
const helpPath = path.join(root, 'app/components/HelpPanel.tsx')
|
||||||
@@ -26,7 +31,7 @@ const sidebarPath = path.join(root, 'app/components/Sidebar.tsx')
|
|||||||
const sandboxListPath = path.join(root, 'app/components/SandboxList.tsx')
|
const sandboxListPath = path.join(root, 'app/components/SandboxList.tsx')
|
||||||
const pagePath = path.join(root, 'app/page.tsx')
|
const pagePath = path.join(root, 'app/page.tsx')
|
||||||
|
|
||||||
const [storeSource, brokerStoreSource, brokerClientSource, manifestSource, privilegedFilesSource, routeSource, uploadRouteSource, preflightRouteSource, healthRouteSource, registryRouteSource, brokerCapabilitiesRouteSource, brokerCallRouteSource, sandboxMcpRouteSource, brokerUrlSource, preflightLibSource, middlewareSource, panelSource, helpSource, sidebarSource, sandboxListSource, pageSource] = await Promise.all([
|
const [storeSource, brokerStoreSource, brokerClientSource, manifestSource, privilegedFilesSource, routeSource, uploadRouteSource, preflightRouteSource, healthRouteSource, registryRouteSource, registriesRouteSource, registriesAssistRouteSource, installAssistRouteSource, registryStoreSource, brokerCapabilitiesRouteSource, brokerCallRouteSource, sandboxMcpRouteSource, brokerUrlSource, preflightLibSource, preflightRepairLibSource, middlewareSource, panelSource, helpSource, sidebarSource, sandboxListSource, pageSource] = await Promise.all([
|
||||||
readFile(storePath, 'utf8'),
|
readFile(storePath, 'utf8'),
|
||||||
readFile(brokerStorePath, 'utf8'),
|
readFile(brokerStorePath, 'utf8'),
|
||||||
readFile(brokerClientPath, 'utf8'),
|
readFile(brokerClientPath, 'utf8'),
|
||||||
@@ -37,11 +42,16 @@ const [storeSource, brokerStoreSource, brokerClientSource, manifestSource, privi
|
|||||||
readFile(preflightRoutePath, 'utf8'),
|
readFile(preflightRoutePath, 'utf8'),
|
||||||
readFile(healthRoutePath, 'utf8'),
|
readFile(healthRoutePath, 'utf8'),
|
||||||
readFile(registryRoutePath, 'utf8'),
|
readFile(registryRoutePath, 'utf8'),
|
||||||
|
readFile(registriesRoutePath, 'utf8'),
|
||||||
|
readFile(registriesAssistRoutePath, 'utf8'),
|
||||||
|
readFile(installAssistRoutePath, 'utf8'),
|
||||||
|
readFile(registryStorePath, 'utf8'),
|
||||||
readFile(brokerCapabilitiesRoutePath, 'utf8'),
|
readFile(brokerCapabilitiesRoutePath, 'utf8'),
|
||||||
readFile(brokerCallRoutePath, 'utf8'),
|
readFile(brokerCallRoutePath, 'utf8'),
|
||||||
readFile(sandboxMcpRoutePath, 'utf8'),
|
readFile(sandboxMcpRoutePath, 'utf8'),
|
||||||
readFile(brokerUrlPath, 'utf8'),
|
readFile(brokerUrlPath, 'utf8'),
|
||||||
readFile(preflightLibPath, 'utf8'),
|
readFile(preflightLibPath, 'utf8'),
|
||||||
|
readFile(preflightRepairLibPath, 'utf8'),
|
||||||
readFile(middlewarePath, 'utf8'),
|
readFile(middlewarePath, 'utf8'),
|
||||||
readFile(panelPath, 'utf8'),
|
readFile(panelPath, 'utf8'),
|
||||||
readFile(helpPath, 'utf8'),
|
readFile(helpPath, 'utf8'),
|
||||||
@@ -108,6 +118,8 @@ assert.match(uploadRouteSource, /python-module/, 'MCP upload API must support Py
|
|||||||
assert.match(uploadRouteSource, /console-script/, 'MCP upload API must support installed console script launch')
|
assert.match(uploadRouteSource, /console-script/, 'MCP upload API must support installed console script launch')
|
||||||
assert.match(uploadRouteSource, /resolveProjectRoot/, 'MCP upload API must find project manifests inside uploaded directories')
|
assert.match(uploadRouteSource, /resolveProjectRoot/, 'MCP upload API must find project manifests inside uploaded directories')
|
||||||
assert.match(uploadRouteSource, /preflightMcpServer/, 'MCP upload API must preflight uploaded server bundles')
|
assert.match(uploadRouteSource, /preflightMcpServer/, 'MCP upload API must preflight uploaded server bundles')
|
||||||
|
assert.match(uploadRouteSource, /repairUploadedMcpServerWithLlm/, 'MCP upload API must attempt bounded LLM repair when uploaded server preflight fails')
|
||||||
|
assert.match(uploadRouteSource, /form\.get\("sandboxId"\)/, 'MCP upload API must accept a sandbox id so repair can mirror that sandbox LLM route')
|
||||||
assert.match(uploadRouteSource, /preflight-failed/, 'MCP upload API must mark failed preflight installs')
|
assert.match(uploadRouteSource, /preflight-failed/, 'MCP upload API must mark failed preflight installs')
|
||||||
assert.match(uploadRouteSource, /installMcpServer/, 'MCP upload API must install uploaded server bundles')
|
assert.match(uploadRouteSource, /installMcpServer/, 'MCP upload API must install uploaded server bundles')
|
||||||
assert.match(preflightRouteSource, /export async function POST/, 'MCP preflight API must expose a POST check endpoint')
|
assert.match(preflightRouteSource, /export async function POST/, 'MCP preflight API must expose a POST check endpoint')
|
||||||
@@ -115,6 +127,11 @@ assert.match(preflightRouteSource, /preflightMcpServer/, 'MCP preflight API must
|
|||||||
assert.match(preflightLibSource, /listBrokerServerTools/, 'MCP preflight must validate servers through SDK tool discovery')
|
assert.match(preflightLibSource, /listBrokerServerTools/, 'MCP preflight must validate servers through SDK tool discovery')
|
||||||
assert.match(preflightLibSource, /attempted relative import/, 'MCP preflight assistant must recognize Python package launch failures')
|
assert.match(preflightLibSource, /attempted relative import/, 'MCP preflight assistant must recognize Python package launch failures')
|
||||||
assert.match(preflightLibSource, /FastMCP/, 'MCP preflight assistant must recognize MCP SDK compatibility failures')
|
assert.match(preflightLibSource, /FastMCP/, 'MCP preflight assistant must recognize MCP SDK compatibility failures')
|
||||||
|
assert.match(preflightRepairLibSource, /getSandboxInferenceConfig/, 'MCP preflight repair must reuse the selected sandbox inference profile when available')
|
||||||
|
assert.match(preflightRepairLibSource, /chat\/completions/, 'MCP preflight repair must call an OpenAI-compatible chat endpoint')
|
||||||
|
assert.match(preflightRepairLibSource, /response_format: \{ type: "json_object" \}/, 'MCP preflight repair must ask the model for structured JSON')
|
||||||
|
assert.match(preflightRepairLibSource, /repair path must stay inside the uploaded server/, 'MCP preflight repair must confine edits to the uploaded server')
|
||||||
|
assert.match(preflightRepairLibSource, /provided context/, 'MCP preflight repair must only edit files shown to the model')
|
||||||
assert.match(healthRouteSource, /listBrokerServerTools/, 'MCP health API must inspect server tools through the broker client')
|
assert.match(healthRouteSource, /listBrokerServerTools/, 'MCP health API must inspect server tools through the broker client')
|
||||||
assert.match(healthRouteSource, /enabledServers/, 'MCP health API must check enabled MCP servers')
|
assert.match(healthRouteSource, /enabledServers/, 'MCP health API must check enabled MCP servers')
|
||||||
assert.match(registryRouteSource, /registry\.modelcontextprotocol\.io/, 'MCP registry search should default to the official registry')
|
assert.match(registryRouteSource, /registry\.modelcontextprotocol\.io/, 'MCP registry search should default to the official registry')
|
||||||
@@ -122,8 +139,20 @@ assert.match(registryRouteSource, /\/v0\/servers/, 'MCP registry search should c
|
|||||||
assert.match(registryRouteSource, /normalizeRegistryEntry/, 'MCP registry search should normalize results into installable entries')
|
assert.match(registryRouteSource, /normalizeRegistryEntry/, 'MCP registry search should normalize results into installable entries')
|
||||||
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(registryRouteSource, /searchParams\.get\("baseUrl"\)/, 'MCP registry search must accept a selected registry base URL')
|
||||||
assert.match(panelSource, /Upload Server/, 'MCP custom server accordion must support uploaded server bundles')
|
assert.match(registryStoreSource, /mcp-registries\.json/, 'MCP registries must persist to dashboard state')
|
||||||
|
assert.match(registryStoreSource, /DEFAULT_MCP_REGISTRY/, 'MCP registries should start with the official registry before user changes')
|
||||||
|
assert.match(registriesRouteSource, /listMcpRegistries/, 'MCP registries API must list registries')
|
||||||
|
assert.match(registriesRouteSource, /saveMcpRegistry/, 'MCP registries API must save registries')
|
||||||
|
assert.match(registriesRouteSource, /deleteMcpRegistry/, 'MCP registries API must delete registries')
|
||||||
|
assert.match(registriesAssistRouteSource, /chat\/completions/, 'MCP registry assistant must use the running OpenAI-compatible LLM endpoint')
|
||||||
|
assert.match(registriesAssistRouteSource, /response_format: \{ type: "json_object" \}/, 'MCP registry assistant must request structured JSON')
|
||||||
|
assert.match(installAssistRouteSource, /chat\/completions/, 'MCP install wizard assistant must use the running OpenAI-compatible LLM endpoint')
|
||||||
|
assert.match(installAssistRouteSource, /uploadRuntime/, 'MCP install wizard assistant must draft upload metadata')
|
||||||
|
assert.match(installAssistRouteSource, /response_format: \{ type: "json_object" \}/, 'MCP install wizard assistant must request structured JSON')
|
||||||
|
assert.match(panelSource, /Install Server Command/, 'MCP page must expose a server command install action')
|
||||||
|
assert.match(panelSource, /Server Install Wizard/, 'MCP page must present custom installation as a wizard')
|
||||||
|
assert.match(panelSource, /Upload and Preflight/, 'MCP custom server accordion must support uploaded server bundles')
|
||||||
assert.match(panelSource, /Choose Directory/, 'MCP custom server upload must accept directories')
|
assert.match(panelSource, /Choose Directory/, 'MCP custom server upload must accept directories')
|
||||||
assert.match(panelSource, /Choose Archive/, 'MCP custom server upload must accept archives')
|
assert.match(panelSource, /Choose Archive/, 'MCP custom server upload must accept archives')
|
||||||
assert.match(panelSource, /\/api\/mcp\/upload/, 'MCP custom server upload must call the upload API')
|
assert.match(panelSource, /\/api\/mcp\/upload/, 'MCP custom server upload must call the upload API')
|
||||||
@@ -132,13 +161,29 @@ assert.match(panelSource, /uploadEntrypoint/, 'MCP custom server upload must col
|
|||||||
assert.match(panelSource, /uploadEntryMode/, 'MCP custom server upload must collect a launch mode')
|
assert.match(panelSource, /uploadEntryMode/, 'MCP custom server upload must collect a launch mode')
|
||||||
assert.match(panelSource, /Python module/, 'MCP custom server upload must expose Python module launch mode')
|
assert.match(panelSource, /Python module/, 'MCP custom server upload must expose Python module launch mode')
|
||||||
assert.match(panelSource, /Console script/, 'MCP custom server upload must expose console script launch mode')
|
assert.match(panelSource, /Console script/, 'MCP custom server upload must expose console script launch mode')
|
||||||
|
assert.match(panelSource, /uploadRepair/, 'MCP custom server upload must expose LLM repair controls')
|
||||||
|
assert.match(panelSource, /repairSandboxId/, 'MCP custom server upload must let operators pick a sandbox LLM route for repair')
|
||||||
|
assert.match(panelSource, /LLM repair/, 'MCP custom server upload must summarize LLM-assisted repair results')
|
||||||
|
assert.match(panelSource, /FieldHint/, 'MCP server install wizard fields must include tooltips')
|
||||||
|
assert.match(panelSource, /wizardStep/, 'MCP server install wizard must expose install workflow steps')
|
||||||
|
assert.match(panelSource, /assistInstall/, 'MCP server install wizard must let the LLM draft install fields')
|
||||||
|
assert.match(panelSource, /Assist Install/, 'MCP server install wizard must expose an assist install action')
|
||||||
|
assert.match(panelSource, /Back/, 'MCP server install wizard must expose back navigation')
|
||||||
|
assert.match(panelSource, /Next/, 'MCP server install wizard must expose next navigation')
|
||||||
|
assert.match(panelSource, /Upload and Preflight/, 'MCP server install wizard must expose upload preflight as the upload action')
|
||||||
assert.match(panelSource, /preflightServer/, 'MCP page must let operators preflight installed servers')
|
assert.match(panelSource, /preflightServer/, 'MCP page must let operators preflight installed servers')
|
||||||
assert.match(panelSource, /Preflight/, 'MCP page must show preflight controls and results')
|
assert.match(panelSource, /Preflight/, 'MCP page must show preflight controls and results')
|
||||||
assert.match(panelSource, /serverPayloadFromJson/, 'MCP page must parse edited server JSON')
|
assert.match(panelSource, /serverPayloadFromJson/, 'MCP page must parse edited server JSON')
|
||||||
assert.match(panelSource, /startEditingServer/, 'MCP installed server list must expose edit state')
|
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, /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, /MCP Repo Search and Preconfigured Servers/, 'MCP page must combine repo search and preconfigured servers')
|
||||||
|
assert.match(panelSource, /Available Registries/, 'MCP page must display available registries')
|
||||||
|
assert.match(panelSource, /Add an MCP Registry/, 'MCP page must show an add-registry empty state')
|
||||||
|
assert.match(panelSource, /Draft With LLM/, 'MCP page must let the running LLM draft registry fields')
|
||||||
|
assert.match(panelSource, /Delete Selected Registry/, 'MCP page must allow deleting registries')
|
||||||
|
assert.match(panelSource, /selectedRegistryId/, 'MCP page must track and highlight the selected registry')
|
||||||
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, /\/api\/mcp\/registries/, 'MCP page must manage registry sources through the registry 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')
|
||||||
assert.match(panelSource, /setRegistryResults\(\[\]\)/, 'MCP registry search should clear stale results before a new search')
|
assert.match(panelSource, /setRegistryResults\(\[\]\)/, 'MCP registry search should clear stale results before a new search')
|
||||||
assert.match(panelSource, /pagedRegistryResults/, 'MCP registry search should render paged results instead of the full result set')
|
assert.match(panelSource, /pagedRegistryResults/, 'MCP registry search should render paged results instead of the full result set')
|
||||||
@@ -146,6 +191,8 @@ assert.match(panelSource, /Preconfigured Servers/, 'MCP page should label catalo
|
|||||||
assert.match(panelSource, /aria-expanded=\{catalogOpen\}/, 'MCP preconfigured servers should render as an accordion')
|
assert.match(panelSource, /aria-expanded=\{catalogOpen\}/, 'MCP preconfigured servers should render as an accordion')
|
||||||
assert.match(panelSource, /aria-expanded=\{customOpen\}/, 'MCP custom server form should render as an accordion')
|
assert.match(panelSource, /aria-expanded=\{customOpen\}/, 'MCP custom server form should render as an accordion')
|
||||||
assert.match(panelSource, /MCP Security/, 'MCP page must expose sandbox access controls')
|
assert.match(panelSource, /MCP Security/, 'MCP page must expose sandbox access controls')
|
||||||
|
assert.match(panelSource, /openSecurityServers/, 'MCP security must render installed servers as sub accordions')
|
||||||
|
assert.match(panelSource, /aria-expanded=\{securityOpen\}/, 'MCP security must render as an accordion')
|
||||||
assert.match(panelSource, /Allow All/, 'MCP security must support allow-all access')
|
assert.match(panelSource, /Allow All/, 'MCP security must support allow-all access')
|
||||||
assert.match(panelSource, /Allow Only/, 'MCP security must support allow-list access')
|
assert.match(panelSource, /Allow Only/, 'MCP security must support allow-list access')
|
||||||
assert.match(panelSource, /syncSandboxBrokerConfig/, 'MCP configuration grants must sync the sandbox broker config automatically')
|
assert.match(panelSource, /syncSandboxBrokerConfig/, 'MCP configuration grants must sync the sandbox broker config automatically')
|
||||||
|
|||||||
Reference in New Issue
Block a user