Configure sandbox MCP broker access
This commit is contained in:
@@ -402,34 +402,12 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
||||
current.delete(sandbox.id)
|
||||
current.delete(sandbox.name)
|
||||
if (allowed) current.add(sandbox.id)
|
||||
const hasOtherMcpAccess = servers.some((candidate) => candidate.id !== server.id && sandboxAllowed(candidate, sandbox))
|
||||
return postUpdate({
|
||||
action: "update-access",
|
||||
serverId: server.id,
|
||||
accessMode: "allow_only",
|
||||
allowedSandboxIds: Array.from(current),
|
||||
}, `${server.name} sandbox access updated.`).then((updated) => {
|
||||
if (!updated) return
|
||||
return syncSandboxBrokerConfig(sandbox, allowed || hasOtherMcpAccess ? "sync" : "revoke")
|
||||
})
|
||||
}
|
||||
|
||||
async function syncSandboxBrokerConfig(sandbox: McpSandbox, action: "sync" | "revoke" = "sync") {
|
||||
try {
|
||||
setSaving(true)
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/mcp`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ sandboxName: sandbox.name, action }),
|
||||
})
|
||||
const data = await response.json()
|
||||
if (!response.ok) throw new Error(data.error || "Failed to sync MCP broker config")
|
||||
setMessage(data.note || (action === "revoke" ? `${sandbox.name} MCP broker config revoked.` : `${sandbox.name} MCP broker config synced.`))
|
||||
} catch (error) {
|
||||
setMessage(error instanceof Error ? error.message : "Failed to sync MCP broker config")
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}, `${server.name} sandbox access updated.`)
|
||||
}
|
||||
|
||||
async function syncAccessModeChange(server: McpServerInstall, accessMode: string) {
|
||||
@@ -439,20 +417,6 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
||||
accessMode,
|
||||
}, `${server.name} availability updated.`)
|
||||
if (!updated) return
|
||||
|
||||
if (accessMode === "allow_all") {
|
||||
await Promise.all(sandboxes.map((sandbox) => syncSandboxBrokerConfig(sandbox)))
|
||||
return
|
||||
}
|
||||
|
||||
if (accessMode === "disabled") {
|
||||
await Promise.all(sandboxes
|
||||
.filter((sandbox) => sandboxAllowed(server, sandbox))
|
||||
.map((sandbox) => {
|
||||
const hasOtherMcpAccess = servers.some((candidate) => candidate.id !== server.id && sandboxAllowed(candidate, sandbox))
|
||||
return syncSandboxBrokerConfig(sandbox, hasOtherMcpAccess ? "sync" : "revoke")
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
async function setServerEnabled(server: McpServerInstall, enabled: boolean) {
|
||||
@@ -462,12 +426,6 @@ export default function McpConfigurationPanel({ sandboxes = [] }: McpConfigurati
|
||||
enabled,
|
||||
}, `${server.name} ${enabled ? "enabled" : "disabled"}.`)
|
||||
if (!updated) return
|
||||
|
||||
const affectedSandboxes = sandboxes.filter((sandbox) => sandboxAllowed(server, sandbox))
|
||||
await Promise.all(affectedSandboxes.map((sandbox) => {
|
||||
const hasOtherMcpAccess = servers.some((candidate) => candidate.id !== server.id && sandboxAllowed(candidate, sandbox))
|
||||
return syncSandboxBrokerConfig(sandbox, enabled || hasOtherMcpAccess ? "sync" : "revoke")
|
||||
}))
|
||||
}
|
||||
|
||||
function editableServerJson(server: McpServerInstall) {
|
||||
|
||||
@@ -305,11 +305,10 @@ export default function SandboxList({
|
||||
enabled: true,
|
||||
accessMode: server.accessMode === 'allow_all' ? 'allow_all' : 'allow_only',
|
||||
allowedSandboxIds: Array.from(current),
|
||||
}, `${server.name} enabled for ${sandbox.name}.`).then(() => syncMcpManifest(sandbox))
|
||||
}, `${server.name} enabled for ${sandbox.name}.`)
|
||||
}
|
||||
|
||||
const revokeMcpForSandbox = (sandbox: SandboxInventoryItem, server: McpServerAccess) => {
|
||||
const hasOtherMcpAccess = mcpServers.some((candidate) => candidate.id !== server.id && sandboxCanAccessMcpServer(sandbox, candidate))
|
||||
const current = new Set(server.allowedSandboxIds)
|
||||
current.delete(sandbox.id)
|
||||
current.delete(sandbox.name)
|
||||
@@ -321,7 +320,7 @@ export default function SandboxList({
|
||||
return updateMcpServerAccess(server, {
|
||||
accessMode: 'allow_only',
|
||||
allowedSandboxIds: Array.from(current),
|
||||
}, `${server.name} revoked from ${sandbox.name}.`).then(() => syncMcpManifest(sandbox, hasOtherMcpAccess ? 'sync' : 'revoke'))
|
||||
}, `${server.name} revoked from ${sandbox.name}.`)
|
||||
}
|
||||
|
||||
const resolvePermissionRequest = async (sandbox: SandboxInventoryItem, action: 'approve' | 'reject', chunkId: string) => {
|
||||
@@ -613,7 +612,7 @@ export default function SandboxList({
|
||||
<div>
|
||||
<h4 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Sandbox Manifest</h4>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">
|
||||
Writes <span className="font-mono text-[var(--foreground)]">/sandbox/openshell_control_mcp.md</span> with broker URL and sandbox token only.
|
||||
Writes <span className="font-mono text-[var(--foreground)]">/sandbox/openshell_control_mcp.md</span> and configures OpenClaw to use the broker MCP endpoint.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user