{"slug": "why-playwright-mcp-cost-us-5-more-tokens-than-we-expected", "title": "Why Playwright MCP Cost Us 5 More Tokens Than We Expected", "summary": "An open-source browser automation MCP called Brocogni reduces token costs by 81% compared to Playwright MCP by pre-computing selectors server-side. The developer found that iteration, not observation quality, drives costs when generating reusable Playwright scripts. Brocogni returns only actionable elements with pre-computed selectors, eliminating the need for LLM reasoning about ephemeral references.", "body_md": "We built an open-source browser automation MCP because we wanted something simple:\n\nObserve a webpage once, let an LLM interact with it, then export a Playwright script that actually works.\n\nThat sounds straightforward.\n\nIt wasn't.\n\nWhile benchmarking against Playwright MCP, we discovered something we hadn't considered: **observation quality isn't the biggest contributor to cost. Iteration is.**\n\nThe expensive part isn't making the browser agent click buttons.\n\nIt's making the generated automation reusable.\n\n`browser_snapshot`\n\nPlaywright MCP represents elements using ephemeral references:\n\n```\nbutton \"Login\" [ref=e5]\ntextbox \"Email\" [ref=e10]\nlink \"Forgot password\" [ref=e23]\n```\n\nWithin an MCP session, this is excellent.\n\nThe model simply responds:\n\n```\nbrowser_click(\"e5\")\n```\n\nFast.\n\nClean.\n\nMinimal reasoning.\n\nThe problem appears later.\n\nEvery snapshot generates a new set of references.\n\n`e5`\n\ntoday is not `e5`\n\ntomorrow.\n\nThose identifiers only exist for the lifetime of that observation.\n\nMany people aren't using browser agents just to click around.\n\nThey're using them to produce reusable automation.\n\nFor example:\n\nOnce the LLM tries to generate code like this:\n\n```\nawait page.getByRole(...);\n```\n\nthe references become useless.\n\nThey're meaningless outside the MCP session.\n\nThe model now has to reconstruct selectors from scratch.\n\nThat usually means:\n\nThe browser interaction itself is cheap.\n\nThe retries are not.\n\nInstead of measuring a single observation, we measured the full pipeline:\n\n```\nObserve\n    ↓\nInteract\n    ↓\nGenerate Playwright Script\n    ↓\nExecute Script\n    ↓\nFix Failures if Needed\n```\n\nThe numbers were surprising.\n\n**≈ 1,099 tokens**\n\n`getByRole()`\n\nselectors**≈ 1,171 tokens**\n\n**≈ 941 tokens**\n\n```\n3,211 tokens\n≈ $0.04 per generated script\n```\n\nInstead of returning references, Brocogni computes selectors before the LLM ever sees the page.\n\nThe observation already contains:\n\nThe model simply copies them into the Playwright script.\n\nOne observation.\n\nOne generation.\n\nDone.\n\n```\n1,535 tokens\n≈ $0.01 per generated script\n```\n\nAcross roughly **200 generated scripts/month**:\n\n| Solution | Monthly Cost |\n|---|---|\n| Playwright MCP | ~$7.11 |\n| Brocogni | ~$1.33 |\n\nThat's roughly an **81% reduction** in token cost in our benchmark.\n\nMore importantly, it's fewer failed iterations.\n\nAnother observation was how much unnecessary information reaches the LLM.\n\nA typical Playwright MCP snapshot contains:\n\nOnly around **9** are actually interactive.\n\nThe model must determine:\n\nThat reasoning consumes tokens.\n\nBrocogni instead returns only actionable elements.\n\n| Playwright MCP | Brocogni | |\n|---|---|---|\n| Elements returned | 62–93 | 9 |\n| Actionable | Mixed | 9/9 (100%) |\n| LLM filters nodes | Yes | No |\n| Pre-computed selectors | No | Yes |\n| Fallback selector chains | No | Yes |\n\nThe observation is slightly richer.\n\nThe downstream reasoning becomes dramatically simpler.\n\nThe distinction comes from where the work happens.\n\nPlaywright MCP exposes browser state.\n\nThe LLM performs much of the interpretation.\n\nBrocogni shifts that interpretation server-side.\n\n```\nChrome DevTools Protocol\n          │\n          ▼\nAccessibility Tree\n          │\n          ▼\nDOM Snapshot\n          │\n          ▼\nGeometry Extraction\n          │\n          ▼\nActionability Filtering\n          │\n          ▼\nPurpose Inference\n          │\n          ▼\nRanked Selector Generation\n          │\n          ▼\nStructured JSON Observation\n          │\n          ▼\nLLM\n```\n\nBy the time the model receives the observation:\n\nThe LLM doesn't need to reverse-engineer the DOM.\n\nPlaywright MCP is extremely well designed for interactive browser agents.\n\nIf your goal is simply:\n\n\"Navigate a website.\"\n\nit's an excellent choice.\n\nOur benchmark looked at a different workflow:\n\n\"Generate Playwright code that someone will commit to a repository.\"\n\nThose are different optimization problems.\n\nFor the second case, reusable selectors matter more than ephemeral references.\n\nBrocogni is an open-source MCP server focused on browser automation for LLMs.\n\nInstead of exposing raw browser state, it provides structured observations that are immediately usable for automation generation.\n\n**GitHub**\n\n[https://github.com/hrshx3o5o6/brocogni](https://github.com/hrshx3o5o6/brocogni)\n\n**Website**\n\nI'd love feedback from people building browser agents or using Playwright MCP in production.\n\nIf you've measured similar token costs—or found different tradeoffs—I'd be interested to compare approaches.", "url": "https://wpnews.pro/news/why-playwright-mcp-cost-us-5-more-tokens-than-we-expected", "canonical_source": "https://dev.to/harshavardhan_kangaladay/why-playwright-mcp-cost-us-5x-more-tokens-than-we-expected-5ckf", "published_at": "2026-06-29 17:59:36+00:00", "updated_at": "2026-06-29 18:18:54.611815+00:00", "lang": "en", "topics": ["developer-tools", "machine-learning", "large-language-models", "ai-agents"], "entities": ["Playwright MCP", "Brocogni", "Chrome DevTools Protocol", "LLM"], "alternates": {"html": "https://wpnews.pro/news/why-playwright-mcp-cost-us-5-more-tokens-than-we-expected", "markdown": "https://wpnews.pro/news/why-playwright-mcp-cost-us-5-more-tokens-than-we-expected.md", "text": "https://wpnews.pro/news/why-playwright-mcp-cost-us-5-more-tokens-than-we-expected.txt", "jsonld": "https://wpnews.pro/news/why-playwright-mcp-cost-us-5-more-tokens-than-we-expected.jsonld"}}