diff --git a/mcp-server/src/PenpotMcpServer.ts b/mcp-server/src/PenpotMcpServer.ts index 0582e9b..002ff08 100644 --- a/mcp-server/src/PenpotMcpServer.ts +++ b/mcp-server/src/PenpotMcpServer.ts @@ -8,7 +8,7 @@ import { ToolInterface } from "./Tool"; import { HelloWorldTool } from "./tools/HelloWorldTool"; import { PrintTextTool } from "./tools/PrintTextTool"; import { PluginTask } from "./PluginTask"; -import { PluginTaskResponse, PluginTaskResult } from '@penpot-mcp/common'; +import { PluginTaskResponse, PluginTaskResult } from "@penpot-mcp/common"; /** * Penpot MCP server implementation with HTTP and SSE Transport Support @@ -255,10 +255,10 @@ export class PenpotMcpServer { /** * Handles responses from the plugin for completed tasks. - * + * * Finds the pending task by ID and resolves or rejects its promise * based on the execution result. - * + * * @param response - The plugin task response containing ID and result */ private handlePluginTaskResponse(response: PluginTaskResponse): void { @@ -280,7 +280,7 @@ export class PenpotMcpServer { if (response.result.success) { task.resolveWithResult(response.result); } else { - const error = new Error(response.result.error || 'Task execution failed'); + const error = new Error(response.result.error || "Task execution failed"); task.rejectWithError(error); } @@ -289,16 +289,14 @@ export class PenpotMcpServer { /** * Executes a plugin task by sending it to connected clients. - * + * * Registers the task for result correlation and returns a promise * that resolves when the plugin responds with the execution result. - * + * * @param task - The plugin task to execute * @throws Error if no plugin instances are connected or available */ - public async executePluginTask( - task: PluginTask - ): Promise { + public async executePluginTask(task: PluginTask): Promise { // Check if there are connected clients if (this.connectedClients.size === 0) { throw new Error( @@ -319,7 +317,7 @@ export class PenpotMcpServer { sentCount++; } }); - + if (sentCount === 0) { // Clean up the pending task and timeout since we couldn't send it this.pendingTasks.delete(task.id); diff --git a/mcp-server/src/PluginBridge.ts b/mcp-server/src/PluginBridge.ts index 0582e9b..002ff08 100644 --- a/mcp-server/src/PluginBridge.ts +++ b/mcp-server/src/PluginBridge.ts @@ -8,7 +8,7 @@ import { ToolInterface } from "./Tool"; import { HelloWorldTool } from "./tools/HelloWorldTool"; import { PrintTextTool } from "./tools/PrintTextTool"; import { PluginTask } from "./PluginTask"; -import { PluginTaskResponse, PluginTaskResult } from '@penpot-mcp/common'; +import { PluginTaskResponse, PluginTaskResult } from "@penpot-mcp/common"; /** * Penpot MCP server implementation with HTTP and SSE Transport Support @@ -255,10 +255,10 @@ export class PenpotMcpServer { /** * Handles responses from the plugin for completed tasks. - * + * * Finds the pending task by ID and resolves or rejects its promise * based on the execution result. - * + * * @param response - The plugin task response containing ID and result */ private handlePluginTaskResponse(response: PluginTaskResponse): void { @@ -280,7 +280,7 @@ export class PenpotMcpServer { if (response.result.success) { task.resolveWithResult(response.result); } else { - const error = new Error(response.result.error || 'Task execution failed'); + const error = new Error(response.result.error || "Task execution failed"); task.rejectWithError(error); } @@ -289,16 +289,14 @@ export class PenpotMcpServer { /** * Executes a plugin task by sending it to connected clients. - * + * * Registers the task for result correlation and returns a promise * that resolves when the plugin responds with the execution result. - * + * * @param task - The plugin task to execute * @throws Error if no plugin instances are connected or available */ - public async executePluginTask( - task: PluginTask - ): Promise { + public async executePluginTask(task: PluginTask): Promise { // Check if there are connected clients if (this.connectedClients.size === 0) { throw new Error( @@ -319,7 +317,7 @@ export class PenpotMcpServer { sentCount++; } }); - + if (sentCount === 0) { // Clean up the pending task and timeout since we couldn't send it this.pendingTasks.delete(task.id); diff --git a/mcp-server/src/PluginTask.ts b/mcp-server/src/PluginTask.ts index daaa42d..be8f234 100644 --- a/mcp-server/src/PluginTask.ts +++ b/mcp-server/src/PluginTask.ts @@ -6,8 +6,8 @@ * * @template TParams - The strongly-typed parameters for this task */ -import { PluginTaskRequest, PluginTaskResult } from '@penpot-mcp/common'; -import { randomUUID } from 'crypto'; +import { PluginTaskRequest, PluginTaskResult } from "@penpot-mcp/common"; +import { randomUUID } from "crypto"; /** * Base class for plugin tasks that are sent over WebSocket. @@ -64,7 +64,7 @@ export abstract class PluginTask { if (!this.result) { - throw new Error('Result promise not initialized'); + throw new Error("Result promise not initialized"); } return this.result; } /** * Resolves the task with the given result. - * + * * This method should be called when a task response is received * from the plugin with matching ID. - * + * * @param result - The task execution result */ resolveWithResult(result: TResult): void { if (!this.resolveResult) { - throw new Error('Result promise not initialized'); + throw new Error("Result promise not initialized"); } this.resolveResult(result); } /** * Rejects the task with the given error. - * + * * This method should be called when task execution fails * or times out. - * + * * @param error - The error that occurred during task execution */ rejectWithError(error: Error): void { if (!this.rejectResult) { - throw new Error('Result promise not initialized'); + throw new Error("Result promise not initialized"); } this.rejectResult(error); } /** * Serializes the task to a request message for WebSocket transmission. - * + * * @returns The request message containing ID, task name, and parameters */ toRequest(): PluginTaskRequest { diff --git a/mcp-server/src/tasks/PrintTextPluginTask.ts b/mcp-server/src/tasks/PrintTextPluginTask.ts index 7048845..057a864 100644 --- a/mcp-server/src/tasks/PrintTextPluginTask.ts +++ b/mcp-server/src/tasks/PrintTextPluginTask.ts @@ -1,5 +1,5 @@ import { PluginTask } from "../PluginTask"; -import { PrintTextTaskParams, PluginTaskResult } from '@penpot-mcp/common'; +import { PrintTextTaskParams, PluginTaskResult } from "@penpot-mcp/common"; /** * Task for printing/creating text in Penpot. diff --git a/mcp-server/src/tools/PrintTextTool.ts b/mcp-server/src/tools/PrintTextTool.ts index ad34443..ebaa0cb 100644 --- a/mcp-server/src/tools/PrintTextTool.ts +++ b/mcp-server/src/tools/PrintTextTool.ts @@ -5,7 +5,7 @@ import { TextResponse } from "../ToolResponse"; import "reflect-metadata"; import { PenpotMcpServer } from "../PenpotMcpServer"; import { PrintTextPluginTask } from "../tasks/PrintTextPluginTask"; -import { PrintTextTaskParams } from '@penpot-mcp/common'; +import { PrintTextTaskParams } from "@penpot-mcp/common"; /** * Arguments class for the PrintText tool with validation decorators. @@ -46,22 +46,18 @@ export class PrintTextTool extends Tool { protected async executeCore(args: PrintTextArgs): Promise { const taskParams: PrintTextTaskParams = { text: args.text }; const task = new PrintTextPluginTask(taskParams); - + try { await this.mcpServer.executePluginTask(task); const result = await task.getResultPromise(); - + if (result.success) { - return new TextResponse( - `Successfully created text "${args.text}" in Penpot.` - ); + return new TextResponse(`Successfully created text "${args.text}" in Penpot.`); } else { - return new TextResponse( - `Failed to create text in Penpot: ${result.error || 'Unknown error'}` - ); + return new TextResponse(`Failed to create text in Penpot: ${result.error || "Unknown error"}`); } } catch (error) { - const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + const errorMessage = error instanceof Error ? error.message : "Unknown error"; return new TextResponse(`Failed to execute text creation task: ${errorMessage}`); } }