get_styled_text_segments
Extract text segments from Figma nodes based on specific styling properties like font, color, or spacing for design analysis and consistency checks.
Instructions
Get text segments with specific styling in a text node
Input Schema
TableJSON 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 handler function that executes the tool logic: sends 'get_styled_text_segments' command to Figma and returns the result as JSON-formatted text content or error message.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)}` } ] }; } }
- Zod input schema defining parameters: nodeId (string) and property (enum of specific style properties).{ 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-494 (registration)Registration of the 'get_styled_text_segments' tool on the MCP server, specifying name, description, input schema, and handler function.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)}` } ] }; } } );
- TypeScript union type FigmaCommand includes 'get_styled_text_segments' for type safety in Figma websocket commands.export type FigmaCommand = | "get_document_info" | "get_selection" | "get_node_info" | "create_rectangle" | "create_frame" | "create_text" | "create_ellipse" | "create_polygon" | "create_star" | "create_vector" | "create_line" | "set_fill_color" | "set_stroke_color" | "move_node" | "resize_node" | "delete_node" | "get_styles" | "get_local_components" | "get_team_components" | "create_component_instance" | "export_node_as_image" | "join" | "set_corner_radius" | "clone_node" | "set_text_content" | "scan_text_nodes" | "set_multiple_text_contents" | "set_auto_layout" | "set_font_name" | "set_font_size" | "set_font_weight" | "set_letter_spacing" | "set_line_height" | "set_paragraph_spacing" | "set_text_case" | "set_text_decoration" | "get_styled_text_segments" | "load_font_async" | "get_remote_components" | "set_effects" | "set_effect_style_id" | "group_nodes" | "ungroup_nodes" | "flatten_node" | "insert_child";