Skip to main content
Glama
mvacaporale

Claude Usage MCP Server

by mvacaporale

get_claude_usage

Fetch Claude.ai usage data to monitor daily token consumption and track session limits through automated dashboard retrieval.

Instructions

Fetch Claude usage data from the dashboard. Returns daily token usage information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler implementation for the `get_claude_usage` tool, which fetches the browser context, checks for authentication, and triggers the scraping of the usage data.
    if name == "get_claude_usage":
        context = await get_browser_context()
    
        # Check if authenticated
        if not await check_authenticated(context):
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": False,
                    "error": "Not authenticated. Please run claude_login first."
                }, indent=2)
            )]
    
        result = await scrape_usage_data(context)
        await save_auth_state()
    
        return [TextContent(
            type="text",
            text=json.dumps(result, indent=2)
        )]
  • server.py:192-200 (registration)
    The definition of the `get_claude_usage` tool, registered within the `list_tools` function.
    Tool(
        name="get_claude_usage",
        description="Fetch Claude usage data from the dashboard. Returns daily token usage information.",
        inputSchema={
            "type": "object",
            "properties": {},
            "required": []
        }
    ),
  • The helper function `scrape_usage_data` that performs the actual web scraping on the Claude settings page.
    async def scrape_usage_data(context: BrowserContext) -> dict[str, Any]:
        """Scrape usage data from the Claude dashboard."""
        page = await context.new_page()
        try:
            await page.goto(USAGE_URL, wait_until="domcontentloaded", timeout=60000)
    
            # Wait for the page to fully load
            await page.wait_for_timeout(2000)
    
            # Extract usage data from the page
            # The structure may vary - we'll try to get what's available
            usage_data = await page.evaluate("""
                () => {
                    const data = {
                        raw_text: document.body.innerText,
                        title: document.title,
                        url: window.location.href
                    };
    
                    // Try to find usage-related elements
                    const usageElements = document.querySelectorAll('[class*="usage"], [class*="Usage"]');
                    data.usage_elements = Array.from(usageElements).map(el => el.innerText);
    
                    // Try to find any tables or data displays
                    const tables = document.querySelectorAll('table');
                    data.tables = Array.from(tables).map(table => table.innerText);
    
                    // Try to find any chart or graph data
                    const charts = document.querySelectorAll('[class*="chart"], [class*="Chart"], svg');
                    data.chart_count = charts.length;
    
                    return data;
                }
            """)
    
            return {
                "success": True,
                "data": usage_data
            }
        except Exception as e:
            return {
                "success": False,
                "error": str(e)
            }
        finally:
            await page.close()
Behavior3/5

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

No annotations provided, so description carries full burden. It successfully discloses that the tool returns 'daily token usage information,' which is crucial given the lack of output schema. However, it fails to mention authentication requirements, rate limiting, supported date ranges, or whether the data is cached versus live.

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?

Two efficient sentences: first establishes the action and target, second describes the return value. No redundancy or filler content. Information is front-loaded with the verb 'Fetch.'

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?

While the description explains return values (necessary without output schema), it omits critical context given the sibling tools: authentication prerequisites and token/date range limitations. For a dashboard-accessing tool with auth siblings, mentioning the required auth state would make this 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?

Zero parameters present, establishing a baseline of 4 per scoring rules. The description does not need to compensate for missing parameter documentation since the input schema requires none.

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

Purpose5/5

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

Uses specific verb 'Fetch' with clear resource 'Claude usage data' and source 'dashboard.' The mention of 'daily token usage' precisely scopes the returned data. Clearly distinguishes from auth-related siblings (check_claude_auth, claude_login) by focusing on data retrieval rather than authentication.

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?

Provides no explicit guidance on when to use versus alternatives, prerequisites, or sequencing. Given the authentication-related siblings, the description should state that authentication is required first or recommend using check_claude_auth beforehand, but it remains silent on workflow.

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

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/mvacaporale/claude-usage-mcp'

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