set_layout_mode
Adjust the layout mode and wrap behavior of a Figma frame using Cursor AI’s integration, enabling precise control over design elements programmatically.
Instructions
Set the layout mode and wrap behavior of a frame 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
- src/cursor_mcp_plugin/code.js:2693-2726 (handler)Figma plugin handler function that executes the set_layout_mode tool logic by setting the layoutMode and layoutWrap properties on the target node (FRAME, COMPONENT, COMPONENT_SET, or INSTANCE).async function setLayoutMode(params) { const { nodeId, layoutMode = "NONE", layoutWrap = "NO_WRAP" } = params || {}; // Get the target node const node = await figma.getNodeByIdAsync(nodeId); if (!node) { throw new Error(`Node with ID ${nodeId} not found`); } // Check if node is a frame or component that supports layoutMode if ( node.type !== "FRAME" && node.type !== "COMPONENT" && node.type !== "COMPONENT_SET" && node.type !== "INSTANCE" ) { throw new Error(`Node type ${node.type} does not support layoutMode`); } // Set layout mode node.layoutMode = layoutMode; // Set layoutWrap if applicable if (layoutMode !== "NONE") { node.layoutWrap = layoutWrap; } return { id: node.id, name: node.name, layoutMode: node.layoutMode, layoutWrap: node.layoutWrap, }; }
- src/talk_to_figma_mcp/server.ts:1928-1964 (registration)MCP server registration of the 'set_layout_mode' tool, including Zod input schema validation, thin proxy handler that sends the command via WebSocket to the Figma plugin, and formats the textual response.// Set Layout Mode Tool server.tool( "set_layout_mode", "Set the layout mode and wrap behavior of a frame in Figma", { nodeId: z.string().describe("The ID of the frame to modify"), layoutMode: z.enum(["NONE", "HORIZONTAL", "VERTICAL"]).describe("Layout mode for the frame"), layoutWrap: z.enum(["NO_WRAP", "WRAP"]).optional().describe("Whether the auto-layout frame wraps its children") }, async ({ nodeId, layoutMode, layoutWrap }) => { try { const result = await sendCommandToFigma("set_layout_mode", { nodeId, layoutMode, layoutWrap: layoutWrap || "NO_WRAP" }); const typedResult = result as { name: string }; return { content: [ { type: "text", text: `Set layout mode of frame "${typedResult.name}" to ${layoutMode}${layoutWrap ? ` with ${layoutWrap}` : ''}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting layout mode: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
- Zod schema for input validation of the set_layout_mode tool parameters.nodeId: z.string().describe("The ID of the frame to modify"), layoutMode: z.enum(["NONE", "HORIZONTAL", "VERTICAL"]).describe("Layout mode for the frame"), layoutWrap: z.enum(["NO_WRAP", "WRAP"]).optional().describe("Whether the auto-layout frame wraps its children") },