diff --git a/backend/src/modules/mcp/integration.test.ts b/backend/src/modules/mcp/integration.test.ts index b25d9d5e..ba18cf24 100644 --- a/backend/src/modules/mcp/integration.test.ts +++ b/backend/src/modules/mcp/integration.test.ts @@ -647,6 +647,11 @@ try { // downloads disabled in this owned fixture before any telemetry refresh. await pool.query("INSERT INTO geoip_settings(id,enabled) VALUES(1,false) ON CONFLICT(id) DO UPDATE SET enabled=false") await pool.query("INSERT INTO servers(id,name,host,port,use_ssl) VALUES(1,'test-router','127.0.0.1',$1,false),(2,'outside-scope','127.0.0.1',$1,false)", [port]) + // A fresh installation keeps MCP and the route controller off until an administrator enables them (completion plan, stage 5). + assert.equal((await pool.query("SELECT enabled FROM mcp_settings WHERE id=1")).rows[0].enabled, false) + assert.equal((await pool.query("SELECT count(*)::int AS n FROM mcp_routing_profiles WHERE enabled")).rows[0].n, 0) + assert.equal((await pool.query("SELECT column_default FROM information_schema.columns WHERE table_schema='public' AND table_name='mcp_routing_profiles' AND column_name='enabled'")).rows[0].column_default, "false") + assert.equal((await import("@mmapp/contracts/mcp-routing")).routeAiProfileSchema.shape.autoRecovery.parse(undefined), false) await updateMcpSettings({ enabled: true }, actor) const { registerManagementChannel, verifyManagementChannel } = await import("./management.js") let alternateIdentity = "fixture-primary" @@ -666,6 +671,12 @@ try { const input = mcpConnectionCreateSchema.parse({ name: "Integration", mode: "approval", expiresAt: new Date(fixtureAuthExpiresAt).toISOString(), permissions: ["mm:network:write", "mm:servers:read"], scope: { serverIds: [1], operationIds: ["ros.ip_settings.list", "ros.ip_settings.update", "servers.list", "operations.recover", "operations.reconcile"], allowGlobal: false } }) const issued = await createMcpConnection(input, actor) const principal = await authenticateMcpToken(issued.token) + // Switching MCP off refuses every token at once; switching it back on restores the same credential. + await updateMcpSettings({ enabled: false }, actor) + await assert.rejects(authenticateMcpToken(issued.token), (error: unknown) => (error as { code?: string }).code === "MCP_DISABLED" && (error as { statusCode?: number }).statusCode === 503) + await updateMcpSettings({ enabled: true }, actor) + assert.equal((await authenticateMcpToken(issued.token)).connectionId, principal.connectionId) + console.log("✓ Fresh install: MCP off, no enabled controller profile, autoRecovery off; disabled MCP refuses tokens") const credentials = await pool.query("SELECT digest FROM mcp_credentials WHERE connection_id=$1", [issued.connection.id]) assert.equal(credentials.rows[0].digest, tokenDigest(issued.token)); assert.notEqual(credentials.rows[0].digest, issued.token) const read = await invokeMcpTool(principal, "mm_ip_settings_list", { serverId: 1 }) as { items: unknown[] }