Skip to main content
Glama
yhc984
by yhc984

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
NameRequiredDescriptionDefault
componentKeyYesKey of the component to instantiate
xYesX position
yYesY position

Implementation Reference

  • 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}`); } }
  • Registration of the create_component_instance command in the Figma plugin's command handler switch statement.
    case "create_component_instance": return await createComponentInstance(params);
  • 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") },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yhc984/cursor-talk-to-figma-mcp-main'

If you have feedback or need assistance with the MCP directory API, please join our Discord server