export_multiple_images
Export multiple Figma design elements as images in one batch operation. Specify file ID, node IDs, format (PNG, JPG, SVG, PDF), and scale to download multiple images simultaneously.
Instructions
批量导出多个节点的图片
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fileId | Yes | Figma文件ID | |
| nodeIds | Yes | 节点ID列表 | |
| format | No | 图片格式,默认为png | png |
| scale | No | 图片缩放比例,默认为1 |
Implementation Reference
- src/index.ts:94-125 (registration)Registration of the 'export_multiple_images' tool in the ListTools response, including name, description, and input schema.{ name: 'export_multiple_images', description: '批量导出多个节点的图片', inputSchema: { type: 'object', properties: { fileId: { type: 'string', description: 'Figma文件ID', }, nodeIds: { type: 'array', items: { type: 'string' }, description: '节点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: ['fileId', 'nodeIds'], }, },
- src/index.ts:328-348 (handler)The primary MCP tool handler that destructures input arguments, invokes the image extractor for multiple images, and formats the JSON response.private async handleExportMultipleImages(args: any) { const { fileId, nodeIds, format = 'png', scale = 1 } = args; const options: ImageExportOptions = { format, scale }; const results = await this.imageExtractor.getMultipleImages(fileId, nodeIds, options); return { content: [ { type: 'text', text: JSON.stringify({ success: true, data: { images: results, totalCount: results.length, }, }, null, 2), }, ], }; }
- src/index.ts:203-204 (registration)Dispatcher case in the CallToolRequestSchema handler that routes to the specific tool handler.case 'export_multiple_images': return await this.handleExportMultipleImages(args);
- src/image-extractor.ts:69-109 (helper)Helper function implementing the batch image export logic: fetches node names, exports images via FigmaService, and constructs result objects.async getMultipleImages( fileId: string, nodeIds: string[], options: ImageExportOptions = {} ): Promise<ImageResult[]> { try { if (nodeIds.length === 0) { return []; } // 获取所有节点信息 const nodeInfoPromises = nodeIds.map(nodeId => this.figmaService.getNode(fileId, nodeId) ); const nodeInfos = await Promise.all(nodeInfoPromises); // 导出所有图片 const images = await this.figmaService.exportImage(fileId, nodeIds, options); const results: ImageResult[] = []; for (let i = 0; i < nodeIds.length; i++) { const nodeId = nodeIds[i]; const nodeInfo = nodeInfos[i]; const imageUrl = images[nodeId]; if (imageUrl && nodeInfo) { results.push({ url: imageUrl, nodeId, nodeName: nodeInfo.name, format: options.format || 'png', scale: options.scale || 1, }); } } return results; } catch (error) { throw new Error(`批量获取图片失败: ${error instanceof Error ? error.message : '未知错误'}`); } }
- src/image-extractor.ts:3-15 (schema)Type definitions for ImageExportOptions (input options) and ImageResult (output format) used by the tool.export interface ImageExportOptions { format?: 'jpg' | 'png' | 'svg' | 'pdf'; scale?: number; version?: string; } export interface ImageResult { url: string; nodeId: string; nodeName: string; format: string; scale: number; }