Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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.' }],
        };
      }
    }
  • 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: []
      },
  • 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;
    }
  • 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);
      }
    }
  • 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();
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/smithery-ai/mcp-figma'

If you have feedback or need assistance with the MCP directory API, please join our Discord server