drawing_getCanvasData
Extract current canvas pixel data as JSON to analyze or process drawing content programmatically.
Instructions
Get the current pixel data of the drawing canvas as JSON.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.ts:178-206 (handler)The tool handler case in handleToolCall function: checks for existing canvas, calls drawingTool.getCanvasData, stringifies and returns as text content.
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 (schema)Tool schema definition in TOOLS array: 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: [], }, }, - drawingTool.ts:123-128 (helper)Exported getCanvasData function: validates Canvas instance and delegates to its getCanvasData 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)Canvas class getCanvasData method: returns the internal 2D pixels array.
getCanvasData(): Pixel[][] { // Renamed from getCanvas to getCanvasData for clarity return this.pixels; }