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)
        )]

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