create_polygon
Generate custom polygons in Figma using natural language commands, enabling AI-assisted design workflows with direct integration through MCP server.
Instructions
Create a new polygon in Figma
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- The core handler implementation for the 'create_polygon' MCP tool. It validates inputs with Zod schema, sends a 'create_polygon' command to Figma via sendCommandToFigma websocket utility, handles the response, and returns formatted content or error.server.tool( "create_polygon", "Create a new polygon in Figma", { x: z.number().describe("X position"), y: z.number().describe("Y position"), width: z.number().describe("Width of the polygon"), height: z.number().describe("Height of the polygon"), sides: z.number().min(3).optional().describe("Number of sides (default: 6)"), name: z.string().optional().describe("Optional name for the polygon"), parentId: z.string().optional().describe("Optional parent node ID to append the polygon to"), fillColor: z .object({ r: z.number().min(0).max(1).describe("Red component (0-1)"), g: z.number().min(0).max(1).describe("Green component (0-1)"), b: z.number().min(0).max(1).describe("Blue component (0-1)"), a: z.number().min(0).max(1).optional().describe("Alpha component (0-1)"), }) .optional() .describe("Fill color in RGBA format"), strokeColor: z .object({ r: z.number().min(0).max(1).describe("Red component (0-1)"), g: z.number().min(0).max(1).describe("Green component (0-1)"), b: z.number().min(0).max(1).describe("Blue component (0-1)"), a: z.number().min(0).max(1).optional().describe("Alpha component (0-1)"), }) .optional() .describe("Stroke color in RGBA format"), strokeWeight: z.number().positive().optional().describe("Stroke weight"), }, async ({ x, y, width, height, sides, name, parentId, fillColor, strokeColor, strokeWeight }) => { try { const result = await sendCommandToFigma("create_polygon", { x, y, width, height, sides: sides || 6, name: name || "Polygon", parentId, fillColor, strokeColor, strokeWeight, }); const typedResult = result as { id: string, name: string }; return { content: [ { type: "text", text: `Created polygon with ID: ${typedResult.id} and ${sides || 6} sides` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error creating polygon: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
- src/talk_to_figma_mcp/tools/index.ts:15-15 (registration)Registration of creation tools (including create_polygon) by calling registerCreationTools(server) within the overall registerTools function.registerCreationTools(server);
- src/talk_to_figma_mcp/server.ts:34-34 (registration)Top-level registration of all tools (including create_polygon via chained calls) in the main MCP server initialization.registerTools(server);
- TypeScript type definition for FigmaCommand union that includes 'create_polygon' as an expected command sent to Figma.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";