Skip to main content
Glama
arinspunk

Claude Talk to Figma MCP

by arinspunk

export_node_as_image

Export Figma design elements as PNG, JPG, SVG, or PDF images by specifying node ID and scale for design documentation and asset creation.

Instructions

Export a node as an image from Figma

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodeIdYesThe ID of the node to export
formatNoExport format
scaleNoExport scale

Implementation Reference

  • The main handler function for the 'export_node_as_image' MCP tool. It forwards the parameters to the Figma plugin via sendCommandToFigma and returns the resulting image data in MCP format.
    async ({ nodeId, format, scale }) => {
      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 schema for input validation of the 'export_node_as_image' tool parameters.
    {
      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"),
    },
  • Registration of the 'export_node_as_image' tool with the MCP server using server.tool(), specifying name, description, input schema, and handler.
    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 }) => {
        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)}`,
              },
            ],
          };
        }
      }
    );
  • The 'export_node_as_image' command is included in the FigmaCommand type union used for TypeScript typing of Figma plugin commands.
    | "export_node_as_image"

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/arinspunk/claude-talk-to-figma-mcp'

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