Skip to content

AI-native design editor. Open-source Figma alternative.

fix(automation): avoid redundant MCP restarts

Danila Poyarkov6be82c115e94
diff --git a/src/app/automation/bridge/vite-plugin.ts b/src/app/automation/bridge/vite-plugin.ts
index c6e18c7a1..fb5af73aa 100644
--- a/src/app/automation/bridge/vite-plugin.ts
+++ b/src/app/automation/bridge/vite-plugin.ts
@@ -50,7 +50,7 @@ export function createAutomationEnvironment(
const MAX_CONFIGURATION_BYTES = 70_000
const CHILD_EXIT_TIMEOUT_MS = 2_000
-const CHILD_HEALTH_ATTEMPTS = 40
+const CHILD_HEALTH_ATTEMPTS = 200
const CHILD_HEALTH_DELAY_MS = 50
type DevMCPConfigurationErrorStatus = 400 | 413
@@ -133,6 +133,18 @@ function safeRuntimeId(value: string): string {
return createHash('sha256').update(value).digest('hex').slice(0, 16)
}
+export function configurationsMatch(
+ current: DevMCPConfiguration,
+ next: DevMCPConfiguration
+): boolean {
+ return (
+ current.authenticationEnabled === next.authenticationEnabled &&
+ current.rootDirectory === next.rootDirectory &&
+ current.disabledTools.length === next.disabledTools.length &&
+ current.disabledTools.every((tool, index) => tool === next.disabledTools[index])
+ )
+}
+
// TODO: production — bundle MCP server as Tauri sidecar or spawn via shell plugin
export function automationPlugin(
authToken: string | null,
@@ -223,6 +235,7 @@ export function automationPlugin(
}
async function restartChild(nextConfiguration: DevMCPConfiguration): Promise<void> {
+ if (child && configurationsMatch(configuration, nextConfiguration)) return
configuration = nextConfiguration
await stopChild()
await startChild()
diff --git a/tests/engine/app/automation/mcp-vite-plugin.test.ts b/tests/engine/app/automation/mcp-vite-plugin.test.ts
index 261bc45f2..1c16718a1 100644
--- a/tests/engine/app/automation/mcp-vite-plugin.test.ts
+++ b/tests/engine/app/automation/mcp-vite-plugin.test.ts
@@ -4,6 +4,7 @@ import { Readable } from 'node:stream'
import {
DevMCPConfigurationSyntaxError,
DevMCPConfigurationTooLargeError,
+ configurationsMatch,
createAutomationEnvironment,
devMCPConfigurationErrorStatus,
readDevMCPConfiguration,
@@ -72,6 +73,18 @@ describe('MCP Vite development server', () => {
})
})
+ test('does not restart MCP for unchanged configuration', () => {
+ const configuration = {
+ authenticationEnabled: true,
+ rootDirectory: '/designs',
+ disabledTools: ['eval', 'delete_node']
+ }
+ expect(configurationsMatch(configuration, structuredClone(configuration))).toBe(true)
+ expect(
+ configurationsMatch(configuration, { ...configuration, disabledTools: ['delete_node'] })
+ ).toBe(false)
+ })
+
test('waits through transient Portless responses until MCP is healthy', async () => {
const statuses = [404, 404, 200]
const requests: string[] = []