Skip to main content
Glama

drawing_fillRectangle

Fill a rectangle on a drawing canvas by specifying coordinates, dimensions, and color values to create colored shapes for visual content.

Instructions

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

Input Schema

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

Implementation Reference

  • Core implementation of the fillRectangle method in the Canvas class. This is the exact logic that fills the rectangle pixels with the given color after validation.
    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
            }
        }
    }
  • Exported wrapper function fillRectangle that validates the canvas instance and delegates to the Canvas class 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);
    }
  • MCP tool handler switch case for 'drawing_fillRectangle'. Validates canvas existence, calls drawingTool.fillRectangle, handles errors and returns result.
    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, defining parameters x, y, width, height, and color object.
    {
      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:21-77 (registration)
    The TOOLS constant array that registers the 'drawing_fillRectangle' tool along with others, used in ListToolsRequestHandler.
    const TOOLS = [
      {
        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"],
        },
      },
      {
        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"],
        },
      },
      {
        name: "drawing_getCanvasPng", // Changed name to reflect PNG output
        description: "Get the current drawing canvas as a PNG image (base64 encoded).", // Updated description
        inputSchema: {
          type: "object",
          properties: {}, // No input needed to get canvas data
          required: [],
        },
      },
      {
        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: [],
        },
      },
    ];
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('Fill a rectangle') which implies a mutation/write operation, but doesn't clarify if this overwrites existing content, requires specific permissions, has side effects, or provides any return value. For a mutation tool with zero annotation coverage, this leaves significant behavioral gaps unaddressed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that immediately conveys the core functionality. Every word contributes essential information with zero redundancy. It's appropriately sized for this straightforward drawing operation.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what happens after filling (e.g., returns success/failure, modifies canvas state), doesn't mention error conditions, and provides minimal behavioral context. Given the complexity of a canvas modification operation, more completeness is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description mentions 'color and coordinates' which aligns with parameters but adds no additional semantic context beyond what's in the schema (e.g., coordinate system origin, units, color format details). This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Fill a rectangle'), resource ('on the drawing canvas'), and key parameters ('with a specified color and coordinates'). It distinguishes from siblings like drawing_generateCanvas (creation) and drawing_getCanvasData/getCanvasPng (retrieval) by focusing on modification. However, it doesn't explicitly differentiate from potential future drawing tools that might also modify the canvas.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing canvas from drawing_generateCanvas), when not to use it (e.g., for non-rectangular shapes), or how it relates to sibling tools. The agent must infer usage from tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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