set_text_decoration
Modify text decoration in Figma by setting underline, strikethrough, or none on a text node. Specify the node ID and choose the decoration type.
Instructions
Set the text decoration of a text node in Figma
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the text node to modify | |
| textDecoration | Yes | Text decoration type |
Implementation Reference
- The set_text_decoration tool handler. It registers an MCP tool via server.tool() that accepts nodeId (string) and textDecoration (enum: NONE, UNDERLINE, STRIKETHROUGH), then sends the command to Figma via WebSocket.
// Set Text Decoration Tool server.tool( "set_text_decoration", "Set the text decoration of a text node in Figma", { nodeId: z.string().describe("The ID of the text node to modify"), textDecoration: z.enum(["NONE", "UNDERLINE", "STRIKETHROUGH"]).describe("Text decoration type"), }, async ({ nodeId, textDecoration }) => { try { const result = await sendCommandToFigma("set_text_decoration", { nodeId, textDecoration }); const typedResult = result as { name: string, textDecoration: string }; return { content: [ { type: "text", text: `Updated text decoration of node "${typedResult.name}" to ${typedResult.textDecoration}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error setting text decoration: ${error instanceof Error ? error.message : String(error)}` } ] }; } } - The 'set_text_decoration' string literal is included in the FigmaCommand union type, defining it as a valid command type that can be passed to sendCommandToFigma.
| "set_text_decoration" - src/talk_to_figma_mcp/tools/text-tools.ts:414-448 (registration)The tool is registered via server.tool() within the registerTextTools function. This is both the handler and the registration point, as MCP tools are registered at the same time they are defined.
// Set Text Decoration Tool server.tool( "set_text_decoration", "Set the text decoration of a text node in Figma", { nodeId: z.string().describe("The ID of the text node to modify"), textDecoration: z.enum(["NONE", "UNDERLINE", "STRIKETHROUGH"]).describe("Text decoration type"), }, async ({ nodeId, textDecoration }) => { try { const result = await sendCommandToFigma("set_text_decoration", { nodeId, textDecoration }); const typedResult = result as { name: string, textDecoration: string }; return { content: [ { type: "text", text: `Updated text decoration of node "${typedResult.name}" to ${typedResult.textDecoration}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error setting text decoration: ${error instanceof Error ? error.message : String(error)}` } ] }; } } ); - The sendCommandToFigma helper function that sends the 'set_text_decoration' command (and any other command) over a WebSocket connection to the Figma plugin server.
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)); }); }