Skip to main content
Glama
paragdesai1

Cursor Talk to Figma MCP

by paragdesai1

set_text_content

Modify text content in Figma designs by updating existing text nodes with new text values through programmatic control.

Instructions

Set the text content of an existing text node in Figma

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodeIdYesThe ID of the text node to modify
textYesNew text content

Implementation Reference

  • Handler function for 'set_text_content' command. Validates input, retrieves text node, loads font, calls setCharacters helper to update text content, and returns updated node info.
    async function setTextContent(params) {
      const { nodeId, text } = params || {};
    
      if (!nodeId) {
        throw new Error("Missing nodeId parameter");
      }
    
      if (text === undefined) {
        throw new Error("Missing text parameter");
      }
    
      const node = await figma.getNodeByIdAsync(nodeId);
      if (!node) {
        throw new Error(`Node not found with ID: ${nodeId}`);
      }
    
      if (node.type !== "TEXT") {
        throw new Error(`Node is not a text node: ${nodeId}`);
      }
    
      try {
        await figma.loadFontAsync(node.fontName);
    
        await setCharacters(node, text);
    
        return {
          id: node.id,
          name: node.name,
          characters: node.characters,
          fontName: node.fontName,
        };
      } catch (error) {
        throw new Error(`Error setting text content: ${error.message}`);
      }
    }
  • MCP tool registration for 'set_text_content' including input schema (nodeId, text) and handler that forwards to Figma plugin via sendCommandToFigma.
    server.tool(
      "set_text_content",
      "Set the text content of an existing text node in Figma",
      {
        nodeId: z.string().describe("The ID of the text node to modify"),
        text: z.string().describe("New text content"),
      },
      async ({ nodeId, text }) => {
        try {
          const result = await sendCommandToFigma("set_text_content", {
            nodeId,
            text,
          });
          const typedResult = result as { name: string };
          return {
            content: [
              {
                type: "text",
                text: `Updated text content of node "${typedResult.name}" to "${text}"`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error setting text content: ${error instanceof Error ? error.message : String(error)
                  }`,
              },
            ],
          };
        }
      }
    );
  • Core helper function setCharacters used by setTextContent to handle font loading (with mixed font strategies) and setting node.characters safely.
    export const setCharacters = async (node, characters, options) => {
      const fallbackFont = options?.fallbackFont || {
        family: "Roboto",
        style: "Regular",
      };
      try {
        if (node.fontName === figma.mixed) {
          if (options?.smartStrategy === "prevail") {
            const fontHashTree = {};
            for (let i = 1; i < node.characters.length; i++) {
              const charFont = node.getRangeFontName(i - 1, i);
              const key = `${charFont.family}::${charFont.style}`;
              fontHashTree[key] = fontHashTree[key] ? fontHashTree[key] + 1 : 1;
            }
            const prevailedTreeItem = Object.entries(fontHashTree).sort(
              (a, b) => b[1] - a[1]
            )[0];
            const [family, style] = prevailedTreeItem[0].split("::");
            const prevailedFont = {
              family,
              style,
            };
            await figma.loadFontAsync(prevailedFont);
            node.fontName = prevailedFont;
          } else if (options?.smartStrategy === "strict") {
            return setCharactersWithStrictMatchFont(node, characters, fallbackFont);
          } else if (options?.smartStrategy === "experimental") {
            return setCharactersWithSmartMatchFont(node, characters, fallbackFont);
          } else {
            const firstCharFont = node.getRangeFontName(0, 1);
            await figma.loadFontAsync(firstCharFont);
            node.fontName = firstCharFont;
          }
        } else {
          await figma.loadFontAsync({
            family: node.fontName.family,
            style: node.fontName.style,
          });
        }
      } catch (err) {
        console.warn(
          `Failed to load "${node.fontName["family"]} ${node.fontName["style"]}" font and replaced with fallback "${fallbackFont.family} ${fallbackFont.style}"`,
          err
        );
        await figma.loadFontAsync(fallbackFont);
        node.fontName = fallbackFont;
      }
      try {
        node.characters = characters;
        return true;
      } catch (err) {
        console.warn(`Failed to set characters. Skipped.`, err);
        return false;
      }
    };
Behavior2/5

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

With no annotations provided, the description carries full burden but offers limited behavioral insight. It implies a mutation ('Set') but doesn't disclose permissions needed, side effects (e.g., if it overrides existing content irreversibly), rate limits, or response format. This is inadequate for a mutation tool without annotation support.

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 with zero wasted words. It's front-loaded with the core purpose and avoids unnecessary elaboration, making it easy for an agent to parse quickly.

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 incomplete. It lacks critical context like success/error behaviors, return values, or operational constraints (e.g., node existence requirements). This leaves significant gaps for an agent to invoke the tool effectively.

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 both parameters ('nodeId' and 'text'). The description adds no additional parameter semantics beyond what's in the schema, such as format constraints or examples. Baseline 3 is appropriate when schema handles all parameter documentation.

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 ('Set') and target resource ('text content of an existing text node in Figma'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'set_multiple_text_contents' or 'create_text', which would have earned a perfect score.

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 minimal guidance by specifying 'existing text node,' implying it's not for creating new nodes. However, it lacks explicit when-to-use rules, alternatives (e.g., vs. 'set_multiple_text_contents'), prerequisites, or error conditions, leaving the agent with incomplete context for optimal tool selection.

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/paragdesai1/parag-Figma-MCP'

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