"""How much of agent-browser's MCP tool list is options that every tool repeats (Claude tokens, messages.count_tokens)."""
import asyncio, copy, os, anthropic
from mcp import ClientSession
from mcp.client.stdio import stdio_client, StdioServerParameters
client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY
MSG = [{"role": "user", "content": "Open example.com and tell me its title."}]
async def main():
    async with stdio_client(StdioServerParameters(command="npx", args=["agent-browser", "mcp"])) as (r, w):
        async with ClientSession(r, w) as s:
            await s.initialize()
            tools = [{"name": t.name, "description": t.description or "", "input_schema": t.input_schema} for t in (await s.list_tools()).tools]
    shared = sorted(set.intersection(*(set(t["input_schema"].get("properties", {})) for t in tools)))
    slim = copy.deepcopy(tools)
    for t in slim:
        for k in shared:
            t["input_schema"]["properties"].pop(k, None)
    count = lambda ts: client.messages.count_tokens(model="claude-opus-5-5", messages=MSG, tools=ts).input_tokens
    base = client.messages.count_tokens(model="claude-opus-5-5", messages=MSG).input_tokens
    full, without = count(tools) - base, count(slim) - base
    print(f"tools: {len(tools)}")
    print(f"options on every tool: {len(shared)}")
    print("  " + ", ".join(shared[:7]) + ",\n  " + ", ".join(shared[7:]))
    print(f"tokens, all tools:              {full:,}")
    print(f"tokens, without shared options: {without:,}")
    print(f"shared options:                 {full - without:,} ({(full - without) / full:.0%})")
asyncio.run(main())
