get_components
Extract components from a Figma file using an API tool designed for handling large files efficiently with memory-aware chunking and pagination.
Instructions
Get components from a Figma file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_key | Yes | Figma file key |
Implementation Reference
- src/client.ts:293-308 (handler)The core handler function in ChunkedFigmaClient class that executes the tool logic: fetches components from Figma API `/files/${fileKey}/components`, checks memory limit via nodeProcessor, returns the response data.async getComponents(fileKey: string) { try { console.debug('[MCP Debug] Getting components for file:', fileKey); const response = await this.client.get(`/files/${fileKey}/components`); if (this.nodeProcessor.hasReachedLimit()) { console.debug('[MCP Debug] Memory limit reached while processing components'); throw new Error('Memory limit exceeded while processing components'); } return response.data; } catch (error) { console.error('[MCP Error] Failed to get components:', error); throw error; } }
- src/index.ts:192-205 (registration)Registers the 'get_components' tool in the MCP server's ListTools response, including name, description, and input schema requiring 'file_key'.{ name: 'get_components', description: 'Get components from a Figma file', inputSchema: { type: 'object', properties: { file_key: { type: 'string', description: 'Figma file key' } }, required: ['file_key'] } },
- src/index.ts:384-396 (handler)The MCP server request handler for CallToolRequestSchema that dispatches 'get_components': validates input, calls figmaClient.getComponents, formats response as JSON text content.case 'get_components': { const args = request.params.arguments as unknown as FileKeyArgs; if (!args.file_key) { throw new McpError(ErrorCode.InvalidParams, 'file_key is required'); } console.debug('[MCP Debug] Fetching components', { fileKey: args.file_key, }); const data = await this.figmaClient.getComponents(args.file_key); return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }], }; }
- src/index.ts:195-204 (schema)Input schema definition for the 'get_components' tool, specifying object with required 'file_key' string property.inputSchema: { type: 'object', properties: { file_key: { type: 'string', description: 'Figma file key' } }, required: ['file_key'] }