get_styles
Extract styles from a Figma file using a memory-efficient MCP server, enabling handling of large files with chunking and pagination for optimized performance.
Instructions
Get styles from a Figma file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_key | Yes | Figma file key |
Implementation Reference
- src/index.ts:206-219 (registration)Registration of the 'get_styles' tool in the ListTools handler, including name, description, and input schema definition.{ name: 'get_styles', description: 'Get styles from a Figma file', inputSchema: { type: 'object', properties: { file_key: { type: 'string', description: 'Figma file key' } }, required: ['file_key'] } },
- src/index.ts:398-410 (handler)MCP tool handler for 'get_styles': validates file_key argument, calls figmaClient.getStyles(), and returns JSON response.case 'get_styles': { 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 styles', { fileKey: args.file_key, }); const data = await this.figmaClient.getStyles(args.file_key); return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }], }; }
- src/client.ts:310-325 (helper)Core implementation of getStyles in ChunkedFigmaClient: makes API call to Figma /files/{fileKey}/styles endpoint and returns the data.async getStyles(fileKey: string) { try { console.debug('[MCP Debug] Getting styles for file:', fileKey); const response = await this.client.get(`/files/${fileKey}/styles`); if (this.nodeProcessor.hasReachedLimit()) { console.debug('[MCP Debug] Memory limit reached while processing styles'); throw new Error('Memory limit exceeded while processing styles'); } return response.data; } catch (error) { console.error('[MCP Error] Failed to get styles:', error); throw error; } }