From b7fcf828583c07841ed0cec66bc202be7e0c401d Mon Sep 17 00:00:00 2001 From: Denozordec Date: Sat, 21 Nov 2026 20:27:23 +0700 Subject: [PATCH] =?UTF-8?q?fix(mcp):=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BA=D1=80=D0=B5=D0=BF=D0=BB=D1=8F=D0=B5=D1=82=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8E=20MCP=20=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit На свежей базе после миграций: mcp_settings.enabled=false, ни одного включённого профиля контроллера, значение столбца по умолчанию false, autoRecovery по умолчанию false; выключенный MCP отказывает токену MCP_DISABLED/503, повторное включение возвращает тот же доступ. Co-Authored-By: Claude Opus 5.5 --- backend/src/modules/mcp/integration.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) 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[] }