Tools

Playwright MCP: let agents use a browser via accessibility snapshots instead of screenshots

TL;DR

Playwright MCP exposes browser tools driven by the accessibility tree: faster, cheaper in tokens and more reliable than screenshot-based control. Add it to Claude Code with claude mcp add playwright npx @playwright/mcp@latest. Great for E2E tests, bug reproduction and responsive checks.

When you want an agent to test a sign-up flow, reproduce a UI bug or fill forms in bulk, the “classic” way is to show it screenshots and let it guess coordinates — slow, token-hungry and error-prone. Microsoft’s Playwright MCP works differently: the agent reads the page through the accessibility tree — structured data describing buttons, inputs, links and their roles — and acts on that. No vision model required; faster and more reliable.

Why accessibility snapshots beat screenshots

CriterionScreenshot-basedAccessibility snapshot
How the page is “seen”Pixels, guessed coordinatesA tree of elements with names, roles and states
ReliabilityBreaks when layout or screen size changesPrecise element references
Model requirementNeeds visionOnly reads structured text
Side benefit—Exposes accessibility bugs (unlabelled buttons…)

Adding it to Claude Code

# For all projects
claude mcp add --scope user playwright -- npx -y @playwright/mcp@latest

# Current project only (writes .mcp.json, which you can commit)
claude mcp add --scope project playwright -- npx -y @playwright/mcp@latest

Requires Node.js 18+. After adding it, run /mcp to confirm the server is connected. Claude Desktop, VS Code and Cursor use an equivalent JSON entry running npx @playwright/mcp@latest.

Useful flags

FlagEffect
--headlessRun without a window (headed by default so you can watch)
--isolatedIn-memory profile, nothing saved to disk — run several clients in parallel
--browserPick the browser/channel (chrome, firefox, webkit, msedge…)
--storage-stateLoad login state (cookies, localStorage) from a file — use with test accounts
--allowed-origins / --blocked-originsRestrict which domains the browser may visit
--caps vision,pdf,devtoolsExtra capabilities: coordinate-based actions, PDF export, devtools
--save-trace, --output-dirSave Playwright traces and output files for later debugging
--viewport-sizeSet the viewport size — for responsive checks

Note: with a persistent profile only one browser process can use it at a time — add --isolated for parallel runs. The project is still at 0.0.x, so pin a version and test before relying on it.

Sample QA prompts

Open http://localhost:3000, sign up with the test account in fixtures/users.json,
add two products to the cart and check the total. If it's wrong, take a screenshot
and write the reproduction steps to bug-report.md.
Open /checkout at a 375x812 viewport. List buttons without an accessible
name and inputs without labels.

When to use it — and when not to

Good fitPoor fit
Exploratory testing, bug reproductionHigh-volume coding agents with tight token budgets
Long agent loops that need persistent browser stateSimple one-off browser tasks
Form filling and data entry without vision modelsPixel-based interaction (canvas, games)

Accessibility trees and tool schemas are verbose, so for token-sensitive coding agents Microsoft’s own guidance leans towards Playwright CLI + skills; the trade-off is losing MCP’s persistent browser state and rich introspection.

Safety notes

  • The server runs with your user permissions; browsers it launches can reach your network and file system.
  • Use it on dev/staging with test accounts; never hand the agent real passwords.
  • Pages the agent opens are untrusted content — they may contain prompt injection. Restrict domains with --allowed-origins.
  • Remove or disable the server when you don’t want browser automation in every session.

How to apply it

  • Developers: Use it to reproduce bugs from QA descriptions; once the agent finds the right flow, ask it to turn that into a fixed Playwright test for CI — don’t make your tests depend on an agent.
  • QA: Exploratory testing from natural-language scenarios, with free accessibility checks from the snapshots.
  • PMs: A one-sentence smoke test of staging before a demo, instead of waiting for someone to click through manually.

Sources & references

  1. microsoft/playwright-mcp — GitHub
  2. Playwright MCP — dev.co
  3. Try an MCP: Playwright — Dometrain AI Workshop