Skip to main content
Glama

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
typeYes
_metaNo
annotationsNo

Implementation Reference

  • 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)}")
  • 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.")

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description only implies a read-only operation but provides no additional behavioral details such as side effects, rate limits, or authentication requirements. With no annotations available, the description carries the full burden and is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single short sentence with no unnecessary words. It is front-loaded and efficiently conveys the core action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is adequate for a zero-parameter tool, but it does not clarify what 'credit balance' refers to. Although an output schema exists, the description could provide more context about the credit system. It is minimally complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are no parameters, so the baseline is 4. The description adds no extra meaning beyond the schema, but that is acceptable given the schema coverage is 100%.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's action (check) and resource (credit balance), and it is distinct from sibling tools like check_api_health or generate_custom_song. However, it lacks specificity about which credit system is being checked.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. While sibling tools are different in functionality, the description does not mention any context or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.