create_component_instance
Generate a component instance in Figma by specifying the component key and positioning coordinates (X, Y) for precise placement.
Instructions
Create an instance of a component in Figma
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| componentKey | Yes | Key of the component to instantiate | |
| x | Yes | X position | |
| y | Yes | Y position |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"componentKey": {
"description": "Key of the component to instantiate",
"type": "string"
},
"x": {
"description": "X position",
"type": "number"
},
"y": {
"description": "Y position",
"type": "number"
}
},
"required": [
"componentKey",
"x",
"y"
],
"type": "object"
}
Implementation Reference
- Handler function that executes the tool logic by forwarding the componentKey, x, and y parameters to the Figma plugin via sendCommandToFigma.async ({ componentKey, x, y }: any) => { try { const result = await sendCommandToFigma("create_component_instance", { componentKey, x, y, }); const typedResult = result as any; return { content: [ { type: "text", text: JSON.stringify(typedResult), } ] } } catch (error) { return { content: [ { type: "text", text: `Error creating component instance: ${error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- Zod schema defining the input parameters for the tool: componentKey (string), x (number), y (number).componentKey: z.string().describe("Key of the component to instantiate"), x: z.number().describe("X position"), y: z.number().describe("Y position"), },
- src/talk_to_figma_mcp/server.ts:1198-1234 (registration)MCP tool registration using server.tool(), specifying name, description, input schema, and handler function.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 }: any) => { try { const result = await sendCommandToFigma("create_component_instance", { componentKey, x, y, }); const typedResult = result as any; return { content: [ { type: "text", text: JSON.stringify(typedResult), } ] } } catch (error) { return { content: [ { type: "text", text: `Error creating component instance: ${error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- TypeScript type definition for CommandParams of create_component_instance in the FigmaCommand union.componentKey: string; x: number; y: number; };