create_component_instance
Generate a Figma component instance at specified coordinates using the component key, enabling direct manipulation of design elements through the Talk to Figma MCP server.
Instructions
Create an instance of a component in Figma
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| componentKey | Yes | Key of the component to instantiate | |
| x | Yes | X position | |
| y | Yes | Y position |
Implementation Reference
- src/cursor_mcp_plugin/code.js:644-672 (handler)The core handler function that imports a Figma component by its key, creates an instance, positions it, adds to current page, and returns details.async function createComponentInstance(params) { const { componentKey, x = 0, y = 0 } = params || {}; if (!componentKey) { throw new Error("Missing componentKey parameter"); } try { const component = await figma.importComponentByKeyAsync(componentKey); const instance = component.createInstance(); instance.x = x; instance.y = y; figma.currentPage.appendChild(instance); return { id: instance.id, name: instance.name, x: instance.x, y: instance.y, width: instance.width, height: instance.height, componentId: instance.componentId, }; } catch (error) { throw new Error(`Error creating component instance: ${error.message}`); } }
- src/cursor_mcp_plugin/code.js:95-96 (registration)Registration of the create_component_instance command in the Figma plugin's command handler switch statement.case "create_component_instance": return await createComponentInstance(params);
- src/talk_to_figma_mcp/server.ts:531-562 (registration)MCP server tool registration for create_component_instance, including schema and proxy handler that forwards to Figma plugin.server.tool( "create_component_instance", "Create an instance of a component in Figma", { componentKey: z.string().describe("Key of the component to instantiate"), x: z.number().describe("X position"), y: z.number().describe("Y position") }, async ({ componentKey, x, y }) => { try { const result = await sendCommandToFigma('create_component_instance', { componentKey, x, y }); const typedResult = result as { name: string, id: string }; return { content: [ { type: "text", text: `Created component instance "${typedResult.name}" with ID: ${typedResult.id}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error creating component instance: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
- Input schema definition using Zod for the MCP tool parameters: componentKey, x, y.componentKey: z.string().describe("Key of the component to instantiate"), x: z.number().describe("X position"), y: z.number().describe("Y position") },