mirror of
https://github.com/penpot/penpot-mcp.git
synced 2026-04-25 11:18:37 +00:00
Apply formatter
This commit is contained in:
parent
139f77edb2
commit
48955b67a9
@ -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<TResult extends PluginTaskResult>(
|
||||
task: PluginTask<any, TResult>
|
||||
): Promise<void> {
|
||||
public async executePluginTask<TResult extends PluginTaskResult>(task: PluginTask<any, TResult>): Promise<void> {
|
||||
// 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);
|
||||
|
||||
@ -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<TResult extends PluginTaskResult>(
|
||||
task: PluginTask<any, TResult>
|
||||
): Promise<void> {
|
||||
public async executePluginTask<TResult extends PluginTaskResult>(task: PluginTask<any, TResult>): Promise<void> {
|
||||
// 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);
|
||||
|
||||
@ -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<TParams = any, TResult extends PluginTaskResult
|
||||
|
||||
/**
|
||||
* Sets up the result promise and its resolvers.
|
||||
*
|
||||
*
|
||||
* Creates a promise that can be resolved externally when
|
||||
* the task result is received from the plugin.
|
||||
*/
|
||||
@ -77,49 +77,49 @@ export abstract class PluginTask<TParams = any, TResult extends PluginTaskResult
|
||||
|
||||
/**
|
||||
* Gets the result promise for this task.
|
||||
*
|
||||
*
|
||||
* @returns Promise that resolves when the task execution completes
|
||||
*/
|
||||
getResultPromise(): Promise<TResult> {
|
||||
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 {
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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<PrintTextArgs> {
|
||||
protected async executeCore(args: PrintTextArgs): Promise<ToolResponse> {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user