clone_node
Duplicate Figma design elements by cloning nodes to new positions, enabling rapid design iteration and component reuse.
Instructions
Clone an existing node in Figma
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"nodeId": "<nodeId>"
},
"name": "clone_node"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the node to clone | |
| x | No | New X position for the clone | |
| y | No | New Y position for the clone |
Implementation Reference
- src/cursor_mcp_plugin/code.js:1392-1430 (handler)The core handler function that executes the clone_node tool logic in the Figma plugin: retrieves node by ID, clones it using Figma's node.clone() API, optionally repositions the clone, appends to the original parent, and returns clone details.
const { nodeId, x, y } = params || {}; if (!nodeId) { throw new Error("Missing nodeId parameter"); } const node = await figma.getNodeByIdAsync(nodeId); if (!node) { throw new Error(`Node not found with ID: ${nodeId}`); } // Clone the node const clone = node.clone(); // If x and y are provided, move the clone to that position if (x !== undefined && y !== undefined) { if (!("x" in clone) || !("y" in clone)) { throw new Error(`Cloned node does not support position: ${nodeId}`); } clone.x = x; clone.y = y; } // Add the clone to the same parent as the original node if (node.parent) { node.parent.appendChild(clone); } else { figma.currentPage.appendChild(clone); } return { id: clone.id, name: clone.name, x: "x" in clone ? clone.x : undefined, y: "y" in clone ? clone.y : undefined, width: "width" in clone ? clone.width : undefined, height: "height" in clone ? clone.height : undefined, }; } - src/talk_to_figma_mcp/server.ts:694-725 (registration)Registers the 'clone_node' MCP tool, defining its input schema (nodeId required, x/y optional), description, and proxy handler that sends the command to the Figma plugin via WebSocket and formats the response.
server.tool( "clone_node", "Clone an existing node in Figma", { nodeId: z.string().describe("The ID of the node to clone"), x: z.number().optional().describe("New X position for the clone"), y: z.number().optional().describe("New Y position for the clone") }, async ({ nodeId, x, y }) => { try { const result = await sendCommandToFigma('clone_node', { nodeId, x, y }); const typedResult = result as { name: string, id: string }; return { content: [ { type: "text", text: `Cloned node "${typedResult.name}" with new ID: ${typedResult.id}${x !== undefined && y !== undefined ? ` at position (${x}, ${y})` : ''}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error cloning node: ${error instanceof Error ? error.message : String(error)}` } ] }; } } ); - Zod schema defining input parameters for clone_node tool: nodeId (string, required), x and y (number, optional).
{ nodeId: z.string().describe("The ID of the node to clone"), x: z.number().optional().describe("New X position for the clone"), y: z.number().optional().describe("New Y position for the clone") }, - src/cursor_mcp_plugin/code.js:155-156 (handler)Dispatch case in Figma plugin's handleCommand switch that routes 'clone_node' commands to the cloneNode implementation function.
case "clone_node": return await cloneNode(params); - Includes 'clone_node' in FigmaCommand type union for TypeScript type safety in command handling.
| "clone_node"