From 03d0c62de18dfe4c227dac292a4c3955483b67a2 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 18 Feb 2026 13:16:13 +0100 Subject: [PATCH] :bug: Send a keep alive message in websocket connection --- mcp/packages/plugin/src/main.ts | 11 ++++++++++- mcp/packages/server/src/PluginBridge.ts | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mcp/packages/plugin/src/main.ts b/mcp/packages/plugin/src/main.ts index 6f4b5f25b2..8ead32231c 100644 --- a/mcp/packages/plugin/src/main.ts +++ b/mcp/packages/plugin/src/main.ts @@ -1,5 +1,7 @@ import "./style.css"; +const KEEP_ALIVE_TIME = 30000; // 30 seconds + // get the current theme from the URL const searchParams = new URLSearchParams(window.location.search); document.body.dataset.theme = searchParams.get("theme") ?? "light"; @@ -72,8 +74,12 @@ function connectToMcpServer(baseUrl?: string, token?: string): void { }; ws.onmessage = (event) => { - console.log("Received from MCP server:", event.data); try { + if (event.data === "keep-alive") { + // Keep alive response, ignore it + return; + } + console.log("Received from MCP server:", event.data); const request = JSON.parse(event.data); // Forward the task request to the plugin for execution parent.postMessage(request, "*"); @@ -82,8 +88,11 @@ function connectToMcpServer(baseUrl?: string, token?: string): void { } }; + const interval = setInterval(() => ws?.send("keep-alive"), KEEP_ALIVE_TIME); + ws.onclose = (event: CloseEvent) => { console.log("Disconnected from MCP server"); + clearInterval(interval); const message = event.reason || undefined; updateConnectionStatus("disconnected", "Disconnected", false, message); ws = null; diff --git a/mcp/packages/server/src/PluginBridge.ts b/mcp/packages/server/src/PluginBridge.ts index 413ec2fa70..ebdc38f819 100644 --- a/mcp/packages/server/src/PluginBridge.ts +++ b/mcp/packages/server/src/PluginBridge.ts @@ -72,6 +72,10 @@ export class PluginBridge { ws.on("message", (data: Buffer) => { this.logger.debug("Received WebSocket message: %s", data.toString()); try { + if (data.toString() === "keep-alive") { + ws.send("keep-alive"); + return; + } const response: PluginTaskResponse = JSON.parse(data.toString()); this.handlePluginTaskResponse(response); } catch (error) {