set_padding
Define padding values for auto-layout frames in Figma to adjust spacing efficiently. Automates design modifications using natural language commands for streamlined workflow.
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
- The handler function for the 'set_padding' tool. It sends the set_padding command to the Figma plugin via sendCommandToFigma, processes the result, constructs a descriptive message about the applied padding values, and returns it in the MCP response format. Handles errors appropriately.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)}`, }, ], }; } }
- Zod schema defining the input parameters for the set_padding tool: required nodeId (string) and optional padding values (numbers) for top, right, bottom, left.{ 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"), },
- src/talk_to_figma_mcp/server.ts:2140-2191 (registration)Registration of the 'set_padding' MCP tool using server.tool(), including the tool name, description, input schema, and handler function.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)}`, }, ], }; } } );