Skip to main content
Glama
mvacaporale

Claude Usage MCP Server

by mvacaporale

claude_login

Authenticate with Claude by opening a browser window when usage data retrieval fails due to authentication issues.

Instructions

Open a browser window to authenticate with Claude. Use this if get_claude_usage fails due to authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The `perform_login` function handles the authentication logic by opening a headed browser for user interaction.
    async def perform_login(context: BrowserContext) -> dict[str, Any]:
        """Open a browser window for user to authenticate."""
        # Need to use headed browser for login
        global _browser, _context
    
        playwright = await async_playwright().start()
    
        # Use persistent context with user data dir - much harder for Cloudflare to detect
        # This persists cookies, localStorage, and browser fingerprint
        USER_DATA_DIR.mkdir(exist_ok=True)
    
        headed_context = await playwright.chromium.launch_persistent_context(
            user_data_dir=str(USER_DATA_DIR),
            headless=False,
            channel="chrome",  # Use real Chrome if available
            args=[
                "--disable-blink-features=AutomationControlled",  # Hide automation
            ]
        )
    
        page = headed_context.pages[0] if headed_context.pages else await headed_context.new_page()
    
        try:
            # Navigate to Claude - don't wait for full load
            await page.goto("https://claude.ai/login", wait_until="commit", timeout=60000)
    
            # Wait for user to complete Cloudflare verification and login
            print("Please complete the Cloudflare verification and log in to Claude...")
            print("The browser window will stay open - take your time.")
    
            # Wait up to 5 minutes for login to complete (user needs time for Cloudflare + login)
            try:
                # Wait for navigation away from login page to main Claude interface
                # Check for multiple possible URLs after login
                await page.wait_for_url(
                    lambda url: "claude.ai" in url and "login" not in url and ("new" in url or "chat" in url or "settings" in url),
                    timeout=300000
                )
                await page.wait_for_timeout(3000)  # Wait for session to stabilize
    
                # Save the auth state
                await headed_context.storage_state(path=str(AUTH_STATE_PATH))
    
                # Clear global context so it gets recreated with the new browser data
                if _context:
                    await _context.close()
                    _context = None
                if _browser:
                    await _browser.close()
                    _browser = None
    
                return {"success": True, "message": "Login successful! Auth state saved."}
            except Exception as e:
                return {"success": False, "error": f"Login timeout or error: {e}"}
        finally:
            await headed_context.close()
  • server.py:201-209 (registration)
    Registration of the 'claude_login' tool in the `list_tools` function.
    Tool(
        name="claude_login",
        description="Open a browser window to authenticate with Claude. Use this if get_claude_usage fails due to authentication.",
        inputSchema={
            "type": "object",
            "properties": {},
            "required": []
        }
    ),
  • The tool dispatch logic in `call_tool` that invokes `perform_login` for the 'claude_login' tool.
    elif name == "claude_login":
        context = await get_browser_context()
        result = await perform_login(context)
    
        return [TextContent(
            type="text",
            text=json.dumps(result, indent=2)
        )]
Behavior3/5

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

No annotations provided, so description carries full burden. It adds critical behavioral context that this opens a browser window (interactive UI) rather than returning a URL or token silently. However, it omits completion behavior (blocking vs async), success indicators, or failure handling.

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 well-structured sentences: first states purpose, second states usage condition. Front-loaded with action, zero redundancy, appropriate length for tool complexity.

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

Completeness4/5

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

For a simple 0-parameter auth utility without annotations or output schema, the description covers essential purpose and usage triggers. Could be improved by mentioning success/failure signals or timeout behavior, but adequately complete for selection purposes.

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?

Input schema has zero parameters. Per scoring rules, 0 params = baseline 4. The description appropriately contains no parameter discussion since none exist.

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?

Clear specific verb ('Open') and resource ('browser window to authenticate with Claude'). The description effectively distinguishes this from sibling get_claude_usage by positioning it as the auth recovery mechanism.

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

Usage Guidelines5/5

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

Excellent explicit guidance: 'Use this if get_claude_usage fails due to authentication.' States the exact trigger condition and identifies the sibling alternative, creating a clear decision tree for the agent.

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