Skip to main content
Glama

download-svg-assets

Download specific SVG assets from a Figma file by node ID. Specify file key, node details, and local path for saving. Handles PNG scaling and customizable SVG export options.

Instructions

根据图像或图标节点的ID,仅下载Figma文件中使用的SVG资源

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileKeyYesThe key of the Figma file containing the node
localPathYesThe absolute path to the directory where images are stored in the project. If the directory does not exist, it will be created. The format of this path should respect the directory format of the operating system you are running on. Don't use any special character escaping in the path name either.
nodesYesThe nodes to fetch as images
pngScaleNoExport scale for PNG images. Optional, defaults to 2 if not specified. Affects PNG images only.
svgOptionsNoOptions for SVG export

Implementation Reference

  • Registration of the 'download-svg-assets' MCP tool, including input schema and execute handler that delegates to figmaToolsCore.downloadFigmaSVGAssets
    private dowdloadSVGAssets(): void {
      this.server.addTool({
        name: 'download-svg-assets',
        description: '根据图像或图标节点的ID,仅下载Figma文件中使用的SVG资源',
        parameters: z.object({
          fileKey: z.string().describe("The key of the Figma file containing the node"),
          nodes: z
            .object({
              nodeId: z
                .string()
                .describe("The ID of the Figma image node to fetch, formatted as 1234:5678"),
              imageRef: z
                .string()
                .optional()
                .describe(
                  "If a node has an imageRef fill, you must include this variable. Leave blank when downloading Vector SVG images.",
                ),
              fileName: z.string().describe("The local name for saving the fetched file"),
            })
            .array()
            .describe("The nodes to fetch as images"),
          pngScale: z
            .number()
            .positive()
            .optional()
            .default(2)
            .describe(
              "Export scale for PNG images. Optional, defaults to 2 if not specified. Affects PNG images only.",
            ),
          localPath: z
            .string()
            .describe(
              "The absolute path to the directory where images are stored in the project. If the directory does not exist, it will be created. The format of this path should respect the directory format of the operating system you are running on. Don't use any special character escaping in the path name either.",
            ),
          svgOptions: z
            .object({
              outlineText: z
                .boolean()
                .optional()
                .default(true)
                .describe("Whether to outline text in SVG exports. Default is true."),
              includeId: z
                .boolean()
                .optional()
                .default(false)
                .describe("Whether to include IDs in SVG exports. Default is false."),
              simplifyStroke: z
                .boolean()
                .optional()
                .default(true)
                .describe("Whether to simplify strokes in SVG exports. Default is true."),
            })
            .optional()
            .default({})
            .describe("Options for SVG export"),
        }),
        execute: async ({ fileKey, nodes, localPath, pngScale, svgOptions }, { session }) => {
          try {
            const downloads = await this.figmaToolsCore.downloadFigmaSVGAssets({
              fileKey,
              nodes,
              localPath,
              pngScale,
              svgOptions,
            })
    
            // If any download fails, return false
            const saveSuccess = !downloads.find(success => !success)
            const assetsPrompt = saveSuccess
              ? `Success, ${downloads.length} images downloaded: ${downloads.join(', ')}`
              : 'Failed'
    
            const prompt: string = `
              <xml>
                <SVG-URL>${assetsPrompt}</SVG-URL>
              </xml>
            `
    
            return {
              content: [
                {
                  type: 'text',
                  text: prompt
                },
              ],
            }
          } catch (error) {
            Logger.error(`Error downloading images from file ${fileKey}:`, error)
            return {
              isError: true,
              content: [{ type: 'text', text: `Error downloading images: ${error}` }],
            }
          }
        },
      })
    }
  • Core handler logic for downloading SVG assets from Figma, called by the tool's execute function. Filters nodes without imageRef and calls figmaService.getSVG
    public async downloadFigmaSVGAssets({
      fileKey,
      nodes,
      localPath
    }: DownloadFigmaImagesParams) {
      const figmaService = this.figmaService
    
      const renderRequests = nodes
        .filter(({ imageRef }) => !imageRef)
        .map(({ nodeId, fileName }) => ({
          nodeId,
          fileName,
          fileType: fileName.endsWith('.svg') ? ('svg' as const) : ('png' as const),
        }))
    
      console.log('renderRequests', nodes)
    
      const renderDownloads = figmaService.getSVG(fileKey, renderRequests, localPath)
    
      const downloads = await Promise.all([renderDownloads]).then(([r]) => [
        ...r,
      ])
    
      return downloads
    }
  • Zod schema defining input parameters for the 'download-svg-assets' tool
    parameters: z.object({
      fileKey: z.string().describe("The key of the Figma file containing the node"),
      nodes: z
        .object({
          nodeId: z
            .string()
            .describe("The ID of the Figma image node to fetch, formatted as 1234:5678"),
          imageRef: z
            .string()
            .optional()
            .describe(
              "If a node has an imageRef fill, you must include this variable. Leave blank when downloading Vector SVG images.",
            ),
          fileName: z.string().describe("The local name for saving the fetched file"),
        })
        .array()
        .describe("The nodes to fetch as images"),
      pngScale: z
        .number()
        .positive()
        .optional()
        .default(2)
        .describe(
          "Export scale for PNG images. Optional, defaults to 2 if not specified. Affects PNG images only.",
        ),
      localPath: z
        .string()
        .describe(
          "The absolute path to the directory where images are stored in the project. If the directory does not exist, it will be created. The format of this path should respect the directory format of the operating system you are running on. Don't use any special character escaping in the path name either.",
        ),
      svgOptions: z
        .object({
          outlineText: z
            .boolean()
            .optional()
            .default(true)
            .describe("Whether to outline text in SVG exports. Default is true."),
          includeId: z
            .boolean()
            .optional()
            .default(false)
            .describe("Whether to include IDs in SVG exports. Default is false."),
          simplifyStroke: z
            .boolean()
            .optional()
            .default(true)
            .describe("Whether to simplify strokes in SVG exports. Default is true."),
        })
        .optional()
        .default({})
        .describe("Options for SVG export"),
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions downloading SVG resources but fails to describe key behaviors: it doesn't specify that the tool creates directories if needed (hinted in schema), handles both SVG and PNG exports (per schema), or what happens on failure. The description is minimal and lacks operational context needed for safe invocation.

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

Conciseness4/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded with the core action and resource. However, it could be slightly more comprehensive given the tool's complexity, but it avoids waste and is structurally sound.

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 tool's complexity (5 parameters, nested objects, no output schema, and no annotations), the description is inadequate. It doesn't cover the dual SVG/PNG functionality, directory creation behavior, export options, or what the tool returns. For a tool with this level of detail in the schema, the description should provide more operational context to compensate for missing annotations and output schema.

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 already documents all parameters thoroughly. The description adds no parameter-specific information beyond implying node IDs are used. It doesn't explain parameter relationships or provide additional context beyond what's in the schema, meeting the baseline 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 clearly states the action ('download') and resource ('SVG assets from Figma files'), specifying it's based on node IDs. It distinguishes from siblings like 'Download-Figma-Images' by focusing on SVG resources only. However, it doesn't explicitly mention PNG handling which appears in the schema, making it slightly less specific than a perfect 5.

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 'Download-Figma-Images' or 'extract-svg-assets'. It states what the tool does but offers no context about appropriate use cases, prerequisites, or comparisons with sibling tools, leaving the agent to infer usage from the tool name 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

Related 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/Panzer-Jack/feuse-mcp'

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