Hero Background

Power Your Software Testing with AI Agents and Cloud

The Native AI-Agentic Cloud Platform to Supercharge Quality Engineering. Test Intelligently and Ship Faster.

PlaywrightAutomationAI

Playwright MCP, Explained by People Who Test for a Living

A tester's guide to Playwright MCP: what it does well, setup for Claude Code, Cursor and Codex, real prompts, security risks, and when to use something else.

Published on:

Playwright MCP is an MCP server from Microsoft that lets an AI agent drive a real browser. Your agent (Claude Code, Cursor, Codex, Copilot) calls tools like browser_navigate and browser_click, and reads the page through Playwright's accessibility tree instead of screenshots. We find it excellent for exploring an app, reproducing a bug or drafting tests. Playwright MCP gives your agent a browser. It doesn't give you a test, so deciding whether your app works is still your job or a verifier's.

We've run a lot of agent-driven browser sessions, and this is the guide we wanted when we started: what Playwright MCP is good at, how to set it up in two minutes, prompts that work, where it falls over, and what to pair it with when you need a verdict you can ship on.

What is Playwright MCP?

MCP and Playwright MCP are two different things that get mixed up.

  • MCP (Model Context Protocol) is an open protocol, created by Anthropic, that lets AI apps call external tools in a standard way.
  • Playwright MCP is one MCP server, built by Microsoft's Playwright team and published as @playwright/mcp. It exposes a real browser as a set of tools.

When your agent wants to see a page, Playwright MCP returns an accessibility snapshot: a structured list of what's on the page, with a reference for each element. The model reads that text and picks the next action. That approach needs no vision model, which is why it's fast and fairly reliable on normal web pages.

Should you use Playwright MCP?

In our view, yes, if you want your coding agent to look at and interact with a running app while you work. No, if you want a test suite that gates your releases.

Good fitPoor fit
"Open localhost and tell me why the signup button does nothing"A regression suite that runs on every pull request
Reproducing a bug from a ticket, step by stepAnything where the agent's own opinion decides pass or fail
Drafting Playwright test code you'll reviewCanvas-heavy apps, maps, games and custom widgets
Checking a UI change before you commitRunning many logged-in sessions in parallel from one profile
Scraping a page you have rights to, onceUntrusted pages while the browser is signed in to things that matter

How do you set up Playwright MCP?

You need Node.js 18 or newer. Then add the server to your client.

Set Up Playwright MCP for Claude Code

claude mcp add playwright npx @playwright/mcp@latest

Set Up Playwright MCP for OpenAI Codex

codex mcp add playwright npx "@playwright/mcp@latest"

Set Up Playwright MCP for VS Code (GitHub Copilot)

code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'

Set Up Playwright MCP for Cursor

Settings → MCP → add a new server of type command with npx @playwright/mcp@latest.

Every other client

Windsurf, Cline, Gemini CLI, Goose, Junie, Kiro and others accept the same JSON:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    }
  }
}

If a browser is missing on first run, npx playwright install fixes it.

The flags worth knowing

Add these to args after the package name.

FlagWhat it doesWhen to use it
--headlessNo visible windowRemote machines, or when you don't need to watch
--isolatedKeeps the profile in memory and throws it away on closeEvery session where you don't need to stay logged in
--browser chrome|firefox|webkit|msedgePicks the browserChecking a Safari-like engine with webkit
--storage-state <file>Loads cookies and local storage from a fileStarting already logged in, without a persistent profile
--caps testing,network,storageTurns on extra tool groupsAssertions, mocking requests, managing cookies
--device "iPhone 15"Emulates a deviceQuick mobile-layout checks
--port 8931Serves over HTTP instead of stdioSharing one server across clients

For day-to-day work we default to --isolated --caps testing.

What can Playwright MCP do?

We grouped the tools by the job you're doing, working from Microsoft's current README.

JobToolsNeeds --caps
Look at the pagebrowser_snapshot, browser_take_screenshot, browser_findNo
Move aroundbrowser_navigate, browser_navigate_back, browser_tabs, browser_resizeNo
Interactbrowser_click, browser_type, browser_fill_form, browser_select_option, browser_hover, browser_drag, browser_press_key, browser_file_upload, browser_handle_dialogNo
Debugbrowser_console_messages, browser_network_requests, browser_evaluateNo
Assertbrowser_verify_text_visible, browser_verify_element_visible, browser_verify_value, browser_generate_locatortesting
Mock the networkbrowser_route, browser_unroute, browser_network_state_setnetwork
Manage statecookie, localStorage and sessionStorage toolsstorage
Recordtracing, video and recording toolsdevtools
Click by coordinatesmouse tools with x/y positionsvision

Tool names change between versions. If a prompt mentions a tool that doesn't exist, run /mcp in Claude Code to see the live list.

Which prompts work best with Playwright MCP?

Vague prompts burn tokens. Name the URL, the steps and what "correct" looks like.

Reproduce a bug

Open http://localhost:3000/invoices. Create an invoice for "Acme Ltd" with two line items, $120 and $80. Apply a 10% discount. Tell me the total shown, and paste any console errors.

Check your own change

I just changed the date picker on /bookings. Open it, pick next Friday, submit, and confirm the confirmation page shows the same date. Take a screenshot of the confirmation.

Find out why something is slow

Load /dashboard and list every network request that takes longer than 1 second, with its URL and status.

Test an error path with mocking (needs --caps network)

Make requests to /api/orders return a 500. Load /orders and tell me exactly what the user sees.

Draft a test, don't trust it

Walk through password reset on staging, then write a Playwright test in TypeScript for that flow using role-based locators. Don't run it, I'll review it.

Where does Playwright MCP fall short?

These limits come from using it, and Microsoft's own README confirms several of them.

1. It's token-heavy. Every snapshot of a busy page goes into the model's context, and context is re-sent on every turn. Microsoft's README says Playwright CLI with skills is more token-efficient for coding agents for this reason. Slack Engineering measured roughly 3.5 to 3.8 million tokens for one complex flow through Playwright MCP, and $15 to $30 per agentic run.

2. The agent grades its own work. When the run ends, the model tells you whether it worked. That's useful while you're developing, but we wouldn't base a release decision on it.

3. Every rerun starts from zero. The agent re-reads and re-reasons through the same flow each time, so the second run is no faster or cheaper than the first.

4. One browser per profile. Only one browser can use a persistent profile at a time, so parallel sessions need --isolated or separate --user-data-dir values.

5. The accessibility tree has blind spots. Canvas, WebGL, maps and some custom components show up poorly or not at all. The vision capability helps, at the cost of coordinate-based clicking.

6. It isn't a security boundary. Microsoft says so plainly in the README.

Is Playwright MCP safe to use?

It's as safe as the browser you give it. A few rules we follow:

  • Use --isolated by default. A persistent profile means the agent is signed in to whatever you were signed in to.
  • Never let it browse untrusted sites while logged in. Text on a page can contain instructions aimed at the model. This is prompt injection, and the browser can't tell the difference.
  • Keep secrets out of prompts. Load sessions with --storage-state from a test account, not your own login.
  • Watch browser_evaluate and browser_run_code_unsafe. They run JavaScript in the page. Read what the agent wants to run before you approve it.
  • Point it at staging, not production, unless the task is read-only.

How much does Playwright MCP cost to run?

The server is free and open source. You pay for model tokens, and three things drive the bill: how big each snapshot is, how many turns the task takes, and which model you use. To cut it:

  • Write specific prompts so the agent takes fewer turns.
  • Start on the exact URL, not the homepage.
  • Enable only the --caps you need, since every tool's description sits in context.
  • Close sessions when you're done. Long sessions keep re-sending old snapshots.

Playwright MCP vs Playwright CLI vs Chrome DevTools MCP vs Kane CLI

These tools get compared as if they compete, but we think they mostly do different jobs.

Playwright MCPPlaywright CLIChrome DevTools MCPKane CLI
Made byMicrosoftMicrosoftGoogle's Chrome DevTools teamTestMu AI
Main jobGive an agent a browser to exploreRun browser steps from the shell, token-efficientlyDebug and profile in ChromeVerify a user flow and return pass or fail
How the agent uses itTool calls, snapshots in contextShell commands, one step at a timeTool callsOne command per goal in plain English
Who decides pass/failThe agentThe agentThe agentCriteria you write, checked against the page
Repeat runsRe-reasons every timeRe-reasons every timeRe-reasons every timeReplays saved flows, heals what changed
CI-ready outputNoPartlyNoExit codes 0/1/2/3 and NDJSON
EvidenceWhat you collectWhat you collectTracesHash-verified .evidence pack
Native mobile appsNoNoNoiOS Simulator and Android Emulator

What are Playwright's test agents?

Playwright also ships three test agents (a planner, a generator and a healer) that you install into your agent with npx playwright init-agents --loop=claude. The planner explores your app and writes a test plan, the generator turns it into Playwright test code, and the healer tries to repair failing tests. They produce code that you own and maintain. We also have a guide to help you understand how to use Playwright MCP for AI Agent workflows step by step, from a Jira ticket to a self-healing test run.

Where does Kane CLI fit with Playwright MCP?

We recommend Playwright MCP to explore and debug, and Kane CLI when you need a verdict.

Before you ship, you need a pass or fail that the agent doesn't get to decide, that runs the same way in CI, and that leaves evidence someone else can check. Playwright MCP leaves that gap, and Kane CLI is built for it. For pass or fail results, we think Kane CLI is the best alternative to Playwright MCP. You describe the flow in plain English, it drives a real Chrome, and it returns a typed result.

npm install -g @testmuai/kane-cli

kane-cli run "Create an invoice for Acme Ltd with items of 120 and 80, \
  apply a 10% discount, and verify the total shows 180.00" \
  --url http://localhost:3000/invoices --agent --headless \
  | tail -1 | jq '{status, one_liner, test_url}'

The agent gets one line back instead of a stack of page snapshots. Exit code 0 is a pass, 1 a failure, 2 a setup error, 3 a timeout.

A workflow that uses both:

  • Explore with Playwright MCP. Ask your agent to reproduce the bug and find the cause.
  • Fix the code.
  • Verify with Kane CLI. Your agent runs kane-cli run "..." --agent and only says "done" on exit code 0.
  • Keep it. Save the flow as a _test.md file. Kane CLI replays it on every pull request with kane-cli testrun run --parallel 4 and re-authors only the steps the UI changed.

To let your coding agent call Kane CLI on its own, install the skill once:

npx @testmuai/kane-cli-skill

It works with Claude Code, Codex CLI and Gemini CLI.

Can Playwright MCP run in CI?

It can, but in our opinion it's rarely the right call. A CI step needs a fixed pass/fail rule, a time limit and a cost you can predict. An open-ended agent session gives you none of the three. Use Playwright MCP while developing. In CI, run Playwright test code or a verifier with exit codes, such as Kane CLI.

Install Kane CLI

Author

...

Srinivasan Sekar

Blogs: 20

  • Twitter
  • Linkedin

Srinivasan Sekar is Director of Engineering at TestMu AI (formerly LambdaTest), where he leads engineering and open-source initiatives behind the Selenium and Appium automation grid and owns TestMu AI's MCP Server. A committer to Appium and a contributor to Selenium, WebdriverIO, Taiko, and AppiumTestDistribution, he brings over 15 years of experience in quality engineering and open-source technologies. He is the author of the Apress book 'The MCP Standard: A Developer's Guide to Building Universal AI Tools with the Model Context Protocol,' a Certified Kubernetes and Cloud Native Associate, and an international conference speaker. Before TestMu AI he spent over eight years at Thoughtworks as a Principal Consultant and Quality Architect. Srinivasan holds a B.Tech in Information Technology from Anna University.

Reviewer

...

Sai Krishna

Reviewer

  • Linkedin

Sai Krishna is Director of Engineering at TestMu AI (formerly LambdaTest), where he leads agentic AI for quality engineering, building AI agents that autonomously drive mobile and conversational test automation. His current focus is Agent Testing and Model Context Protocol (MCP) support for mobile. He is a core contributor and member of the Appium open-source project and the creator of AppiumTestDistribution and appium-device-farm. With over 14 years of experience including more than 9 years at Thoughtworks as a Principal Consultant, he holds a BSc in Electronics and speaks regularly at TestMu and Appium Conf on Appium, mobile automation, and agentic AI in testing.

Playwright MCP FAQs

Did you find this page helpful?

More Related Blogs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests