set_padding
Define padding values for auto-layout frames in Figma designs programmatically, enabling precise spacing adjustments.
Instructions
Set padding values for an auto-layout 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:2728-2769 (handler)Core implementation of the set_padding tool in the Figma plugin. Sets individual padding properties (top, right, bottom, left) on an auto-layout frame node.async function setPadding(params) { const { nodeId, paddingTop, paddingRight, paddingBottom, paddingLeft } = 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 padding if ( node.type !== "FRAME" && node.type !== "COMPONENT" && node.type !== "COMPONENT_SET" && node.type !== "INSTANCE" ) { throw new Error(`Node type ${node.type} does not support padding`); } // Check if the node has auto-layout enabled if (node.layoutMode === "NONE") { throw new Error( "Padding can only be set on auto-layout frames (layoutMode must not be NONE)" ); } // Set padding values if provided if (paddingTop !== undefined) node.paddingTop = paddingTop; if (paddingRight !== undefined) node.paddingRight = paddingRight; if (paddingBottom !== undefined) node.paddingBottom = paddingBottom; if (paddingLeft !== undefined) node.paddingLeft = paddingLeft; return { id: node.id, name: node.name, paddingTop: node.paddingTop, paddingRight: node.paddingRight, paddingBottom: node.paddingBottom, paddingLeft: node.paddingLeft, }; }
- src/talk_to_figma_mcp/server.ts:1966-2019 (registration)MCP tool registration including schema (Zod) and proxy handler that forwards the set_padding command to the Figma plugin via WebSocket.// Set Padding Tool server.tool( "set_padding", "Set padding values for an auto-layout frame in Figma", { nodeId: z.string().describe("The ID of the frame to modify"), paddingTop: z.number().optional().describe("Top padding value"), paddingRight: z.number().optional().describe("Right padding value"), paddingBottom: z.number().optional().describe("Bottom padding value"), paddingLeft: z.number().optional().describe("Left padding value"), }, async ({ nodeId, paddingTop, paddingRight, paddingBottom, paddingLeft }) => { try { const result = await sendCommandToFigma("set_padding", { nodeId, paddingTop, paddingRight, paddingBottom, paddingLeft, }); const typedResult = result as { name: string }; // Create a message about which padding values were set const paddingMessages = []; if (paddingTop !== undefined) paddingMessages.push(`top: ${paddingTop}`); if (paddingRight !== undefined) paddingMessages.push(`right: ${paddingRight}`); if (paddingBottom !== undefined) paddingMessages.push(`bottom: ${paddingBottom}`); if (paddingLeft !== undefined) paddingMessages.push(`left: ${paddingLeft}`); const paddingText = paddingMessages.length > 0 ? `padding (${paddingMessages.join(', ')})` : "padding"; return { content: [ { type: "text", text: `Set ${paddingText} for frame "${typedResult.name}"`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting padding: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } );
- src/cursor_mcp_plugin/code.js:171-173 (registration)Dispatch/registration of the set_padding command in the Figma plugin's handleCommand switch statement.case "set_padding": return await setPadding(params); case "set_axis_align":
- Input schema (Zod validation) for the set_padding tool parameters.nodeId: z.string().describe("The ID of the frame to modify"), paddingTop: z.number().optional().describe("Top padding value"), paddingRight: z.number().optional().describe("Right padding value"), paddingBottom: z.number().optional().describe("Bottom padding value"), paddingLeft: z.number().optional().describe("Left padding value"), },