Skip to main content
Glama
paragdesai1

Cursor Talk to Figma MCP

by paragdesai1

set_padding

Adjust padding values for auto-layout frames in Figma designs through programmatic control, enabling precise spacing customization between elements.

Instructions

Set padding values for an auto-layout frame in Figma

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodeIdYesThe ID of the frame to modify
paddingTopNoTop padding value
paddingRightNoRight padding value
paddingBottomNoBottom padding value
paddingLeftNoLeft padding value

Implementation Reference

  • Registration of the 'set_padding' MCP tool, including schema definition and handler implementation. The handler sends a 'set_padding' command to the Figma plugin and formats the response.
    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)}`,
              },
            ],
          };
        }
      }
    );
  • Handler function for the set_padding tool. It calls sendCommandToFigma with the padding parameters and constructs a success/error response message.
    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)}`,
            },
          ],
        };
      }
    }
  • Input schema for the set_padding tool using Zod validation, defining optional padding values 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"),
    },

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