Skip to main content
Glama

Cursor Talk to Figma MCP

by paragdesai1

set_item_spacing

Adjust spacing between elements in an auto-layout frame in Figma using the Cursor AI and MCP integration.

Instructions

Set distance between children in an auto-layout frame

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": {}, "type": "object" }

Implementation Reference

  • Executes the core logic for the set_item_spacing tool by retrieving the specified Figma node, validating it supports auto-layout (FRAME, COMPONENT, etc. with layoutMode !== 'NONE'), and setting its itemSpacing property.
    async function setItemSpacing(params) { const { nodeId, itemSpacing } = 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 item spacing if ( node.type !== "FRAME" && node.type !== "COMPONENT" && node.type !== "COMPONENT_SET" && node.type !== "INSTANCE" ) { throw new Error(`Node type ${node.type} does not support item spacing`); } // Check if the node has auto-layout enabled if (node.layoutMode === "NONE") { throw new Error( "Item spacing can only be set on auto-layout frames (layoutMode must not be NONE)" ); } // Set item spacing if (itemSpacing !== undefined) { if (typeof itemSpacing !== "number") { throw new Error("Item spacing must be a number"); } node.itemSpacing = itemSpacing; } return { id: node.id, name: node.name, itemSpacing: node.itemSpacing, layoutMode: node.layoutMode, }; }
  • Registers the 'set_item_spacing' MCP tool, defines its input schema (nodeId and itemSpacing) using Zod, and provides a handler that forwards the parameters to the Figma plugin via WebSocket using sendCommandToFigma.
    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)}`, }, ], }; } } );
  • Dispatches the 'set_item_spacing' command to the specific handler function within the Figma plugin's main command router.
    case "set_item_spacing": return await setItemSpacing(params);
  • Zod schema for input validation of the set_item_spacing tool parameters.
    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.") },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/paragdesai1/parag-Figma-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server