Skip to main content
Glama
yhc984

Talk to Figma MCP

by yhc984

export_node_as_image

Export Figma design elements as images in PNG, JPG, SVG, or PDF formats 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

  • Core handler function that fetches the Figma node by ID, exports it as image bytes using Figma's exportAsync API with specified format and scale, converts the bytes to a base64-encoded data URL, and returns the image data along with metadata.
    async function exportNodeAsImage(params) {
      const { nodeId, format = "PNG", scale = 1 } = params || {};
    
      if (!nodeId) {
        throw new Error("Missing nodeId parameter");
      }
    
      const node = await figma.getNodeByIdAsync(nodeId);
      if (!node) {
        throw new Error(`Node not found with ID: ${nodeId}`);
      }
    
      if (!("exportAsync" in node)) {
        throw new Error(`Node does not support exporting: ${nodeId}`);
      }
    
      try {
        const settings = {
          format: format,
          constraint: { type: "SCALE", value: scale },
        };
    
        const bytes = await node.exportAsync(settings);
    
        let mimeType;
        switch (format) {
          case "PNG":
            mimeType = "image/png";
            break;
          case "JPG":
            mimeType = "image/jpeg";
            break;
          case "SVG":
            mimeType = "image/svg+xml";
            break;
          case "PDF":
            mimeType = "application/pdf";
            break;
          default:
            mimeType = "application/octet-stream";
        }
    
        // Convert to base64
        const uint8Array = new Uint8Array(bytes);
        let binary = "";
        for (let i = 0; i < uint8Array.length; i++) {
          binary += String.fromCharCode(uint8Array[i]);
        }
        const base64 = btoa(binary);
        const imageData = `data:${mimeType};base64,${base64}`;
    
        return {
          nodeId,
          format,
          scale,
          mimeType,
          imageData,
        };
      } catch (error) {
        throw new Error(`Error exporting node as image: ${error.message}`);
      }
    }
  • Switch case registration/dispatch in the main command handler that routes 'export_node_as_image' calls to the exportNodeAsImage function.
    case "export_node_as_image":
      return await exportNodeAsImage(params);
  • MCP server tool registration including name, description, Zod input schema validation, and wrapper handler that proxies the call to the Figma plugin via sendCommandToFigma.
      "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)}`
              }
            ]
          };
        }
      }
    );
  • TypeScript union type defining allowed Figma commands, including 'export_node_as_image' for type safety in command sending.
    type FigmaCommand =
      | 'get_document_info'
      | 'get_selection'
      | 'get_node_info'
      | 'create_rectangle'
      | 'create_frame'
      | 'create_text'
      | 'set_fill_color'
      | 'set_stroke_color'
      | 'move_node'
      | 'resize_node'
      | 'delete_node'
      | 'get_styles'
      | 'get_local_components'
      | 'get_team_components'
      | 'create_component_instance'
      | 'export_node_as_image'
      | 'execute_code'
      | 'join'
      | 'set_corner_radius';
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. It states the action ('Export') but doesn't clarify critical details like whether this downloads a file, requires specific permissions, has rate limits, or what happens on failure (e.g., invalid nodeId). For a tool with potential side effects like file generation, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place by conveying essential information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 3 parameters with full schema coverage and no output schema, the description is minimally complete but lacks depth. It doesn't explain what the tool returns (e.g., a file path, binary data, or success status), which is critical for an export operation. For a tool with no annotations and potential behavioral complexity, it should provide more context about outcomes and constraints.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for nodeId, format, and scale in the input schema. The description adds no additional parameter semantics beyond what's already documented in the schema, such as explaining what 'scale' means in practical terms or format implications. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Export') and resource ('a node as an image from Figma'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential siblings like 'get_node_info' or 'scan_nodes_by_types' that might also involve nodes but don't export them, so it lacks explicit sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it doesn't specify if this is for downloading images versus viewing them in-app, or if other tools like 'get_node_info' should be used first to verify node existence. There's no mention of prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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