export_node_as_image
Convert Figma design nodes into images in PNG, JPG, SVG, or PDF formats. Specify the node ID and scale to export precise design elements for use in documents or presentations.
Instructions
Export a node as an image from Figma
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Export format | |
| nodeId | Yes | The ID of the node to export | |
| scale | No | Export scale |
Implementation Reference
- src/talk_to_figma_mcp/server.ts:854-896 (registration)Registration of the 'export_node_as_image' tool including its input schema (nodeId, optional format and scale), description, and handler function. The handler sends the export command to the underlying Figma plugin via WebSocket (sendCommandToFigma), receives the base64 image data, and returns it as an MCP image content block.// Export Node as Image Tool server.tool( "export_node_as_image", "Export a node as an image from Figma", { nodeId: z.string().describe("The ID of the node to export"), format: z .enum(["PNG", "JPG", "SVG", "PDF"]) .optional() .describe("Export format"), scale: z.number().positive().optional().describe("Export scale"), }, async ({ nodeId, format, scale }: any) => { try { const result = await sendCommandToFigma("export_node_as_image", { nodeId, format: format || "PNG", scale: scale || 1, }); const typedResult = result as { imageData: string; mimeType: string }; return { content: [ { type: "image", data: typedResult.imageData, mimeType: typedResult.mimeType || "image/png", }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error exporting node as image: ${error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- Zod input schema for the 'export_node_as_image' tool defining parameters: nodeId (required string), format (optional enum PNG/JPG/SVG/PDF), scale (optional positive number).{ nodeId: z.string().describe("The ID of the node to export"), format: z .enum(["PNG", "JPG", "SVG", "PDF"]) .optional() .describe("Export format"), scale: z.number().positive().optional().describe("Export scale"),
- src/talk_to_figma_mcp/server.ts:866-895 (handler)Handler function that executes the tool: proxies parameters to Figma plugin command 'export_node_as_image', handles the response (imageData base64 and mimeType), returns MCP image content or error text.async ({ nodeId, format, scale }: any) => { try { const result = await sendCommandToFigma("export_node_as_image", { nodeId, format: format || "PNG", scale: scale || 1, }); const typedResult = result as { imageData: string; mimeType: string }; return { content: [ { type: "image", data: typedResult.imageData, mimeType: typedResult.mimeType || "image/png", }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error exporting node as image: ${error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- TypeScript type definition for CommandParams of 'export_node_as_image' matching the Zod schema, used in sendCommandToFigma.export_node_as_image: { nodeId: string; format?: "PNG" | "JPG" | "SVG" | "PDF"; scale?: number; };