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));
      });
    }
Behavior2/5

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

Without annotations, the description must fully disclose behavioral traits. It only states 'apply a text style', implying mutation, but provides no details about safety (e.g., is it reversible?), required permissions, or what happens if the node is not a text type. This minimal disclosure leaves significant uncertainty for an agent.

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 concise sentence with no extraneous information. It communicates the core action efficiently, earning its place without waste.

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 string parameters and no output schema, the description is minimally complete. However, it could be improved by noting that the text style must exist or that the node must be a text node, which are missing contextual nuances.

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 input schema has 100% coverage with descriptions for both parameters ('The ID of the text node to modify' and 'The ID of the text style to apply'). The description does not add additional semantics beyond what the schema already provides, so a baseline score of 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 verb 'apply' and the resource 'text style', and specifies the target 'text node in Figma'. It distinguishes itself from sibling tools like 'set_text_content' (which modifies content) and 'set_font_name' (which modifies a specific property), providing a unique and unambiguous purpose.

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 is provided on when to use this tool versus alternatives. With many sibling tools that affect text properties (e.g., set_font_name, set_font_size, set_text_align), the description lacks explicit context for choosing this tool, leaving the agent to infer from the name 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/arinspunk/claude-talk-to-figma-mcp'

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