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"),

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