set_image
Set an image fill on a Figma node from base64-encoded image data. Supports PNG, JPEG, GIF, WebP formats up to ~5MB after decoding. Specify node ID, image data, and optional scale mode (FILL, FIT, CROP, TILE).
Instructions
Set an image fill on a node from base64-encoded image data. Supports PNG, JPEG, GIF, WebP. Max ~5MB after decode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the node to apply the image fill to | |
| imageData | Yes | Base64-encoded image data (PNG, JPEG, GIF, or WebP). Max ~5MB after decode. | |
| scaleMode | No | How the image is scaled within the node (default: FILL) |
Implementation Reference
- The 'set_image' tool handler. Registers a server tool that accepts nodeId, base64 imageData, and optional scaleMode, then sends a 'set_image' command to Figma via WebSocket. Returns the node name and image hash on success, or an error message on failure.
// Set Image Fill Tool server.tool( "set_image", "Set an image fill on a node from base64-encoded image data. Supports PNG, JPEG, GIF, WebP. Max ~5MB after decode.", { nodeId: z.string().describe("The ID of the node to apply the image fill to"), imageData: z.string().max(7_000_000).describe("Base64-encoded image data (PNG, JPEG, GIF, or WebP). Max ~5MB after decode."), scaleMode: z.enum(["FILL", "FIT", "CROP", "TILE"]).optional().describe("How the image is scaled within the node (default: FILL)"), }, async ({ nodeId, imageData, scaleMode }) => { try { const result = await sendCommandToFigma("set_image", { nodeId, imageData, scaleMode: scaleMode || "FILL", }); const typedResult = result as { name: string; imageHash: string }; return { content: [ { type: "text", text: `Set image fill on node "${typedResult.name}" with scale mode ${scaleMode || "FILL"} (hash: ${typedResult.imageHash})`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting image fill: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); - Input schema for the 'set_image' tool: nodeId (string), imageData (base64 string, max 7M chars), scaleMode (optional enum: FILL/FIT/CROP/TILE).
{ nodeId: z.string().describe("The ID of the node to apply the image fill to"), imageData: z.string().max(7_000_000).describe("Base64-encoded image data (PNG, JPEG, GIF, or WebP). Max ~5MB after decode."), scaleMode: z.enum(["FILL", "FIT", "CROP", "TILE"]).optional().describe("How the image is scaled within the node (default: FILL)"), }, - src/talk_to_figma_mcp/tools/index.ts:21-21 (registration)Registration call: registerModificationTools(server) is called from the central registerTools function, which wires the 'set_image' tool into the MCP server.
registerModificationTools(server); - src/talk_to_figma_mcp/tools/modification-tools.ts:13-13 (registration)The registerModificationTools function declaration which internally uses server.tool() to register 'set_image' (line 662-697).
export function registerModificationTools(server: McpServer): void { - Type definition: 'set_image' is listed as a valid FigmaCommand in the union type, ensuring type safety for command dispatch.
| "set_image"