Skip to main content
Glama

extract_node_elements

Extract all design elements (images, vectors, components) from Figma nodes to analyze or export assets from your designs.

Instructions

提取节点中的所有设计元素(图片、矢量、组件)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesFigma文件URL,必须包含node-id参数
includeDetailsNo是否包含详细信息,默认为false

Implementation Reference

  • Tool schema definition for 'extract_node_elements', including name, description, and input schema.
    {
      name: 'extract_node_elements',
      description: '提取节点中的所有设计元素(图片、矢量、组件)',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'Figma文件URL,必须包含node-id参数',
          },
          includeDetails: {
            type: 'boolean',
            description: '是否包含详细信息,默认为false',
            default: false,
          },
        },
        required: ['url'],
      },
    },
  • src/index.ts:215-216 (registration)
    Tool dispatch/registration in the switch statement for CallToolRequest.
    case 'extract_node_elements':
      return await this.handleExtractNodeElements(args);
  • Primary handler function for the 'extract_node_elements' tool, which delegates to FigmaElementExtractor and formats the response.
    private async handleExtractNodeElements(args: any) {
      const { url, includeDetails = false } = args;
    
      try {
        console.error(`开始提取节点设计元素: ${url}`);
        
        const elements = await this.elementExtractor.getElementsFromUrl(url);
        
        console.error(`成功提取设计元素: ${elements.totalElements} 个`);
        
        const responseData: any = {
          success: true,
          data: {
            nodeId: elements.nodeId,
            nodeName: elements.nodeName,
            summary: {
              totalElements: elements.totalElements,
              images: elements.images.length,
              vectors: elements.vectors.length,
              components: elements.components.length,
            },
            elements: includeDetails ? {
              images: elements.images,
              vectors: elements.vectors,
              components: elements.components,
            } : undefined,
          },
        };
    
        // 如果不包含详细信息,提供可读的摘要
        if (!includeDetails) {
          responseData.data.textSummary = this.elementExtractor.generateElementsSummary(elements);
        }
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(responseData, 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参数',
                    '确认对该文件和节点有访问权限',
                    '验证节点是否存在且包含设计元素',
                  ],
                  tip: '使用includeDetails=true获取详细的元素信息'
                }
              }, null, 2),
            },
          ],
        };
      }
    }
  • Handler method in FigmaElementExtractor that parses the Figma URL and invokes the core element extraction logic.
    async getElementsFromUrl(figmaUrl: string): Promise<NodeElements> {
      try {
        const urlInfo = this.figmaService.parseUrl(figmaUrl);
        const { fileId, nodeId } = urlInfo;
    
        if (!nodeId) {
          throw new Error('URL中缺少节点ID,无法提取设计元素。请确保URL包含node-id参数');
        }
    
        return await this.getAllNodeElements(fileId, nodeId);
      } catch (error) {
        throw new Error(`从URL获取设计元素失败: ${error instanceof Error ? error.message : '未知错误'}`);
      }
    }
  • Core helper function that extracts images, vectors, and components from a Figma node using parallel calls and tree traversal.
    async getAllNodeElements(fileId: string, nodeId: string): Promise<NodeElements> {
      try {
        const node = await this.figmaService.getNodeDetails(fileId, nodeId);
        if (!node) {
          throw new Error(`节点 ${nodeId} 不存在`);
        }
    
        const [images, vectors] = await Promise.all([
          this.getNodeImages(fileId, nodeId),
          this.extractVectorElements(fileId, nodeId)
        ]);
    
        // 收集组件节点
        const components: any[] = [];
        this.figmaService.traverseNodeTree(node, (currentNode) => {
          if (currentNode.type === 'COMPONENT' || currentNode.type === 'INSTANCE') {
            components.push({
              id: currentNode.id,
              name: currentNode.name,
              type: currentNode.type,
              componentId: currentNode.componentId || undefined
            });
          }
        });
    
        return {
          nodeId,
          nodeName: node.name || 'Unnamed Node',
          images,
          vectors,
          components,
          totalElements: images.length + vectors.length + components.length
        };
      } catch (error) {
        throw new Error(`获取节点元素失败: ${error instanceof Error ? error.message : '未知错误'}`);
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states what the tool does (extract elements) but lacks behavioral details such as permissions required, rate limits, output format, or whether it's a read-only operation. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 unnecessary words. It's front-loaded with the core action and resource, making it easy to parse. Every part of the sentence contributes to understanding the purpose.

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 no annotations and no output schema, the description is incomplete for a tool with 2 parameters. It explains what the tool does but lacks critical context like behavioral traits, output details, or usage scenarios. For a tool in this context, more information is needed to fully guide an AI agent.

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%, so the schema fully documents both parameters ('url' and 'includeDetails'). The description adds no additional meaning beyond what's in the schema, such as examples or context for parameter usage. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.

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 ('提取' meaning 'extract') and the target ('节点中的所有设计元素' meaning 'all design elements in a node'), specifying the resource types (images, vectors, components). It distinguishes from siblings like 'get_node_images' (only images) and 'get_node_svg' (only SVG), but doesn't explicitly name these alternatives. This makes the purpose specific but not fully differentiated.

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?

No guidance is provided on when to use this tool versus alternatives like 'get_node_images' or 'get_node_svg'. The description implies it extracts all element types, but doesn't state when to prefer this comprehensive extraction over more specific tools. There are no exclusions or prerequisites mentioned.

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