set_item_spacing
Adjust spacing between elements in auto-layout frames to control visual hierarchy and alignment in Figma designs.
Instructions
Set distance between children in an auto-layout frame
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the frame to modify | |
| itemSpacing | Yes | Distance between children. Note: This value will be ignored if primaryAxisAlignItems is set to SPACE_BETWEEN. |
Implementation Reference
- src/talk_to_figma_mcp/server.ts:2301-2336 (registration)Registration of the MCP tool 'set_item_spacing'. Includes the tool name, description, input schema (nodeId: string, itemSpacing: number), and the handler function that sends a 'set_item_spacing' command to the Figma plugin via WebSocket and formats the response.// Set Item Spacing Tool server.tool( "set_item_spacing", "Set distance between children in an auto-layout frame", { nodeId: z.string().describe("The ID of the frame to modify"), itemSpacing: z.number().describe("Distance between children. Note: This value will be ignored if primaryAxisAlignItems is set to SPACE_BETWEEN.") }, async ({ nodeId, itemSpacing }) => { try { const result = await sendCommandToFigma("set_item_spacing", { nodeId, itemSpacing }); const typedResult = result as { name: string }; return { content: [ { type: "text", text: `Set item spacing to ${itemSpacing} for frame "${typedResult.name}"`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting item spacing: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
- Input schema for the 'set_item_spacing' tool using Zod validation: requires nodeId (string) and itemSpacing (number).nodeId: z.string().describe("The ID of the frame to modify"), itemSpacing: z.number().describe("Distance between children. Note: This value will be ignored if primaryAxisAlignItems is set to SPACE_BETWEEN.") },
- Handler function for the 'set_item_spacing' tool. Proxies the parameters to the Figma plugin using sendCommandToFigma('set_item_spacing'), handles the result by extracting the frame name, and returns a formatted text response or error message.async ({ nodeId, itemSpacing }) => { try { const result = await sendCommandToFigma("set_item_spacing", { nodeId, itemSpacing }); const typedResult = result as { name: string }; return { content: [ { type: "text", text: `Set item spacing to ${itemSpacing} for frame "${typedResult.name}"`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting item spacing: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } }