validate_api_key
Verify MMAudio API key validity and check account credits/status to ensure access to video-to-audio and text-to-audio generation services.
Instructions
Validate MMAudio API key and check account credits/status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | No | MMAudio API key to validate (optional, uses configured key if not provided) |
Implementation Reference
- server/index.js:430-505 (handler)The handler function that executes the validate_api_key tool. It takes an optional api_key from args or uses the configured one, makes a GET request to /api/credits to validate it, and returns a JSON response with validation status and credits.async handleValidateApiKey(args) { const apiKey = args.api_key || this.config?.apiKey; if (!apiKey) { throw new McpError(ErrorCode.InvalidRequest, 'No API key provided'); } try { console.error(`[MMAudio] Validating API key...`); // Try to fetch credits/usage endpoint to validate the key const response = await fetch(`${this.config?.baseUrl || 'https://mmaudio.net'}/api/credits`, { method: 'GET', headers: { 'Authorization': `Bearer ${apiKey}`, 'User-Agent': 'MMAudio-MCP/1.0.0', }, timeout: 10000, }); if (response.status === 401) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, valid: false, message: 'Invalid API key', error: 'Authentication failed' }, null, 2), }, ], }; } if (!response.ok) { throw new Error(`HTTP ${response.status}: ${await response.text()}`); } const data = await response.json(); console.error(`[MMAudio] API key validation successful`); return { content: [ { type: 'text', text: JSON.stringify({ success: true, valid: true, message: 'API key is valid', credits: data.credits || 'Unknown', account_status: 'Active' }, null, 2), }, ], }; } catch (error) { console.error(`[MMAudio] API key validation failed:`, error); return { content: [ { type: 'text', text: JSON.stringify({ success: false, valid: false, message: 'Failed to validate API key', error: error.message }, null, 2), }, ], }; } }
- server/index.js:219-232 (registration)Tool registration in the listTools handler, defining the name, description, and input schema for validate_api_key.{ name: 'validate_api_key', description: 'Validate MMAudio API key and check account credits/status', inputSchema: { type: 'object', properties: { api_key: { type: 'string', description: 'MMAudio API key to validate (optional, uses configured key if not provided)', }, }, required: [], }, },
- server/index.js:247-248 (registration)Dispatcher case in the CallToolRequestSchema handler that routes calls to validate_api_key to the handleValidateApiKey method.case 'validate_api_key': return await this.handleValidateApiKey(args);