Skip to main content
Glama

drawing_fillRectangle

Fill a rectangle on a drawing canvas with a specified color by defining top-left coordinates, width, height, and RGB values using the mcp-painter tool.

Instructions

Fill a rectangle on the drawing canvas with a specified color and coordinates.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
colorYesColor to fill the rectangle with (RGB)
heightYesHeight of the rectangle
widthYesWidth of the rectangle
xYesX coordinate of the top-left corner of the rectangle
yYesY coordinate of the top-left corner of the rectangle

Implementation Reference

  • MCP tool handler for 'drawing_fillRectangle' that checks for canvas, calls drawingTool.fillRectangle, and returns success/error response.
    case "drawing_fillRectangle": if (!currentCanvas) { return { content: [{ type: "text", text: "Error: No canvas generated. Please use 'drawing_generateCanvas' first.", }], isError: true, }; } try { drawingTool.fillRectangle( currentCanvas, args.x, args.y, args.width, args.height, args.color ); return { content: [{ type: "text", text: `Filled rectangle at (${args.x}, ${args.y}) with dimensions ${args.width}x${args.height} and color RGB(${args.color.r},${args.color.g},${args.color.b})`, }], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Failed to fill rectangle: ${(error as Error).message}`, }], isError: true, }; }
  • Input schema and metadata for the 'drawing_fillRectangle' tool, part of the TOOLS array used for registration.
    { name: "drawing_fillRectangle", description: "Fill a rectangle on the drawing canvas with a specified color and coordinates.", inputSchema: { type: "object", properties: { x: { type: "number", description: "X coordinate of the top-left corner of the rectangle" }, y: { type: "number", description: "Y coordinate of the top-left corner of the rectangle" }, width: { type: "number", description: "Width of the rectangle" }, height: { type: "number", description: "Height of the rectangle" }, color: { type: "object", description: "Color to fill the rectangle with (RGB)", properties: { r: { type: "number", description: "Red component (0-255)" }, g: { type: "number", description: "Green component (0-255)" }, b: { type: "number", description: "Blue component (0-255)" }, a: { type: "number", description: "Alpha component (0-255, optional, default 255)" }, }, required: ["r", "g", "b"], }, }, required: ["x", "y", "width", "height", "color"], }, },
  • index.ts:286-288 (registration)
    Registers the list of tools including 'drawing_fillRectangle' via ListToolsRequestSchema handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS, }));
  • Wrapper helper function 'fillRectangle' exported from drawingTool.ts, validates canvas and delegates to Canvas instance method.
    function fillRectangle(canvas: Canvas, x: number, y: number, width: number, height: number, color: Color): void { if (!(canvas instanceof Canvas)) { throw new Error("Invalid canvas object provided."); } canvas.fillRectangle(x, y, width, height, color); }
  • Core implementation in Canvas class 'fillRectangle' method that performs bounds checking and fills the pixel array with the specified color.
    fillRectangle(x: number, y: number, width: number, height: number, color: Color): void { if (!this.isValidCoordinate(x, y) || !this.isValidCoordinate(x + width - 1, y + height - 1)) { throw new Error("Rectangle coordinates are out of canvas bounds."); } if (typeof width !== 'number' || width <= 0 || typeof height !== 'number' || height <= 0) { throw new Error("Rectangle dimensions must be positive numbers."); } if (!this.isValidColor(color)) { throw new Error("Invalid color format. Color should be an object with {r, g, b, a} values (0-255 for r, g, b and 0-255 for a)."); } for (let rectY = y; rectY < y + height; rectY++) { for (let rectX = x; rectX < x + width; rectX++) { this.pixels[rectY][rectX] = { ...color }; // Spread to avoid modifying the original color object } } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/flrngel/mcp-painter'

If you have feedback or need assistance with the MCP directory API, please join our Discord server