Skip to main content
Glama
arinspunk

Claude Talk to Figma MCP

by arinspunk

create_rectangle

Insert a rectangle shape into a Figma file by specifying its x/y position, width, height, and optional visual properties like fill and stroke. Design UI elements with precise control.

Instructions

Create a new rectangle in Figma

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xYesX position (local coordinates, relative to parent)
yYesY position (local coordinates, relative to parent)
widthYesWidth of the rectangle
heightYesHeight of the rectangle
nameNoOptional name for the rectangle
parentIdNoParent node ID. REQUIRED — server enforces this. Use page node ID for top-level elements. Get page IDs via get_pages tool.
fillColorNoFill color in RGBA format
strokeColorNoStroke color in RGBA format
strokeWeightNoStroke weight

Implementation Reference

  • Handler function for the create_rectangle tool. Sends the command to Figma via WebSocket with position, dimensions, optional name, parentId, fill/stroke colors, and stroke weight.
      async ({ x, y, width, height, name, parentId, fillColor, strokeColor, strokeWeight }) => {
        try {
          const result = await sendCommandToFigma("create_rectangle", {
            x,
            y,
            width,
            height,
            name: name || "Rectangle",
            parentId,
            fillColor,
            strokeColor,
            strokeWeight,
          });
          return {
            content: [
              {
                type: "text",
                text: `Created rectangle "${JSON.stringify(result)}"`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error creating rectangle: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • Input schema for the create_rectangle tool using Zod validation. Defines x, y, width, height (required), plus optional name, parentId, fillColor (RGBA), strokeColor (RGBA), and strokeWeight.
    {
      x: z.coerce.number().describe("X position (local coordinates, relative to parent)"),
      y: z.coerce.number().describe("Y position (local coordinates, relative to parent)"),
      width: z.coerce.number().describe("Width of the rectangle"),
      height: z.coerce.number().describe("Height of the rectangle"),
      name: z.string().optional().describe("Optional name for the rectangle"),
      parentId: z
        .string()
        .optional()
        .describe("Parent node ID. REQUIRED — server enforces this. Use page node ID for top-level elements. Get page IDs via get_pages tool."),
      fillColor: coerceJson(z.object({
          r: z.coerce.number().min(0).max(1).describe("Red component (0-1)"),
          g: z.coerce.number().min(0).max(1).describe("Green component (0-1)"),
          b: z.coerce.number().min(0).max(1).describe("Blue component (0-1)"),
          a: z.coerce.number().min(0).max(1).optional().describe("Alpha component (0-1)"),
        }))
        .optional()
        .describe("Fill color in RGBA format"),
      strokeColor: coerceJson(z.object({
          r: z.coerce.number().min(0).max(1).describe("Red component (0-1)"),
          g: z.coerce.number().min(0).max(1).describe("Green component (0-1)"),
          b: z.coerce.number().min(0).max(1).describe("Blue component (0-1)"),
          a: z.coerce.number().min(0).max(1).optional().describe("Alpha component (0-1)"),
        }))
        .optional()
        .describe("Stroke color in RGBA format"),
      strokeWeight: z.coerce.number().positive().optional().describe("Stroke weight"),
    },
  • Registration of the 'create_rectangle' tool via server.tool() in the registerCreationTools function.
    server.tool(
      "create_rectangle",
      "Create a new rectangle in Figma",
      {
        x: z.coerce.number().describe("X position (local coordinates, relative to parent)"),
        y: z.coerce.number().describe("Y position (local coordinates, relative to parent)"),
        width: z.coerce.number().describe("Width of the rectangle"),
        height: z.coerce.number().describe("Height of the rectangle"),
        name: z.string().optional().describe("Optional name for the rectangle"),
        parentId: z
          .string()
          .optional()
          .describe("Parent node ID. REQUIRED — server enforces this. Use page node ID for top-level elements. Get page IDs via get_pages tool."),
        fillColor: coerceJson(z.object({
            r: z.coerce.number().min(0).max(1).describe("Red component (0-1)"),
            g: z.coerce.number().min(0).max(1).describe("Green component (0-1)"),
            b: z.coerce.number().min(0).max(1).describe("Blue component (0-1)"),
            a: z.coerce.number().min(0).max(1).optional().describe("Alpha component (0-1)"),
          }))
          .optional()
          .describe("Fill color in RGBA format"),
        strokeColor: coerceJson(z.object({
            r: z.coerce.number().min(0).max(1).describe("Red component (0-1)"),
            g: z.coerce.number().min(0).max(1).describe("Green component (0-1)"),
            b: z.coerce.number().min(0).max(1).describe("Blue component (0-1)"),
            a: z.coerce.number().min(0).max(1).optional().describe("Alpha component (0-1)"),
          }))
          .optional()
          .describe("Stroke color in RGBA format"),
        strokeWeight: z.coerce.number().positive().optional().describe("Stroke weight"),
      },
      async ({ x, y, width, height, name, parentId, fillColor, strokeColor, strokeWeight }) => {
        try {
          const result = await sendCommandToFigma("create_rectangle", {
            x,
            y,
            width,
            height,
            name: name || "Rectangle",
            parentId,
            fillColor,
            strokeColor,
            strokeWeight,
          });
          return {
            content: [
              {
                type: "text",
                text: `Created rectangle "${JSON.stringify(result)}"`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error creating rectangle: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • The sendCommandToFigma function that sends the 'create_rectangle' command over WebSocket to the Figma plugin and returns a promise resolving with the response.
    export function sendCommandToFigma(
      command: FigmaCommand,
      params: unknown = {},
      timeoutMs: number = 300000
    ): Promise<unknown> {
      return new Promise((resolve, reject) => {
        // If not connected, try to connect first
        if (!ws || ws.readyState !== WebSocket.OPEN) {
          connectToFigma();
          reject(new Error("Not connected to Figma. Attempting to connect..."));
          return;
        }
    
        // Check if we need a channel for this command
        const requiresChannel = command !== "join";
        if (requiresChannel && !currentChannel) {
          reject(new Error("Must join a channel before sending commands"));
          return;
        }
    
        const id = uuidv4();
        const request = {
          id,
          type: command === "join" ? "join" : "message",
          ...(command === "join"
            ? { channel: (params as any).channel, sessionId: SESSION_ID }
            : { channel: currentChannel }),
          message: {
            id,
            command,
            params: {
              ...(params as any),
              commandId: id, // Include the command ID in params
            },
          },
        };
    
        // Set timeout for request
        const timeout = setTimeout(() => {
          if (pendingRequests.has(id)) {
            pendingRequests.delete(id);
            logger.error(`Request ${id} to Figma timed out after ${timeoutMs / 1000} seconds`);
            reject(new Error('Request to Figma timed out'));
          }
        }, timeoutMs);
    
        // Store the promise callbacks to resolve/reject later
        pendingRequests.set(id, {
          resolve,
          reject,
          timeout,
          lastActivity: Date.now()
        });
    
        // Send the request
        logger.info(`Sending command to Figma: ${command}`);
        logger.debug(`Request details: ${JSON.stringify(request)}`);
        ws.send(JSON.stringify(request));
      });
    }
Behavior2/5

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

No annotations are provided, and the description only says 'Create a new rectangle'. It does not disclose behavioral traits such as side effects (e.g., selection changes, file modification), required permissions, or error conditions.

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

Conciseness4/5

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

The description is one sentence, concise and front-loaded. However, it could include more contextual hints without becoming verbose, so a 4 is suitable.

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?

Given the tool has 9 parameters and nested objects, the description is minimal. It lacks context about the working file, selection, or output. No mention of return values or required state.

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?

The schema description coverage is 100%, so the schema already documents all parameters. The description adds no extra meaning beyond the schema. Baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states the action 'Create', the resource 'rectangle', and the platform 'Figma'. It is specific and distinguishes this tool from siblings like create_ellipse or create_frame.

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 (e.g., create_shape_with_text, clone_node). It does not mention prerequisites or when not to use it.

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/arinspunk/claude-talk-to-figma-mcp'

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