drawing_generateCanvas
Create a new drawing canvas by specifying width and height in pixels for digital artwork or diagrams.
Instructions
Generate a new drawing canvas with specified width and height.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| width | Yes | Width of the canvas in pixels | |
| height | Yes | Height of the canvas in pixels |
Implementation Reference
- index.ts:87-105 (handler)MCP tool handler case that processes the drawing_generateCanvas tool call, invokes the generateCanvas helper, and returns success/error response.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, }; }
- drawingTool.ts:105-107 (helper)Core helper function that creates and returns a new Canvas instance with the specified dimensions.function generateCanvas(width: number, height: number): Canvas { return new Canvas(width, height); }
- index.ts:22-33 (registration)Tool registration object in the TOOLS array used for ListToolsRequest, includes name, description, and input schema.{ 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"], }, },
- drawingTool.ts:12-31 (helper)Canvas class definition with constructor that initializes pixel array to white background, used by generateCanvas.class Canvas { width: number; height: number; pixels: Pixel[][]; 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 }; } } }