Set_auto_layouts
Overview
The set_auto_layouts
function is a powerful tool for automating the process of setting up auto-layouts in Figma. It allows you to apply a comprehensive set of auto-layout settings to multiple nodes in a single operation, making it an essential feature for designers and developers working with Figma.
Key Features
1. Batch Processing
The set_auto_layouts
function enables batch processing, allowing you to apply auto-layout settings to multiple nodes simultaneously. This feature saves time and effort, making it an ideal solution for large-scale design projects.
2. Comprehensive Configuration
The function provides a wide range of configuration options for auto-layouts, including:
- Layout Mode: Choose from horizontal, vertical, or none layout modes to suit your design needs.
- Sizing Modes: Set primary and counter-axis sizing modes to control the behavior of your auto-layouts.
- Item Spacing: Adjust the spacing between items in your auto-layouts.
- Padding: Add padding to your auto-layouts to create a more visually appealing design.
- Alignment: Choose from various alignment options to control the positioning of items in your auto-layouts.
3. Position Maintenance
The set_auto_layouts
function allows you to maintain the original position of nodes during auto-layout updates. This feature ensures that your design remains intact and that you don't lose any critical information.
4. Validation
The function includes a validation mechanism to ensure that only compatible node types are modified. This feature prevents errors and ensures that your design remains stable.
5. Error Handling
The set_auto_layouts
function provides robust error handling, allowing you to skip invalid nodes or throw errors. This feature enables you to handle unexpected situations and maintain a smooth design workflow.
Example Usage
await figma.commands.executeCommand('set_auto_layouts', {
layouts: [
{
node_id: '1:23',
mode: 'VERTICAL',
primary_axis_sizing: 'AUTO',
item_spacing: 20,
padding: { top: 16, bottom: 16 },
align_items: 'CENTER'
},
{
node_id: '4:56',
mode: 'HORIZONTAL',
counter_axis_sizing: 'FIXED',
item_spacing: 10
}
],
options: {
maintain_position: true
}
});
Implementation Notes
The set_auto_layouts
function follows the repository's batch operation patterns and handles Figma's auto-layout API constraints. It maintains backward compatibility with existing nodes and includes viewport management and selection control.
Required Type Additions
// src/talk_to_figma_mcp/types/modification-tools.d.ts
declare module '@figma/plugin-typings' {
interface ModificationTools {
set_auto_layouts(params: {
layouts: Array<{
node_id: string;
mode: 'HORIZONTAL' | 'VERTICAL' | 'NONE';
primary_axis_sizing?: 'FIXED' | 'AUTO';
counter_axis_sizing?: 'FIXED' | 'AUTO';
item_spacing?: number;
padding?: {
top?: number;
right?: number;
bottom?: number;
left?: number;
};
align_items?: 'MIN' | 'CENTER' | 'MAX' | 'SPACE_BETWEEN';
}>;
options?: {
skip_errors?: boolean;
maintain_position?: boolean;
};
}): Promise<SceneNode[]>;
}
}
Sources
The implementation of the set_auto_layouts
function is based on the following sources:
- [1] arinspunk/claude-talk-to-figma-mcp - GitHub https://github.com/arinspunk/claude-talk-to-figma-mcp
- [2] Figma - MCP Server - Magic Slides https://www.magicslides.app/mcps/matthewdailey-figma
- [3] Specification - Model Context Protocol https://modelcontextprotocol.io/specification/2025-03-26
- [4] layoutMode | Plugin API - Figma https://www.figma.com/plugin-docs/api/properties/nodes-layoutmode/
- [5] Cursor Talk To Figma MCP Plugin https://www.figma.com/community/plugin/1485687494525374295/cursor-talk-to-figma-mcp-plugin
- [6] FrameNode | Plugin API - Figma https://www.figma.com/plugin-docs/api/FrameNode/
- [7] MCP for PMs: How To Automate Figma → Jira (Epics, Stories) in 10 ... https://www.productcompass.pm/p/mcp-case-study-jira-figma
- [8] MatthewDailey/figma-mcp: ModelContextProtocol for ... - GitHub https://github.com/MatthewDailey/figma-mcp
- [9] primaryAxisSizingMode | Plugin API - Figma https://www.figma.com/plugin-docs/api/properties/nodes-primaryaxissizingmode/
- [10] Talk to Figma MCP server for AI agents - Playbooks https://playbooks.com/mcp/yhc984-talk-to-figma
- [11] Talk to Figma MCP – An MCP server integration that enables Cursor ... https://www.reddit.com/r/mcp/comments/1jfys3e/talk_to_figma_mcp_an_mcp_server_integration_that/
- [12] itemSpacing | Plugin API - Figma https://www.figma.com/plugin-docs/api/properties/nodes-itemspacing/
- [13] Figma Now Has a MCP Server and Here's How to Use It - Apidog https://apidog.com/blog/figma-mcp/
- [14] Claude Figma MCP server for AI agents - Playbooks https://playbooks.com/mcp/tonycueva-figma
- [15] primaryAxisAlignItems | Plugin API - Figma https://www.figma.com/plugin-docs/api/properties/nodes-primaryaxisalignitems/
- [16] smithery-ai/mcp-figma - GitHub https://github.com/smithery-ai/mcp-figma
- [17] counterAxisSpacing | Plugin API - Figma https://www.figma.com/plugin-docs/api/properties/nodes-counteraxisspacing/
- [18] Claude Code designing in Figma with MCP server and plug-in https://www.youtube.com/watch?v=1L1tSwJk30Y
- [19] Model Context Protocol - GitHub https://github.com/modelcontextprotocol
- [20] Cursor Talk To Figma Mcp - MCP Servers https://mcp.so/en/server/cursor-talk-to-figma-mcp/sonnylazuardi
- [21] Converting Figma designs with Cursor MCP - YouTube https://www.youtube.com/watch?v=X-aX1TuGP0s
- [22] Introducing the Model Context Protocol - Anthropic https://www.anthropic.com/news/model-context-protocol
- [23] Cursor Talk to Figma MCP Server - GenAI Works https://genai.works/mcp-servers/Cursor-Talk-to-Figma-MCP-Server
- [24] Sonny Lazuardi's Post - LinkedIn https://www.linkedin.com/posts/sonnylazuardi_just-wanted-to-share-my-latest-experiment-activity-7307821553654657024-yrh8
- [25] Model Context Protocol - Cursor https://docs.cursor.com/context/model-context-protocol
- [26] sonnylazuardi/cursor-talk-to-figma-mcp - GitHub https://github.com/sonnylazuardi/cursor-talk-to-figma-mcp
- [27] Model Context Protocol (MCP) - PydanticAI https://ai.pydantic.dev/mcp/
- [28] Figma Design Automation MCP Client - MCP.so https://mcp.so/client/figma-design-mcp
- [29] Model Context Protocol: Introduction https://modelcontextprotocol.io/introduction
- [30] Everyone's Talking About This MCP Server for Figma - YouTube https://www.youtube.com/watch?v=feHyglFV6js
- [31] MCP - Connect your AI tool to Figma https://html.to.design/docs/mcp-tab/
- [32] Claude Code designing in Figma with MCP server and plug-in https://www.linkedin.com/posts/sonnylazuardi_claude-code-designing-in-figma-with-mcp-server-activity-7308248516710027264-j_5K
- [33] mcp-figma/USAGE.md at main - GitHub https://github.com/smithery-ai/mcp-figma/blob/main/USAGE.md
- [34] Differentiate vertical/horizontal item spacing values in REST API ... https://forum.figma.com/ask-the-community-7/solved-differentiate-vertical-horizontal-item-spacing-values-in-rest-api-response-for-wrapping-auto-layout-frames-15011
- [35] Shared Node Properties | Plugin API - Figma https://www.figma.com/plugin-docs/api/node-properties/
- [36] GLips/Figma-Context-MCP: MCP server to provide Figma ... - GitHub https://github.com/GLips/Figma-Context-MCP
- [37] How to convert a Figma design to code with Claude - PulseMCP https://www.pulsemcp.com/use-cases/figma-to-code/macoughl-claude-figma
- [38] Edward Chechique's Post - LinkedIn https://www.linkedin.com/posts/edwche_figma-mcp-design-automation-on-steroids-activity-7309854009278787584
Frequently Asked Questions
Q: What is the set_auto_layouts
function?
A: The set_auto_layouts
function is a powerful tool for automating the process of setting up auto-layouts in Figma. It allows you to apply a comprehensive set of auto-layout settings to multiple nodes in a single operation.
Q: What are the key features of the set_auto_layouts
function?
A: The key features of the set_auto_layouts
function include:
- Batch Processing: Applies auto-layout settings to multiple nodes simultaneously.
- Comprehensive Configuration: Provides a wide range of configuration options for auto-layouts, including layout mode, sizing modes, item spacing, padding, and alignment.
- Position Maintenance: Maintains the original position of nodes during auto-layout updates.
- Validation: Ensures that only compatible node types are modified.
- Error Handling: Provides robust error handling, allowing you to skip invalid nodes or throw errors.
Q: How do I use the set_auto_layouts
function?
A: To use the set_auto_layouts
function, you need to call it with an object containing the following properties:
- layouts: An array of objects, each containing the node ID, layout mode, primary axis sizing mode, counter axis sizing mode, item spacing, padding, and alignment.
- options: An object containing the following properties:
- skip_errors: A boolean indicating whether to skip invalid nodes or throw errors.
- maintain_position: A boolean indicating whether to maintain the original position of nodes during auto-layout updates.
Q: What are the benefits of using the set_auto_layouts
function?
A: The benefits of using the set_auto_layouts
function include:
- Time-saving: Automates the process of setting up auto-layouts, saving you time and effort.
- Improved accuracy: Ensures that auto-layout settings are applied consistently and accurately.
- Increased productivity: Allows you to focus on other tasks while the
set_auto_layouts
function takes care of setting up auto-layouts.
Q: What are the limitations of the set_auto_layouts
function?
A: The limitations of the set_auto_layouts
function include:
- Compatibility: Only works with Figma nodes that support auto-layouts.
- Configuration: Requires a comprehensive understanding of auto-layout settings and Figma node properties.
- Error handling: May throw errors if invalid nodes or configuration options are provided.
Q: How do I troubleshoot issues with the set_auto_layouts
function?
A: To troubleshoot issues with the set_auto_layouts
function, you can:
- Check the Figma documentation: Ensure that you have a comprehensive understanding of Figma node properties and auto-layout settings.
- Verify the configuration options: Double-check that the configuration options provided are correct and valid.
- Use the error handling mechanism: If errors occur, use the error handling mechanism to skip invalid nodes or throw errors.
Q: Can I customize the set_auto_layouts
function to suit my needs?
A: Yes, you can customize the set_auto_layouts
function to suit your needs by:
- Modifying the configuration options: Add or remove configuration options to suit your specific requirements.
- Implementing custom error handling: Create custom error handling mechanisms to handle specific error scenarios.
- Extending the function: Extend the
set_auto_layouts
function to support additional features or functionality.
Q: What are the best practices for using the set_auto_layouts
function?
A: The best practices for using the set_auto_layouts
function include:
- Thoroughly test the function: Test the
set_auto_layouts
function with various configuration options and node types to ensure that it works as expected. - Use the error handling mechanism: Use the error handling mechanism to handle errors and exceptions that may occur during execution.
- Document the function: Document the
set_auto_layouts
function and its usage to ensure that others can understand and use it effectively.