AI

How to use Playwright MCP with Claude Code

Key takeaways

  • Add Playwright MCP to Claude Code with claude mcp add playwright npx @playwright/mcp@latest, then start a new session.

    You need Node.js 20 or newer, and claude mcp list shows whether it connected. Put Playwright MCP's own flags, such as --headless, after --, or Claude Code reads them as its own.

  • Add --isolated when you're writing tests, so each session starts with a clean browser profile.

    By default the browser keeps cookies and logins between sessions, so Claude Code can write a test that skips a login a fresh test run still needs.

  • Ask Claude Code to save each flow it walks through as a Playwright test file, and run that file with npx playwright test.

    The file runs the same steps every time. An agent that clicks through the app on every run can take a different path through the same build, so a changed result could be a bug or a detour.

  • Run npx playwright init-agents --loop=claude to add Playwright's planner, generator, and healer as Claude Code subagents.

    They turn a seed test into a test plan and the plan into test files, and they patch failing tests. Review what the healer changes, since deciding whether the test or the product was wrong is still your call.

  • Switch Claude Code to the Playwright CLI when it works mostly in a large codebase.

    Playwright recommends the CLI for coding agents because it keeps tool schemas and page snapshots out of the model's context. MCP suits exploring an app page by page.

To use Playwright MCP with Claude Code, run claude mcp add playwright npx @playwright/mcp@latest and start a new Claude Code session. Claude Code can then open a browser, read each page, and click, type, and navigate through your app, which makes it a quick way to explore a feature and write a Playwright test for it.

What Playwright MCP gives Claude Code

Playwright MCP is Microsoft's open-source server that gives AI agents a browser through the Model Context Protocol (MCP), the standard Claude Code uses to connect to outside tools. Once it's added, Claude Code gets browser tools such as browser_navigate, browser_click, browser_type, browser_fill_form, browser_snapshot, and browser_take_screenshot, and it calls them the way it calls any other tool.

Playwright MCP reads each page as its accessibility tree instead of a screenshot. Each snapshot lists the page's elements with a short reference, and the model passes that reference back to click or type into the element. So Claude Code works from the page's structure and labels, the way a Playwright locator does, and doesn't need a vision model to find a button.

The browser opens in a visible window by default, so you can watch Claude Code work. It also keeps a persistent browser profile between sessions, which lets Claude Code stay logged in from an earlier session and write a test that skips a login a fresh test run still needs. Start the server with --isolated when you're writing tests, and each session gets a fresh browser profile.

How to add Playwright MCP to Claude Code

You need Claude Code and Node.js 20 or newer. Then:

  1. Add the server: Run this in your terminal, in the project you want to test:

    claude mcp add playwright npx @playwright/mcp@latest
    

    The server is available in your next Claude Code session.

  2. Check that it connected: Run claude mcp list in the terminal, or /mcp inside Claude Code. A working server shows as connected.

  3. Pass Playwright MCP's own options after --: Anthropic's docs say everything after -- goes to the server untouched, and that without it Claude Code tries to parse the server's flags as its own. To run the browser without a window, for example:

    claude mcp add playwright -- npx @playwright/mcp@latest --headless
    

    Other options include --browser (chrome, firefox, webkit, or msedge) and --isolated, which keeps the browser profile in memory so every session starts clean.

  4. Share it with your team, if you want: Claude Code adds a server to your own config for the current project by default. Add --scope project before the server's name to write it to a .mcp.json file in the project root instead, which you can commit. For the headless example above, Claude Code writes:

    {
      "mcpServers": {
        "playwright": {
          "type": "stdio",
          "command": "npx",
          "args": [
            "@playwright/mcp@latest",
            "--headless"
          ],
          "env": {}
        }
      }
    }
    

    Claude Code asks each person to approve a project-scoped server before it uses it. Use --scope user instead to have the server in every project on your machine.

The full list of options is in Playwright's MCP docs, and the scopes are in Anthropic's Claude Code MCP docs.

How to write Playwright tests with Claude Code and Playwright MCP

Ask Claude Code, in plain words, to open your app and walk through a flow, then to write what it did as a Playwright test file and run it with npx playwright test until it passes. Playwright MCP gives Claude Code the page as it really is, so the locators and assertions in the test come from elements it has seen instead of guesses. The server's --codegen option sets the language of the Playwright code it generates, TypeScript by default.

Playwright also ships test agents built for this loop. In a project that has Playwright Test installed, run:

npx playwright init-agents --loop=claude

It adds three Claude Code subagents to .claude/agents/, a seed test, a specs/ folder for test plans, and a .mcp.json entry for Playwright's own test MCP server:

  • The planner: Explores the app from the seed test and writes a test plan in Markdown.
  • The generator: Turns the plan into Playwright test files, checking selectors and assertions against the live app as it goes.
  • The healer: Runs a failing test, looks for the changed element in the current page, and patches the test until it passes or hits its limits. Review what it changed, since deciding whether the test or the product was wrong is still your call.

Either way, what you keep is ordinary Playwright code in your repo, which you can read, review, and run without an agent. Run that file on each change instead of asking Claude Code to click through the flow again, since a model that decides what to click on each run can take a different path through the same build, and a changed result could then be a bug or a detour.

Playwright MCP or the Playwright CLI: which should Claude Code use?

Playwright's own docs recommend the Playwright CLI for coding agents such as Claude Code that work in large codebases, and Playwright MCP for exploratory automation and long-running agent loops. The difference is how much each one puts in the model's context. With MCP, the tool schemas and page snapshots sit there for the whole session, while the CLI runs as shell commands and keeps them out.

To set up the CLI for Claude Code, install it and its skills in your project:

npm install -D @playwright/cli@latest
npx playwright-cli install --skills

The skills go in .claude/skills/, where Claude Code finds them. Add -g to the second command to install them in your home folder for every project. If Claude Code spends most of its time in your code and only checks the browser now and then, start with the CLI. If it spends a session working through an app page by page, MCP's snapshots are worth the tokens.

How QA Wolf works with Claude Code

Playwright MCP gives Claude Code a browser for one session, which covers exploring a feature and writing a test for it. Writing tests is the smaller part of QA, though. Before AI agents took on the work, QA Wolf measured how long each step took its QA engineers across 3.5 million tests: about 95 minutes to create a test, once, and then, each time it came up, about 17 minutes to investigate a failure, 45 to fix a broken test, and 30 to report a bug. AI agents do each step much faster now, but investigating and maintaining tests still add up to more work than creating them.

QA Wolf's AI agents do all of it, and Claude Code calls them through QA Wolf's MCP server. Claude Code passes what it knows about the change (the diff, the task, what the feature is meant to do), QA Wolf's agents test it, and the results come back to Claude Code, which still has the code in context and can fix the problem and send the new version through again. The same platform runs Playwright test automation for teams that want QA Wolf's agents to build and maintain the whole suite.

What Playwright MCP leaves to your team

Playwright MCP doesn't know what your suite already covers, so Claude Code can write a second test for a flow you already test, or one your team decided against. Running hundreds of the tests it writes in parallel on every pull request takes CI runners, browsers, and test data your team sets up and pays for. When a test fails in CI overnight, no Claude Code session is open, and someone on your team reads the trace to decide whether it's a bug, a broken test, or a flake. And when the product changes, someone asks Claude Code to fix each test that broke.

QA Wolf beats Claude Code with Playwright MCP on QA work

On QA Wolf's own benchmark, QA Wolf's agent, Claude Code, and Codex ran the same 1,567 evals on web, iOS, and Android apps. Claude Code used the browser through Playwright MCP on the 1,336 web evals, which cover planning a test strategy, writing tests, investigating failures, repairing broken tests, and filing bug reports. QA Wolf passed 92% of them, and Claude Code 77% (QA Wolf vs Claude Code vs Codex).

Web · 1,336 evals

  • QA Wolfgpt-6.1-sol92%
  • Claude CodeOpus 5.577%−15 points behind QA Wolf
  • Codexgpt-6.1-sol72%−20 points behind QA Wolf
The share of web evals where a reviewer with no QA Wolf background would accept the agent's work. Claude Code and Codex worked in the browser through Playwright MCP.

Across all 1,567 evals, QA Wolf passed 93%, Claude Code 78%, and Codex 74%. Codex and QA Wolf ran the same model, so the difference is the system QA Wolf builds around it: subagents, tools such as an email inbox for sign-in codes, and what its agents know about writing and maintaining tests.

QA Wolf runs, investigates, and maintains every test

  • Tests where they're missing: QA Wolf's agents find the coverage that already exists for a feature, then create new tests or update the ones that are there. When QA Wolf remaps an app, flows your team rejected stay rejected, along with the reason.
  • Every test in parallel on every pull request: QA Wolf runs the whole suite at once on its own infrastructure, with no browsers, devices, or runners for your team to manage.
  • Every failure investigated: QA Wolf's AI starts investigating while the rest of the suite is still running and works out whether each failure is a flake, a broken test, or a bug. It settled 75% of failed tests on its own, by fixing the test, reporting the bug, or seeing it pass on a retry, and bugs get filed with repro steps, a video, and the Playwright trace.
  • Repairs that start from the cause: Broken tests get unlimited repairs, and each one starts from why the test failed. Brittle selectors cause only about 28% of failures in QA Wolf's data, so a fix that only swaps selectors misses most of them.
  • Deterministic Playwright code: The agent uses the browser to write the test, then hands off to open-source Playwright code that runs the same steps every time.
  • Code your team owns: The tests are standard Playwright code your team can review, change, and version like any other code.

Salesloft is a perfect example. QA Wolf runs more than 300 of its tests in parallel on every pull request.

Start now, connect QA Wolf to Claude Code, and ask the agent to help you choose and create your first test on staging, or talk to sales.

Frequently asked questions

  • How do you add Playwright MCP to Claude Code?

    Run claude mcp add playwright npx @playwright/mcp@latest in your terminal, then start a new Claude Code session. You need Node.js 20 or newer. Run claude mcp list, or /mcp inside Claude Code, to check that the server is connected.

  • How do you use Playwright MCP with Claude Code?

    Ask Claude Code, in plain words, to open your app and walk through a flow. It calls Playwright MCP's tools to navigate, click, type, and read each page. To keep what it did, ask it to write the flow as a Playwright test file and run it with npx playwright test until it passes.

  • Is Playwright MCP free?

    Yes. Playwright MCP is open source from Microsoft, under the Apache 2.0 license, like Playwright itself. The model calls Claude Code makes while it uses the browser count against your Claude Code usage like any other work, and Playwright's docs note that MCP uses more tokens than the Playwright CLI.

  • Should Claude Code use the Playwright CLI or Playwright MCP?

    Playwright's docs recommend the Playwright CLI for coding agents such as Claude Code that work in large codebases, because shell commands keep tool schemas and page snapshots out of the model's context. They recommend Playwright MCP for exploratory automation and long-running agent loops that reason over the page as they go.

  • Is Playwright MCP good for testing?

    It's good for exploring an app and writing tests, and it isn't a test on its own. An agent that decides what to click on every run can take a different path through the same build, so save what it checks as Playwright code and run that code on every change.

  • Is there a better MCP server than Playwright MCP for QA?

    For giving Claude Code a browser, Playwright MCP is Microsoft's official server. For QA, connect Claude Code to QA Wolf's MCP server: QA Wolf's agents find the tests that already cover a change, write or update Playwright tests, run them in parallel on QA Wolf's infrastructure, investigate failures, and send the results back to Claude Code.

  • Which AI testing tool works best with Playwright?

    QA Wolf. Its AI agents write and maintain tests as standard Playwright code your team owns, run every test in parallel, and investigate every failure. On QA Wolf's own benchmark of 1,567 evals on web, iOS, and Android apps, QA Wolf passed 93%, Claude Code 78%, and Codex 74%.

More from the blog

All posts