Add MCP broker access controls

This commit is contained in:
Codex
2026-04-26 21:33:23 +00:00
parent db4d8ed7b8
commit faa51e3974
18 changed files with 2838 additions and 73 deletions
+98
View File
@@ -0,0 +1,98 @@
import assert from 'node:assert/strict'
import path from 'node:path'
import { readFile } from 'node:fs/promises'
const root = process.cwd()
const storePath = path.join(root, 'app/lib/mcpServerStore.ts')
const brokerStorePath = path.join(root, 'app/lib/mcpBrokerStore.ts')
const brokerClientPath = path.join(root, 'app/lib/mcpBrokerClient.ts')
const manifestPath = path.join(root, 'app/lib/sandboxMcpManifest.ts')
const routePath = path.join(root, 'app/api/mcp/route.ts')
const registryRoutePath = path.join(root, 'app/api/mcp/registry/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 sandboxMcpRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/mcp/route.ts')
const panelPath = path.join(root, 'app/components/McpConfigurationPanel.tsx')
const sidebarPath = path.join(root, 'app/components/Sidebar.tsx')
const sandboxListPath = path.join(root, 'app/components/SandboxList.tsx')
const pagePath = path.join(root, 'app/page.tsx')
const [storeSource, brokerStoreSource, brokerClientSource, manifestSource, routeSource, registryRouteSource, brokerCapabilitiesRouteSource, brokerCallRouteSource, sandboxMcpRouteSource, panelSource, sidebarSource, sandboxListSource, pageSource] = await Promise.all([
readFile(storePath, 'utf8'),
readFile(brokerStorePath, 'utf8'),
readFile(brokerClientPath, 'utf8'),
readFile(manifestPath, 'utf8'),
readFile(routePath, 'utf8'),
readFile(registryRoutePath, 'utf8'),
readFile(brokerCapabilitiesRoutePath, 'utf8'),
readFile(brokerCallRoutePath, 'utf8'),
readFile(sandboxMcpRoutePath, 'utf8'),
readFile(panelPath, 'utf8'),
readFile(sidebarPath, 'utf8'),
readFile(sandboxListPath, 'utf8'),
readFile(pagePath, 'utf8'),
])
assert.match(storeSource, /export const MCP_SERVER_CATALOG/, 'MCP store must expose an install catalog')
assert.match(storeSource, /blendermcp\.org/, 'MCP catalog must include the requested BlenderMCP site')
assert.match(storeSource, /args:\s*\["blender-mcp"\]/, 'MCP catalog must install BlenderMCP via uvx blender-mcp')
assert.match(storeSource, /mcp-servers\.json/, 'MCP installs must persist to dashboard state')
assert.match(storeSource, /accessMode/, 'MCP installs must persist sandbox access mode')
assert.match(storeSource, /allowedSandboxIds/, 'MCP installs must persist allowed sandbox lists')
assert.match(storeSource, /existing\?\.accessMode \|\| "disabled"/, 'MCP server access should default to disabled for sandboxes')
assert.match(storeSource, /export function buildMcpClientConfig/, 'MCP store must export client config JSON')
assert.match(storeSource, /mcpServers/, 'MCP client config must use the common mcpServers shape')
assert.match(brokerStoreSource, /mcp-broker-sessions\.json/, 'MCP broker sessions must persist server-side')
assert.match(brokerStoreSource, /verifySandboxMcpBrokerToken/, 'MCP broker must verify sandbox tokens server-side')
assert.match(brokerStoreSource, /listAllowedBrokerServers/, 'MCP broker must filter servers by access policy')
assert.match(brokerClientSource, /@modelcontextprotocol\/sdk\/client\/index\.js/, 'MCP broker must use the official SDK client')
assert.match(brokerClientSource, /StdioClientTransport/, 'MCP broker must support stdio servers')
assert.match(brokerClientSource, /StreamableHTTPClientTransport/, 'MCP broker must support streamable HTTP servers')
assert.match(brokerClientSource, /callBrokerServerTool/, 'MCP broker must forward allowed tool calls')
assert.match(manifestSource, /openshell_control_mcp\.md/, 'MCP sandbox manifest must use the requested filename')
assert.match(manifestSource, /syncSandboxMcpManifest/, 'MCP sandbox manifest must be syncable into a sandbox')
assert.doesNotMatch(manifestSource, /allowedServers|renderServer|commandLine/, 'MCP sandbox handoff must not disclose server inventory or launch specs')
assert.match(manifestSource, /control plane enforces/, 'MCP sandbox handoff must explain broker-side enforcement')
assert.match(brokerCapabilitiesRouteSource, /listAllowedBrokerServers/, 'MCP broker capabilities must only list allowed servers')
assert.match(brokerCapabilitiesRouteSource, /listBrokerServerTools/, 'MCP broker capabilities must inspect allowed server tools')
assert.match(brokerCallRouteSource, /Requested MCP capability is unavailable/, 'MCP broker denied calls must not disclose blocked server names')
assert.match(brokerCallRouteSource, /callBrokerServerTool/, 'MCP broker call route must forward allowed calls')
assert.match(sandboxMcpRouteSource, /export async function POST/, 'Sandbox MCP route must write the broker handoff')
assert.match(sandboxMcpRouteSource, /export async function GET/, 'Sandbox MCP route must preview the broker handoff')
assert.match(routeSource, /export async function GET/, 'MCP API must list server configuration')
assert.match(routeSource, /export async function POST/, 'MCP API must install and update server configuration')
assert.match(routeSource, /installMcpServer/, 'MCP API must support installing servers')
assert.match(routeSource, /uninstallMcpServer/, 'MCP API must support removing servers')
assert.match(routeSource, /updateMcpServerAccess/, 'MCP API must support access policy updates')
assert.match(registryRouteSource, /registry\.modelcontextprotocol\.io/, 'MCP registry search should default to the official registry')
assert.match(registryRouteSource, /\/v0\/servers/, 'MCP registry search should call the registry server list endpoint')
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, /remoteInstall/, 'MCP registry search should support remote HTTP installs')
assert.match(panelSource, /Install Custom Server/, 'MCP page must expose a custom server install action')
assert.match(panelSource, /Registry Search/, 'MCP page must expose official registry search')
assert.match(panelSource, /\/api\/mcp\/registry/, 'MCP page must query the registry search API')
assert.match(panelSource, /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, /pagedRegistryResults/, 'MCP registry search should render paged results instead of the full result set')
assert.match(panelSource, /Preconfigured Servers/, 'MCP page should label catalog presets as preconfigured servers')
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, /MCP Security/, 'MCP page must expose sandbox access controls')
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, /Setup Guide/, 'MCP catalog cards should link out to app setup guides')
assert.match(panelSource, /Client JSON/, 'MCP page must surface generated client JSON')
assert.match(sandboxListSource, /Allowed MCP Server Access/, 'Sandbox page must expose allowed MCP server access accordion')
assert.match(sandboxListSource, /Issue Broker Config/, 'Sandbox MCP access controls must issue broker config')
assert.match(sandboxListSource, /\/sandbox\/openshell_control_mcp\.md/, 'Sandbox MCP access controls must name the manifest path')
assert.match(sandboxListSource, /sandboxCanAccessMcpServer/, 'Sandbox page must derive MCP access per sandbox')
assert.match(sandboxListSource, /MCP access allowed/, 'Sandbox cards must show a lit MCP access indicator')
assert.match(sandboxListSource, /Revoke/, 'Sandbox MCP access controls must include revoke')
assert.match(sidebarSource, /onMcpClick/, 'Sidebar must include MCP navigation callback')
assert.match(sidebarSource, /activeView === 'mcp'/, 'Sidebar must mark MCP view active')
assert.match(pageSource, /McpConfigurationPanel/, 'Dashboard must render MCP configuration panel')
assert.match(pageSource, /setActiveView\('mcp'\)/, 'Dashboard must switch to MCP view')
console.log('mcp-configuration-page-check: PASS MCP dashboard assertions')