set_api_key
Configure your Figma API personal access token to enable AI assistants to interact with Figma files, comments, components, and team resources through the MCP server.
Instructions
Set your Figma API personal access token (will be saved to ~/.mcp-figma/config.json)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | Yes | Your Figma API personal access token |
Implementation Reference
- src/index.ts:467-473 (handler)Main handler for the 'set_api_key' tool. Validates input arguments and delegates to AuthManager.setApiKey to store the API key.case 'set_api_key': { const args = this.validateArgs<{ api_key: string }>(request.params.arguments, ['api_key']); this.authManager.setApiKey(args.api_key); return { content: [{ type: 'text', text: 'API key set successfully and saved to config file' }], }; }
- src/index.ts:91-104 (registration)Tool registration including name, description, and input schema for 'set_api_key'.{ name: 'set_api_key', description: 'Set your Figma API personal access token (will be saved to ~/.mcp-figma/config.json)', inputSchema: { type: 'object', properties: { api_key: { type: 'string', description: 'Your Figma API personal access token' } }, required: ['api_key'] }, },
- src/utils/auth.ts:20-30 (helper)AuthManager.setApiKey method: stores the API key in memory, persists it via ConfigManager, and sets token info.setApiKey(apiKey: string): void { this.apiKey = apiKey; // 保存到配置文件 this.configManager.setApiKey(apiKey); // 由于Figma个人访问令牌不会过期,我们设置一个很远的过期日期 this.tokenInfo = { accessToken: apiKey, expiresAt: Date.now() + (365 * 24 * 60 * 60 * 1000) // 1年后 }; }
- src/utils/config.ts:53-56 (helper)ConfigManager.setApiKey: updates the config object and saves it to ~/.mcp-figma/config.json file.public setApiKey(apiKey: string): void { this.config.apiKey = apiKey; this.saveConfig(); }
- src/index.ts:94-102 (schema)Input schema definition for the 'set_api_key' tool, specifying the required 'api_key' string parameter.inputSchema: { type: 'object', properties: { api_key: { type: 'string', description: 'Your Figma API personal access token' } }, required: ['api_key']