Skip to main content
Glama
arinspunk

Claude Talk to Figma MCP

by arinspunk

set_multiple_text_contents

Simultaneously update text content for multiple nodes inside a parent Figma node by specifying each text node's ID and replacement text.

Instructions

Set multiple text contents parallelly in a node

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodeIdYesThe ID of the node containing the text nodes to replace
textYesArray of text node IDs and their replacement texts

Implementation Reference

  • MCP tool handler for 'set_multiple_text_contents'. Registers the tool via server.tool() with Zod schema validation (nodeId as string, text as coerced JSON array of {nodeId, text} objects). The handler sends the 'set_multiple_text_contents' command to Figma via WebSocket (sendCommandToFigma), then formats progress and detailed results for the response.
    // Set Multiple Text Contents Tool
    server.tool(
      "set_multiple_text_contents",
      "Set multiple text contents parallelly in a node",
      {
        nodeId: z
          .string()
          .describe("The ID of the node containing the text nodes to replace"),
        text: coerceJson(z
          .array(
            z.object({
              nodeId: z.string().describe("The ID of the text node"),
              text: z.string().describe("The replacement text"),
            })
          ))
          .describe("Array of text node IDs and their replacement texts"),
      },
      async ({ nodeId, text }, extra) => {
        try {
          if (!text || text.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: "No text provided",
                },
              ],
            };
          }
    
          // Initial response to indicate we're starting the process
          const initialStatus = {
            type: "text" as const,
            text: `Starting text replacement for ${text.length} nodes. This will be processed in batches of 5...`,
          };
    
          // Track overall progress
          let totalProcessed = 0;
          const totalToProcess = text.length;
    
          // Use the plugin's set_multiple_text_contents function with chunking
          const result = await sendCommandToFigma("set_multiple_text_contents", {
            nodeId,
            text,
          });
    
          // Cast the result to a specific type to work with it safely
          interface TextReplaceResult {
            success: boolean;
            nodeId: string;
            replacementsApplied?: number;
            replacementsFailed?: number;
            totalReplacements?: number;
            completedInChunks?: number;
            results?: Array<{
              success: boolean;
              nodeId: string;
              error?: string;
              originalText?: string;
              translatedText?: string;
            }>;
          }
    
          const typedResult = result as TextReplaceResult;
    
          // Format the results for display
          const success = typedResult.replacementsApplied && typedResult.replacementsApplied > 0;
          const progressText = `
          Text replacement completed:
          - ${typedResult.replacementsApplied || 0} of ${totalToProcess} successfully updated
          - ${typedResult.replacementsFailed || 0} failed
          - Processed in ${typedResult.completedInChunks || 1} batches
          `;
    
          // Detailed results
          const detailedResults = typedResult.results || [];
          const failedResults = detailedResults.filter(item => !item.success);
    
          // Create the detailed part of the response
          let detailedResponse = "";
          if (failedResults.length > 0) {
            detailedResponse = `\n\nNodes that failed:\n${failedResults.map(item =>
              `- ${item.nodeId}: ${item.error || "Unknown error"}`
            ).join('\n')}`;
          }
    
          return {
            content: [
              initialStatus,
              {
                type: "text" as const,
                text: progressText + detailedResponse,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error setting multiple text contents: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • Input schema for 'set_multiple_text_contents' using Zod. Requires a nodeId (string) and text (coerced JSON array of objects with nodeId and text fields). The 'coerceJson' wrapper allows JSON string input to be auto-parsed.
    server.tool(
      "set_multiple_text_contents",
      "Set multiple text contents parallelly in a node",
      {
        nodeId: z
          .string()
          .describe("The ID of the node containing the text nodes to replace"),
        text: coerceJson(z
          .array(
            z.object({
              nodeId: z.string().describe("The ID of the text node"),
              text: z.string().describe("The replacement text"),
            })
          ))
          .describe("Array of text node IDs and their replacement texts"),
      },
  • Registration of the 'set_multiple_text_contents' tool via server.tool(). The tool is registered inside the registerTextTools() function exported from text-tools.ts, which is called from src/talk_to_figma_mcp/tools/index.ts line 22.
    // Set Multiple Text Contents Tool
    server.tool(
  • The 'coerceJson' helper function used in the schema. It wraps a Zod schema with z.preprocess to auto-parse JSON strings, enabling MCP to pass the 'text' parameter as either a JSON string or already-parsed array.
    export const coerceJson = <T extends z.ZodTypeAny>(schema: T) =>
      z.preprocess((val) => {
        if (typeof val === "string") {
          try { return JSON.parse(val); } catch { return val; }
        }
        return val;
      }, schema);
  • Type definition for the FigmaCommand union type, including 'set_multiple_text_contents' as a valid command string, ensuring type safety when sending commands via WebSocket.
    | "set_multiple_text_contents"

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv0.8.2
    • addedInput schema / additionalProperties
      Added value: +false
    • addedInput schema / properties / text / items / additionalProperties
      Added value: +false
  2. Changed4 schema fields changedv1.0.0
    • removedInput schema / additionalProperties
      Removed value: -false
    • addedInput schema / properties / nodeId
      Added value: +{
      +  "description": "The ID of the node containing the text nodes to replace",
      +  "type": "string"
      +}
    • addedInput schema / properties / text
      Added value: +{
      +  "description": "Array of text node IDs and their replacement texts",
      +  "items": {
      +    "properties": {
      +      "nodeId": {
      +        "description": "The ID of the text node",
      +        "type": "string"
      +      },
      +      "text": {
      +        "description": "The replacement text",
      +        "type": "string"
      +      }
      +    },
      +    "required": [
      +      "nodeId",
      +      "text"
      +    ],
      +    "type": "object"
      +  },
      +  "type": "array"
      +}
    • addedInput schema / required
      Added value: +[
      +  "nodeId",
      +  "text"
      +]
  3. First observed

TDQS

B3.1/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only reveals that the operation sets multiple text contents 'parallelly', but does not state whether existing text is replaced, whether the node must contain text nodes, or whether the operation is atomic.

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 a single sentence with no filler and the action verb is front-loaded. However, 'parallelly' is an awkward modifier and 'text contents' is imprecise, so it is concise but not maximally polished.

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 thin. It omits how this tool relates to set_text_content, what 'parallelly' means in terms of execution, and any side effects or prerequisites, though the schema covers the parameter mechanics.

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 baseline is 3. The description adds little beyond the schema: 'parallelly' and 'in a node' hint at the relationship between the parent node and the array, but the schema already documents both parameters and their roles.

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 uses a specific verb ('Set') and resource ('multiple text contents') and scopes the operation to 'a node'. The word 'multiple' differentiates it from the sibling set_text_content, though 'parallelly' is vague and 'text contents' is slightly ambiguous.

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

Usage Guidelines3/5

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

No explicit when-to-use guidance or alternatives are stated. The term 'multiple' implies this is the batch counterpart to set_text_content, but the description never clarifies when to choose this over the singular tool or what types of nodes are valid.

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