get_styled_text_segments
Analyze a Figma text node to extract segments that match a specified style property, such as font size or fill color, for targeted design inspection and adjustments.
Instructions
Get text segments with specific styling in a text node
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the text node to analyze | |
| property | Yes | The style property to analyze segments by |
Implementation Reference
- The get_styled_text_segments tool handler registered on the MCP server. It accepts nodeId and property parameters, sends the command to Figma via WebSocket, and returns the styled text segments result as JSON.
// Get Styled Text Segments Tool server.tool( "get_styled_text_segments", "Get text segments with specific styling in a text node", { nodeId: z.string().describe("The ID of the text node to analyze"), property: z.enum([ "fillStyleId", "fontName", "fontSize", "textCase", "textDecoration", "textStyleId", "fills", "letterSpacing", "lineHeight", "fontWeight" ]).describe("The style property to analyze segments by"), }, async ({ nodeId, property }) => { try { const result = await sendCommandToFigma("get_styled_text_segments", { nodeId, property }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error getting styled text segments: ${error instanceof Error ? error.message : String(error)}` } ] }; } } ); - Input schema for the tool using Zod: nodeId (string) and property (enum of fillStyleId, fontName, fontSize, textCase, textDecoration, textStyleId, fills, letterSpacing, lineHeight, fontWeight).
{ nodeId: z.string().describe("The ID of the text node to analyze"), property: z.enum([ "fillStyleId", "fontName", "fontSize", "textCase", "textDecoration", "textStyleId", "fills", "letterSpacing", "lineHeight", "fontWeight" ]).describe("The style property to analyze segments by"), }, - src/talk_to_figma_mcp/tools/text-tools.ts:450-495 (registration)Tool registered via server.tool('get_styled_text_segments', ...) inside registerTextTools(). The registerTextTools function is called from tools/index.ts which is called from server.ts.
// Get Styled Text Segments Tool server.tool( "get_styled_text_segments", "Get text segments with specific styling in a text node", { nodeId: z.string().describe("The ID of the text node to analyze"), property: z.enum([ "fillStyleId", "fontName", "fontSize", "textCase", "textDecoration", "textStyleId", "fills", "letterSpacing", "lineHeight", "fontWeight" ]).describe("The style property to analyze segments by"), }, async ({ nodeId, property }) => { try { const result = await sendCommandToFigma("get_styled_text_segments", { nodeId, property }); return { content: [ { type: "text", text: JSON.stringify(result, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error getting styled text segments: ${error instanceof Error ? error.message : String(error)}` } ] }; } } ); - sendCommandToFigma function that sends the command over WebSocket and returns a promise. The get_styled_text_segments handler calls this with command type 'get_styled_text_segments'.
export function sendCommandToFigma( command: FigmaCommand, params: unknown = {}, timeoutMs: number = 300000 ): Promise<unknown> { - Type definition: 'get_styled_text_segments' is listed as a valid FigmaCommand in the union type, ensuring type safety for command routing.
| "get_styled_text_segments"