resize_node
Resize a Figma node to custom width and height using its unique node identifier.
Instructions
Resize a node in Figma
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the node to resize | |
| width | Yes | New width | |
| height | Yes | New height |
Implementation Reference
- The handler for the 'resize_node' tool. Defined via server.tool(), it accepts nodeId, width, height, calls sendCommandToFigma('resize_node', ...), and returns a text response with the resized node's name and dimensions.
// Resize Node Tool server.tool( "resize_node", "Resize a node in Figma", { nodeId: z.string().describe("The ID of the node to resize"), width: z.coerce.number().positive().describe("New width"), height: z.coerce.number().positive().describe("New height"), }, async ({ nodeId, width, height }) => { try { const result = await sendCommandToFigma("resize_node", { nodeId, width, height, }); const typedResult = result as { name: string }; return { content: [ { type: "text", text: `Resized node "${typedResult.name}" to width ${width} and height ${height}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error resizing node: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); - src/talk_to_figma_mcp/tools/index.ts:17-21 (registration)registerModificationTools(server) is called from registerTools() which registers all tool categories to the MCP server.
export function registerTools(server: McpServer): void { // Register all tool categories registerDocumentTools(server); registerCreationTools(server); registerModificationTools(server); - src/talk_to_figma_mcp/tools/index.ts:17-29 (registration)registerModificationTools(server) is called from registerTools() which registers all tool categories to the MCP server.
export function registerTools(server: McpServer): void { // Register all tool categories registerDocumentTools(server); registerCreationTools(server); registerModificationTools(server); registerTextTools(server); registerComponentTools(server); registerImageTools(server); registerSvgTools(server); registerVariableTools(server); registerFigJamTools(server); registerStyleTools(server); } - The 'resize_node' string literal is part of the FigmaCommand union type, which defines all valid command identifiers for the Figma WebSocket protocol.
export type FigmaCommand = | "get_document_info" | "get_selection" | "get_node_info" | "create_rectangle" | "create_frame" | "create_text" | "create_ellipse" | "create_polygon" | "create_star" | "create_vector" | "create_line" | "set_fill_color" | "set_stroke_color" | "move_node" | "resize_node" | "delete_node" | "get_styles" | "get_local_components" | "get_team_components" | "create_component_instance" | "export_node_as_image" | "join" | "ping" | "set_corner_radius" | "clone_node" | "set_text_content" | "scan_text_nodes" | "set_multiple_text_contents" - sendCommandToFigma() is the generic helper that sends commands (including 'resize_node') over WebSocket to the Figma plugin server. It constructs the request, manages timeouts, and resolves/rejects based on the response.
export function sendCommandToFigma( command: FigmaCommand, params: unknown = {}, timeoutMs: number = 300000 ): Promise<unknown> { return new Promise((resolve, reject) => { // If not connected, try to connect first if (!ws || ws.readyState !== WebSocket.OPEN) { connectToFigma(); reject(new Error("Not connected to Figma. Attempting to connect...")); return; } // Check if we need a channel for this command const requiresChannel = command !== "join"; if (requiresChannel && !currentChannel) { reject(new Error("Must join a channel before sending commands")); return; } const id = uuidv4(); const request = { id, type: command === "join" ? "join" : "message", ...(command === "join" ? { channel: (params as any).channel, sessionId: SESSION_ID } : { channel: currentChannel }), message: { id, command, params: { ...(params as any), commandId: id, // Include the command ID in params }, }, }; // Set timeout for request const timeout = setTimeout(() => { if (pendingRequests.has(id)) { pendingRequests.delete(id); logger.error(`Request ${id} to Figma timed out after ${timeoutMs / 1000} seconds`); reject(new Error('Request to Figma timed out')); } }, timeoutMs); // Store the promise callbacks to resolve/reject later pendingRequests.set(id, { resolve, reject, timeout, lastActivity: Date.now() }); // Send the request logger.info(`Sending command to Figma: ${command}`); logger.debug(`Request details: ${JSON.stringify(request)}`); ws.send(JSON.stringify(request)); }); }