set_multiple_text_contents
Replace multiple text elements simultaneously within a Figma node to update content efficiently and maintain design consistency.
Instructions
Set multiple text contents parallelly in a node
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the node containing the text nodes to replace | |
| text | Yes | Array of text node IDs and their replacement texts |
Implementation Reference
- Handler function that executes the tool logic: validates input, sends 'set_multiple_text_contents' command to Figma, processes results with detailed success/failure reporting and returns markdown content.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)}`, }, ], }; } }
- Zod input schema defining parameters: nodeId (string) and text (array of {nodeId: string, text: string}).{ nodeId: z .string() .describe("The ID of the node containing the text nodes to replace"), text: 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"), },
- src/talk_to_figma_mcp/tools/text-tools.ts:48-153 (registration)MCP server.tool registration call that registers the 'set_multiple_text_contents' tool with description, input schema, and handler function.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: 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)}`, }, ], }; } } );
- src/talk_to_figma_mcp/tools/index.ts:16-16 (registration)Call to registerTextTools within the top-level registerTools function, which registers all text tools including set_multiple_text_contents.registerTextTools(server);
- Type definition including 'set_multiple_text_contents' in FigmaCommand union type for TypeScript support.| "set_multiple_text_contents"