check_credit_balance
View available credits for generating AI-powered music through natural language commands, enabling song creation with direct download links.
Instructions
Check your credit balance.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "check_credit_balance"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| type | Yes | ||
| _meta | No | ||
| annotations | No |
Implementation Reference
- musicmcp_ai_mcp/api.py:379-418 (handler)The handler function for the 'check_credit_balance' MCP tool. It is decorated with @mcp.tool, making this both the implementation and registration point. The function checks the user's credit balance by querying the MusicMCP.AI API's /credit endpoint and returns a TextContent with the balance or error message.
@mcp.tool(description="Check your credit balance.") async def check_credit_balance() -> TextContent: """Check credit balance""" try: if not api_key: raise Exception("Cannot find API key. Please set MUSICMCP_API_KEY environment variable.") url = f"{api_url}/credit" headers = {'api-key': api_key} async with httpx.AsyncClient(timeout=httpx.Timeout(30.0)) as client: response = await client.get(url, headers=headers) response.raise_for_status() result = response.json() # API response format: {success, message, data} if not result or not result.get("success"): error_msg = result.get("message", "Unknown error") return TextContent(type="text", text=f"❌ Credit balance check failed: {error_msg}") data = result.get("data", {}) if data.get("valid"): has_credits = data.get("hasCredits", False) credits = data.get("credits", 0) if has_credits: return TextContent( type="text", text=f"✅ API key is valid! You have {credits} credits remaining." ) else: return TextContent( type="text", text="⚠️ API key is valid but you have insufficient credits. Please recharge." ) else: return TextContent(type="text", text="❌ API key is invalid.") except Exception as e: return TextContent(type="text", text=f"❌ Failed to check credit balance: {str(e)}") - musicmcp_ai_mcp/api.py:379-379 (registration)The @mcp.tool decorator registers the 'check_credit_balance' tool with the MCP server, providing a description for the tool schema.
@mcp.tool(description="Check your credit balance.")