From c3ae05c8fc4f93ebb86ebd58e964e573a368a261 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sat, 20 Sep 2025 19:19:38 +0200 Subject: [PATCH] Track handler responses being sent --- penpot-plugin/src/TaskHandler.ts | 8 ++++++++ penpot-plugin/src/plugin.ts | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/penpot-plugin/src/TaskHandler.ts b/penpot-plugin/src/TaskHandler.ts index a7d005a..4c576c6 100644 --- a/penpot-plugin/src/TaskHandler.ts +++ b/penpot-plugin/src/TaskHandler.ts @@ -2,6 +2,8 @@ * Represents a task received from the MCP server in the Penpot MCP plugin */ export class Task { + public isResponseSent: boolean = false; + /** * @param requestId Unique identifier for the task request * @param taskType The type of the task to execute @@ -13,6 +15,11 @@ export class Task { * Sends a task response back to the MCP server. */ protected sendResponse(success: boolean, data: any = undefined, error: any = undefined): void { + if (this.isResponseSent) { + console.error("Response already sent for task:", this.requestId); + return; + } + const response = { type: "task-response", response: { @@ -26,6 +33,7 @@ export class Task { // Send to main.ts which will forward to MCP server via WebSocket penpot.ui.sendMessage(response); console.log("Sent task response:", response); + this.isResponseSent = true; } public sendSuccess(data: any = undefined): void { diff --git a/penpot-plugin/src/plugin.ts b/penpot-plugin/src/plugin.ts index aa5d220..56ab7c2 100644 --- a/penpot-plugin/src/plugin.ts +++ b/penpot-plugin/src/plugin.ts @@ -52,6 +52,13 @@ function handlePluginTaskRequest(request: { id: string; task: string; params: an // Cast the params to the expected type and handle the task console.log("Processing task with handler:", handler); handler.handle(task); + + // check whether a response was sent and send a generic success if not + if (!task.isResponseSent) { + console.warn("Handler did not send a response, sending generic success."); + task.sendSuccess("Task completed without a specific response."); + } + console.log("Task handled successfully:", task); } catch (error) { console.error("Error handling task:", error);