diff --git a/mcp-server/README.md b/mcp-server/README.md index edc048f..9c396b5 100644 --- a/mcp-server/README.md +++ b/mcp-server/README.md @@ -111,19 +111,7 @@ For MCP clients that support HTTP transport directly, use: - Streamable HTTP for modern clients: `http://localhost:4401/mcp` - SSE for legacy clients: `http://localhost:4401/sse` -## Plugin Communication - -The server also runs a WebSocket server on port 8080 for communication with Penpot plugins: - -- **WebSocket endpoint**: `ws://localhost:8080` -- **Protocol**: Request/response with unique ID correlation -- **Timeout**: 30 seconds for task completion -- **Shared Types**: Uses `@penpot-mcp/common` package for type safety - -### WebSocket Protocol Features - -- **Request Correlation**: Each task has a unique UUID for matching responses -- **Structured Results**: Tasks return `{success: boolean, error?: string, data?: any}` -- **Timeout Handling**: Prevents hanging tasks with automatic cleanup -- **Type Safety**: Shared TypeScript definitions across server and plugin +## Penpot Plugin API REPL +The MCP server includes a REPL interface for testing Penpot Plugin API calls. +To use it, connect to the URL reported at startup. \ No newline at end of file diff --git a/mcp-server/src/PenpotMcpServer.ts b/mcp-server/src/PenpotMcpServer.ts index 84af960..1d6cdb9 100644 --- a/mcp-server/src/PenpotMcpServer.ts +++ b/mcp-server/src/PenpotMcpServer.ts @@ -20,7 +20,6 @@ export class PenpotMcpServer { private readonly tools: Map>; public readonly configLoader: ConfigurationLoader; private app: any; - private readonly port: number; public readonly pluginBridge: PluginBridge; private readonly replServer: ReplServer; @@ -29,9 +28,12 @@ export class PenpotMcpServer { sse: {} as Record, }; - constructor(port: number = 4401, webSocketPort: number = 8080) { + constructor( + public port: number = 4401, + public webSocketPort: number = 8080, + replPort: number = 4403 + ) { this.configLoader = new ConfigurationLoader(); - this.port = port; const instructions = this.configLoader.getInitialInstructions(); this.server = new McpServer( @@ -46,7 +48,7 @@ export class PenpotMcpServer { this.tools = new Map>(); this.pluginBridge = new PluginBridge(webSocketPort); - this.replServer = new ReplServer(this.pluginBridge); + this.replServer = new ReplServer(this.pluginBridge, replPort); this.registerTools(); } @@ -148,7 +150,7 @@ export class PenpotMcpServer { this.logger.info(`Penpot MCP Server started on port ${this.port}`); this.logger.info(`Modern Streamable HTTP endpoint: http://localhost:${this.port}/mcp`); this.logger.info(`Legacy SSE endpoint: http://localhost:${this.port}/sse`); - this.logger.info("WebSocket server is on ws://localhost:8080"); + this.logger.info(`WebSocket server is on ws://localhost:${this.webSocketPort}`); // start the REPL server await this.replServer.start(); diff --git a/mcp-server/src/ReplServer.ts b/mcp-server/src/ReplServer.ts index 892364c..90bcba4 100644 --- a/mcp-server/src/ReplServer.ts +++ b/mcp-server/src/ReplServer.ts @@ -8,9 +8,10 @@ import { createLogger } from "./logger"; /** * Web-based REPL server for executing code through the PluginBridge. * - * Provides a simple HTML interface on port 4403 that allows users to input + * Provides a REPL-style HTML interface that allows users to input * JavaScript code and execute it via ExecuteCodePluginTask instances. - * The interface displays the result member of ExecuteCodeTaskResultData. + * The interface maintains command history, displays logs in <pre> tags, + * and shows results in visually separated blocks. */ export class ReplServer { private readonly logger = createLogger("ReplServer"); @@ -43,7 +44,7 @@ export class ReplServer { this.app.get("/", (req, res) => { const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); - const htmlPath = path.join(__dirname, 'static', 'repl.html'); + const htmlPath = path.join(__dirname, "static", "repl.html"); res.sendFile(htmlPath); }); @@ -78,8 +79,6 @@ export class ReplServer { }); } - - /** * Starts the REPL web server. * diff --git a/mcp-server/src/static/repl.html b/mcp-server/src/static/repl.html index 46d8401..739f066 100644 --- a/mcp-server/src/static/repl.html +++ b/mcp-server/src/static/repl.html @@ -1,217 +1,354 @@ - + - - - - Penpot MCP REPL - - - - -

Penpot MCP REPL

- -
- - -
- -
- - Shortcut: Ctrl+Enter -
- -
- -
Click "Execute Code" to run your JavaScript...
-
+ + + + `; - - + +