Skip to main content
Glama
mmaudio

MMAudio MCP

Official
by mmaudio

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
NameRequiredDescriptionDefault
api_keyNoMMAudio API key to validate (optional, uses configured key if not provided)

Implementation Reference

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

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

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/mmaudio/mmaudio-mcp'

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