Configure sandbox MCP broker access

This commit is contained in:
mmckeen-nv
2026-04-29 13:01:59 -07:00
parent 6b2451e216
commit 10f5a0b6aa
11 changed files with 626 additions and 66 deletions
+28 -10
View File
@@ -6,6 +6,7 @@ import {
updateMcpServerAccess,
uninstallMcpServer,
} from "@/app/lib/mcpServerStore"
import { autoSyncSandboxMcpAccess } from "@/app/lib/mcpSandboxAutoSync"
export async function GET() {
try {
@@ -23,29 +24,44 @@ export async function POST(request: Request) {
if (action === "uninstall") {
const serverId = typeof body?.serverId === "string" ? body.serverId : ""
return NextResponse.json({ server: await uninstallMcpServer(serverId), ...(await listMcpServers()) })
const before = await listMcpServers()
const server = await uninstallMcpServer(serverId)
const after = await listMcpServers()
const sandboxSync = await autoSyncSandboxMcpAccess(request, before.servers, after.servers, [server.id])
return NextResponse.json({ server, ...after, sandboxSync })
}
if (action === "enable" || action === "disable") {
const serverId = typeof body?.serverId === "string" ? body.serverId : ""
const before = await listMcpServers()
const server = await setMcpServerEnabled(serverId, action === "enable")
const after = await listMcpServers()
const sandboxSync = await autoSyncSandboxMcpAccess(request, before.servers, after.servers, [server.id])
return NextResponse.json({
server: await setMcpServerEnabled(serverId, action === "enable"),
...(await listMcpServers()),
server,
...after,
sandboxSync,
})
}
if (action === "update-access") {
const serverId = typeof body?.serverId === "string" ? body.serverId : ""
const before = await listMcpServers()
const server = await updateMcpServerAccess(serverId, {
enabled: typeof body?.enabled === "boolean" ? body.enabled : undefined,
accessMode: body?.accessMode,
allowedSandboxIds: Array.isArray(body?.allowedSandboxIds) ? body.allowedSandboxIds : undefined,
})
const after = await listMcpServers()
const sandboxSync = await autoSyncSandboxMcpAccess(request, before.servers, after.servers, [server.id])
return NextResponse.json({
server: await updateMcpServerAccess(serverId, {
enabled: typeof body?.enabled === "boolean" ? body.enabled : undefined,
accessMode: body?.accessMode,
allowedSandboxIds: Array.isArray(body?.allowedSandboxIds) ? body.allowedSandboxIds : undefined,
}),
...(await listMcpServers()),
server,
...after,
sandboxSync,
})
}
const before = await listMcpServers()
const server = await installMcpServer({
id: body?.id,
name: body?.name,
@@ -61,8 +77,10 @@ export async function POST(request: Request) {
accessMode: body?.accessMode,
allowedSandboxIds: body?.allowedSandboxIds,
})
const after = await listMcpServers()
const sandboxSync = await autoSyncSandboxMcpAccess(request, before.servers, after.servers, [server.id])
return NextResponse.json({ server, ...(await listMcpServers()) })
return NextResponse.json({ server, ...after, sandboxSync })
} catch (error) {
const message = error instanceof Error ? error.message : "Failed to update MCP servers"
return NextResponse.json({ error: message }, { status: 400 })