check_api_key
Verify whether a Figma API key is already configured in the MCP server to enable access to Figma files, comments, and team resources.
Instructions
Check if a Figma API key is already configured
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:475-488 (handler)The main handler for the 'check_api_key' tool. It attempts to retrieve the API key via authManager.getAccessToken(), masks it for display if successful, or returns a message indicating no key is configured.case 'check_api_key': { try { const token = await this.authManager.getAccessToken(); // 只显示部分API key作为安全措施 const maskedToken = token.substring(0, 5) + '...' + token.substring(token.length - 5); return { content: [{ type: 'text', text: `API key is configured (${maskedToken})` }], }; } catch (error) { return { content: [{ type: 'text', text: 'No API key is configured. Please use set_api_key to configure one.' }], }; } }
- src/index.ts:105-112 (schema)Tool schema definition for 'check_api_key', specifying name, description, and empty input schema (no arguments required).{ name: 'check_api_key', description: 'Check if a Figma API key is already configured', inputSchema: { type: 'object', properties: {}, required: [] },
- src/utils/auth.ts:32-54 (helper)Core logic for retrieving the configured Figma API key from AuthManager. Loads from config if needed and throws an error if no key is available.async getAccessToken(): Promise<string> { // 检查我们是否有有效的令牌 if (this.tokenInfo && Date.now() < this.tokenInfo.expiresAt) { return this.tokenInfo.accessToken; } // 如果没有设置API key,尝试从配置中重新加载 if (!this.apiKey) { const savedApiKey = this.configManager.getApiKey(); if (savedApiKey) { this.setApiKey(savedApiKey); return savedApiKey; } throw new McpError( ErrorCode.InvalidParams, 'No Figma API key provided. Use the set_api_key tool first.' ); } // 返回API key作为令牌 return this.apiKey; }
- src/utils/auth.ts:10-18 (helper)AuthManager constructor initializes by loading any saved API key from config.constructor() { this.configManager = new ConfigManager(); // 从配置中加载API key const savedApiKey = this.configManager.getApiKey(); if (savedApiKey) { this.setApiKey(savedApiKey); } }
- src/utils/config.ts:49-56 (helper)ConfigManager methods to get and set the API key, persisting to ~/.mcp-figma/config.json.public getApiKey(): string | undefined { return this.config.apiKey; } public setApiKey(apiKey: string): void { this.config.apiKey = apiKey; this.saveConfig(); }