Skip to main content
Glama

get_figma_image

Extract images from Figma designs by providing a file URL with node ID. Choose PNG, JPG, SVG, or PDF format and adjust scale to export design elements for development or documentation.

Instructions

根据Figma URL获取节点的图片

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesFigma文件URL,必须包含node-id参数
formatNo图片格式,默认为pngpng
scaleNo图片缩放比例,默认为1

Implementation Reference

  • The primary handler function for executing the 'get_figma_image' tool. It extracts parameters from args, calls FigmaImageExtractor to get the image, and returns structured JSON response with success/error handling.
    private async handleGetImage(args: any) {
      const { url, format = 'png', scale = 1 } = args;
    
      try {
        console.error(`开始处理图片请求: ${url}`);
        
        const options: ImageExportOptions = { format, scale };
        const results = await this.imageExtractor.getImageFromUrl(url, options);
    
        if (results.length === 0) {
          throw new Error('未找到可导出的图片');
        }
    
        const result = results[0];
        console.error(`图片导出成功: ${result.nodeName} (${result.nodeId})`);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: true,
                data: {
                  imageUrl: result.url,
                  nodeId: result.nodeId,
                  nodeName: result.nodeName,
                  format: result.format,
                  scale: result.scale,
                },
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : '未知错误';
        console.error(`图片获取失败: ${errorMessage}`);
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: false,
                error: errorMessage,
                troubleshooting: {
                  commonIssues: [
                    '检查Figma URL是否包含node-id参数',
                    '确认Figma token是否有效',
                    '验证对该文件是否有访问权限',
                    '检查节点是否存在且可见'
                  ],
                  urlFormat: 'https://www.figma.com/design/{fileId}/{name}?node-id={nodeId}'
                }
              }, null, 2),
            },
          ],
        };
      }
    }
  • src/index.ts:48-74 (registration)
    Registration of the 'get_figma_image' tool in the ListToolsRequestSchema handler, defining name, description, and input schema.
    {
      name: 'get_figma_image',
      description: '根据Figma URL获取节点的图片',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'Figma文件URL,必须包含node-id参数',
          },
          format: {
            type: 'string',
            enum: ['png', 'jpg', 'svg', 'pdf'],
            description: '图片格式,默认为png',
            default: 'png',
          },
          scale: {
            type: 'number',
            description: '图片缩放比例,默认为1',
            default: 1,
            minimum: 0.01,
            maximum: 4,
          },
        },
        required: ['url'],
      },
    },
  • Helper method in FigmaImageExtractor that parses the Figma URL, fetches node info, exports the image via FigmaService, and returns ImageResult.
    async getImageFromUrl(
      figmaUrl: string, 
      options: ImageExportOptions = {}
    ): Promise<ImageResult[]> {
      try {
        const urlInfo = this.figmaService.parseUrl(figmaUrl);
        const { fileId, nodeId } = urlInfo;
    
        if (!nodeId) {
          throw new Error('URL中缺少节点ID,无法导出图片。请确保URL包含node-id参数');
        }
    
        // 获取节点信息以获取名称
        const nodeInfo = await this.figmaService.getNode(fileId, nodeId);
        if (!nodeInfo) {
          throw new Error(`未找到节点: ${nodeId}`);
        }
    
        // 导出图片
        const images = await this.figmaService.exportImage(
          fileId, 
          [nodeId], 
          options
        );
    
        const imageUrl = images[nodeId];
        if (!imageUrl) {
          throw new Error(`无法生成节点 ${nodeId} 的图片URL`);
        }
    
        return [{
          url: imageUrl,
          nodeId,
          nodeName: nodeInfo.name,
          format: options.format || 'png',
          scale: options.scale || 1,
        }];
    
      } catch (error) {
        throw new Error(`获取图片失败: ${error instanceof Error ? error.message : '未知错误'}`);
      }
    }
  • Type definition for image export options used in the tool parameters and API calls.
    export interface ImageExportOptions {
      format?: 'jpg' | 'png' | 'svg' | 'pdf';
      scale?: number;
      version?: string;
    }
  • Core helper in FigmaService that handles image export via Figma API, with batching for multiple nodes and error handling.
    async exportImage(fileId: string, nodeIds: string[], options: {
      format?: 'jpg' | 'png' | 'svg' | 'pdf';
      scale?: number;
      version?: string;
    } = {}): Promise<Record<string, string>> {
      try {
        // 分批处理,避免URL过长
        const batchSize = 90; // 保守分批
        const allImages: Record<string, string> = {};
    
        for (let i = 0; i < nodeIds.length; i += batchSize) {
          const batch = nodeIds.slice(i, i + batchSize);
          const batchImages = await this.exportImageBatch(fileId, batch, options);
          Object.assign(allImages, batchImages);
        }
    
        return allImages;
      } catch (error) {
        if (axios.isAxiosError(error)) {
          const status = error.response?.status;
          const message = error.response?.data?.message || error.message;
          throw new Error(`导出图片失败 (${status}): ${message}`);
        }
        throw new Error(`导出图片失败: ${error instanceof Error ? error.message : '未知错误'}`);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions fetching images based on a Figma URL but doesn't cover critical aspects like authentication requirements, rate limits, error handling, or what the output looks like (e.g., image data, URLs, or metadata). For a tool that likely involves external API calls, 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 in Chinese that directly states the tool's function without any unnecessary words. It's front-loaded and appropriately sized for its purpose, making it easy to parse quickly.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain the return values (e.g., image bytes, download links, or error formats), which is crucial for a tool that fetches images. For a tool with three parameters and likely external dependencies, more context is needed to ensure proper usage.

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?

The input schema has 100% description coverage, clearly documenting all three parameters (url, format, scale) with details like required status, defaults, and constraints. The description doesn't add any meaningful semantics beyond what the schema provides, so it meets the baseline score of 3 for high schema coverage.

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 '根据Figma URL获取节点的图片' clearly states the action (获取/获取) and resource (节点的图片), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_node_images' or 'get_node_svg', which appear to have similar functions, so it doesn't reach the highest score.

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 like 'get_node_images' or 'get_node_svg'. It lacks context about specific use cases, prerequisites, or exclusions, leaving the agent to infer usage from the tool name and parameters alone.

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/Echoxiawan/figma-mcp-full-server'

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