insert_child
Insert a child node into a parent node in Figma to organize design elements. Specify parent and child IDs with optional index placement.
Instructions
Insert a child node inside a parent node in Figma
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parentId | Yes | ID of the parent node where the child will be inserted | |
| childId | Yes | ID of the child node to insert | |
| index | No | Optional index where to insert the child (if not specified, it will be added at the end) |
Implementation Reference
- The main handler function that implements the logic for the 'insert_child' tool. It forwards the parameters to the Figma plugin via sendCommandToFigma and formats the response.async ({ parentId, childId, index }) => { try { const result = await sendCommandToFigma("insert_child", { parentId, childId, index }); const typedResult = result as { parentId: string, childId: string, index: number, success: boolean }; return { content: [ { type: "text", text: `Child node with ID: ${typedResult.childId} successfully inserted into parent node with ID: ${typedResult.parentId}${index !== undefined ? ` at position ${typedResult.index}` : ''}.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error inserting child node: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
- Zod schema defining the input parameters for the insert_child tool: parentId, childId, and optional index.parentId: z.string().describe("ID of the parent node where the child will be inserted"), childId: z.string().describe("ID of the child node to insert"), index: z.number().optional().describe("Optional index where to insert the child (if not specified, it will be added at the end)") },
- src/talk_to_figma_mcp/tools/creation-tools.ts:540-581 (registration)The server.tool() call that registers the 'insert_child' tool with MCP server, including name, description, input schema, and handler function."insert_child", "Insert a child node inside a parent node in Figma", { parentId: z.string().describe("ID of the parent node where the child will be inserted"), childId: z.string().describe("ID of the child node to insert"), index: z.number().optional().describe("Optional index where to insert the child (if not specified, it will be added at the end)") }, async ({ parentId, childId, index }) => { try { const result = await sendCommandToFigma("insert_child", { parentId, childId, index }); const typedResult = result as { parentId: string, childId: string, index: number, success: boolean }; return { content: [ { type: "text", text: `Child node with ID: ${typedResult.childId} successfully inserted into parent node with ID: ${typedResult.parentId}${index !== undefined ? ` at position ${typedResult.index}` : ''}.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error inserting child node: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
- src/talk_to_figma_mcp/tools/index.ts:14-14 (registration)Higher-level registration call that invokes registerCreationTools(server), which includes the insert_child tool registration.registerCreationTools(server);