Skip to main content
Glama
arinspunk

Claude Talk to Figma MCP

by arinspunk

set_text_style_id

Apply a text style to a text node in Figma by specifying the node ID and the desired text style ID, enabling precise typography control through AI commands.

Instructions

Apply a text style to a text node in Figma

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodeIdYesThe ID of the text node to modify
textStyleIdYesThe ID of the text style to apply

Implementation Reference

  • The tool handler for 'set_text_style_id'. Registers the tool on the MCP server with Zod schema validation for nodeId and textStyleId. The handler sends the command to Figma via WebSocket, and returns a formatted result message or an error.
    // Set Text Style ID Tool
    server.tool(
      "set_text_style_id",
      "Apply a text style to a text node in Figma",
      {
        nodeId: z.string().describe("The ID of the text node to modify"),
        textStyleId: z.string().describe("The ID of the text style to apply"),
      },
      async ({ nodeId, textStyleId }) => {
        try {
          const result = await sendCommandToFigma("set_text_style_id", {
            nodeId,
            textStyleId
          });
          const typedResult = result as { name: string, textStyleId: string, styleName: string };
          return {
            content: [
              {
                type: "text",
                text: `Applied text style "${typedResult.styleName}" to node "${typedResult.name}"`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error setting text style: ${error instanceof Error ? error.message : String(error)}`
              }
            ]
          };
        }
      }
    );
  • Input schema for the 'set_text_style_id' tool, defining required string parameters: nodeId (the text node) and textStyleId (the style to apply).
    {
      nodeId: z.string().describe("The ID of the text node to modify"),
      textStyleId: z.string().describe("The ID of the text style to apply"),
    },
  • Tool registration via server.tool('set_text_style_id', ...) inside the registerTextTools function, which is called from the central registerTools function in tools/index.ts.
    // Set Text Style ID Tool
    server.tool(
      "set_text_style_id",
      "Apply a text style to a text node in Figma",
      {
        nodeId: z.string().describe("The ID of the text node to modify"),
        textStyleId: z.string().describe("The ID of the text style to apply"),
      },
      async ({ nodeId, textStyleId }) => {
        try {
          const result = await sendCommandToFigma("set_text_style_id", {
            nodeId,
            textStyleId
          });
          const typedResult = result as { name: string, textStyleId: string, styleName: string };
          return {
            content: [
              {
                type: "text",
                text: `Applied text style "${typedResult.styleName}" to node "${typedResult.name}"`
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error setting text style: ${error instanceof Error ? error.message : String(error)}`
              }
            ]
          };
        }
      }
    );
  • Type definition: 'set_text_style_id' is included in the FigmaCommand union type, which validates allowed command strings sent via WebSocket.
    | "set_text_style_id"
  • The sendCommandToFigma helper function used by the handler to send the 'set_text_style_id' command over WebSocket to the Figma plugin.
    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));
      });
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.8.2

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are provided, so the description must fully disclose behavior. It only states the action without explaining side effects, reversibility, or failure conditions (e.g., what happens if the node is not a text node or the style ID is invalid).

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

Conciseness3/5

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

The description is very short (one sentence) and gets to the point, but it lacks structure and is arguably too brief, missing opportunities to add value.

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

Completeness3/5

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

For a simple mutation tool with two parameters, the description covers the basic purpose. However, with no output schema, the agent is left uninformed about return values or success/failure indicators. It is minimally complete but not rich.

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 coverage is 100%, with each parameter described in the schema (nodeId and textStyleId). The description adds no additional meaning or context beyond the schema, so baseline 3 is appropriate.

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?

Clearly states the action ('Apply a text style') and the target resource ('text node in Figma'). The verb and resource are specific. However, it does not explicitly distinguish from sibling tools like apply_design_system, which might also apply styles, but the name set_text_style_id makes the intent clear.

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?

No guidance on when to use this tool versus alternatives (e.g., set_font_name, apply_design_system). No prerequisites or context about required node type or style existence are mentioned.

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

Deploy Server

Other Tools