drawing_getCanvasData
Retrieve the pixel data of the drawing canvas as JSON for analysis or further processing using the mcp-painter server.
Instructions
Get the current pixel data of the drawing canvas as JSON.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.ts:178-206 (handler)Executes the drawing_getCanvasData tool: checks for existing canvas, calls drawingTool.getCanvasData to retrieve pixel data, returns it as formatted JSON text or error.case "drawing_getCanvasData": if (!currentCanvas) { return { content: [{ type: "text", text: "Error: No canvas generated. Please use 'drawing_generateCanvas' first.", }], isError: true, }; } try { const canvasData = drawingTool.getCanvasData(currentCanvas); // Use getCanvasData // Return canvas data as JSON text content return { content: [{ type: "text", text: JSON.stringify(canvasData, null, 2), // Stringify for readable JSON }], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Failed to get canvas data: ${(error as Error).message}`, }], isError: true, }; }
- index.ts:68-76 (registration)Registers the drawing_getCanvasData tool in the TOOLS array with name, description, and empty input schema.{ name: "drawing_getCanvasData", description: "Get the current pixel data of the drawing canvas as JSON.", inputSchema: { type: "object", properties: {}, // No input needed to get canvas data required: [], }, },
- index.ts:71-75 (schema)Input schema definition for the tool: empty object with no required properties.inputSchema: { type: "object", properties: {}, // No input needed to get canvas data required: [], },
- drawingTool.ts:123-128 (helper)Helper function that validates the Canvas instance and returns its pixel data by delegating to the class method.function getCanvasData(canvas: Canvas): Pixel[][] { // Exporting getCanvasData instead of getCanvas if (!(canvas instanceof Canvas)) { throw new Error("Invalid canvas object provided."); } return canvas.getCanvasData(); }
- drawingTool.ts:51-53 (helper)Core Canvas class method that directly returns the 2D pixels array, implementing the pixel data retrieval logic.getCanvasData(): Pixel[][] { // Renamed from getCanvas to getCanvasData for clarity return this.pixels; }