drawing_generateCanvas
Create a customizable drawing canvas by specifying width and height in pixels for use in AI-assisted painting projects.
Instructions
Generate a new drawing canvas with specified width and height.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| height | Yes | Height of the canvas in pixels | |
| width | Yes | Width of the canvas in pixels |
Implementation Reference
- index.ts:87-105 (handler)MCP tool handler for 'drawing_generateCanvas' that calls the generateCanvas helper and manages canvas state.case "drawing_generateCanvas": try { currentCanvas = drawingTool.generateCanvas(args.width, args.height); return { content: [{ type: "text", text: `Canvas generated with width: ${args.width}, height: ${args.height}`, }], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Failed to generate canvas: ${(error as Error).message}`, }], isError: true, }; }
- index.ts:22-33 (schema)Input schema for the drawing_generateCanvas tool defining required width and height parameters.{ name: "drawing_generateCanvas", description: "Generate a new drawing canvas with specified width and height.", inputSchema: { type: "object", properties: { width: { type: "number", description: "Width of the canvas in pixels" }, height: { type: "number", description: "Height of the canvas in pixels" }, }, required: ["width", "height"], }, },
- index.ts:290-292 (registration)Registration of the CallToolRequestSchema dispatcher that routes to the tool handler.server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}) );
- drawingTool.ts:105-107 (helper)Helper function implementing canvas generation by instantiating Canvas class.function generateCanvas(width: number, height: number): Canvas { return new Canvas(width, height); }
- drawingTool.ts:17-30 (helper)Canvas class constructor that initializes pixel array with white background.constructor(width: number, height: number) { if (typeof width !== 'number' || width <= 0 || typeof height !== 'number' || height <= 0) { throw new Error("Canvas dimensions must be positive numbers."); } this.width = width; this.height = height; this.pixels = []; for (let y = 0; y < height; y++) { this.pixels[y] = []; for (let x = 0; x < width; x++) { // Default to white background this.pixels[y][x] = { r: 255, g: 255, b: 255, a: 255 }; } }