Skip to content

Playwright MCP server: install it in your coding agent and keep the browser on a short leash

On this page

Playwright MCP is Microsoft’s MCP server, published as @playwright/mcp, that lets an agent drive a real browser through Playwright. Instead of sending screenshots, it gives the model the page’s accessibility snapshot: roles, accessible names and element references the model can click or type into. You run it locally with npx @playwright/mcp@latest, register it in your client as a stdio server, and choose flags for headless mode, browser, profile and extra tool groups.

Checked as of November 2026 against the Playwright MCP README (release v0.0.84) and the Claude Code MCP docs.

Accessibility snapshots instead of screenshots

The core tool is browser_snapshot. It returns the page’s accessibility tree as text, with a reference for each element. Action tools such as browser_click, browser_type and browser_select_option take a target, which is either one of those references or a unique selector. The model never has to guess pixel coordinates, and it doesn’t need a vision model to read the page.

That has practical consequences:

  • Actions are deterministic. A click goes to the element with that reference, not to whatever happens to sit at x=412, y=96 after a layout shift.
  • Hidden structure shows up. A button with no accessible name appears as an unnamed button, which is useful when you are checking accessibility anyway.
  • Big pages are expensive. A long dashboard produces a long snapshot, and by default the server returns a fresh snapshot after actions. The README itself suggests that coding agents short on context may do better with Playwright CLI plus skills, and keeps MCP for longer loops that benefit from a persistent browser.

Screenshots still exist. browser_take_screenshot captures the viewport, the full page or one element, but the tool description tells the model to use browser_snapshot for actions. If you need coordinate clicks for canvas apps or elements missing from the accessibility tree, enable the vision capability (below), which adds tools such as browser_mouse_click_xy.

Install Playwright MCP in Claude Code, Codex, Cursor and VS Code

The server needs Node.js 18 or newer. Every client runs the same command; only the registration differs.

Claude Code

Use -- so Claude Code doesn’t try to parse the server’s flags as its own:

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

Add --scope user before the name to make it available in every project, or --scope project to write it to a committed .mcp.json. The Claude Code client guide explains the three scopes.

Codex

The same pattern, written to ~/.codex/config.toml:

Shell
codex mcp add playwright -- npx @playwright/mcp@latest
TOML
[mcp_servers.playwright]
command = "npx"
args = ["@playwright/mcp@latest", "--headless", "--isolated"]

Cursor

Add the standard config to .cursor/mcp.json in the project or ~/.cursor/mcp.json for all projects:

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

VS Code

The README gives a one-line install through the VS Code CLI:

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

@latest means each new session can pick up a new release. The project ships often (v0.0.84 came out on October 31, 2026), so if a team relies on exact tool behavior, pin a version in the args instead.

Useful Playwright MCP flags

Flags go after the package name in args, or after -- on the command line. Each one also has a PLAYWRIGHT_MCP_* environment variable, and everything can live in a JSON file passed with --config.

FlagWhat it does
--headlessRuns without a visible window. The default is headed
--browserchrome, firefox, webkit or msedge
--isolatedKeeps the profile in memory; nothing is saved when the browser closes
--user-data-dirUses a specific profile directory
--storage-stateLoads cookies and local storage from a file into an isolated session
--allowed-origins, --blocked-originsSemicolon-separated origin lists the browser may or may not request
--capsAdds tool groups such as vision, pdf and devtools
--viewport-size, --device, --mobileViewport size or device emulation
--secretsA dotenv file whose values are replaced in tool responses
--output-dirWhere screenshots and other generated files go
--portServes over HTTP instead of stdio

A setup I’d use for checking a local app:

Shell
claude mcp add playwright -- npx @playwright/mcp@latest \
  --headless --isolated \
  --allowed-origins "http://localhost:3000;http://localhost:5173"

Two warnings from the README are worth repeating. The origin lists do not serve as a security boundary and do not affect redirects, so treat them as a guard against wandering, not as containment. And --secrets (plus the related redactUrlParams config) is described as a convenience, not a security feature.

Profiles: persistent, isolated or your own browser

By default Playwright MCP keeps a persistent profile on disk, one per workspace, under ms-playwright in your cache directory (for example ~/Library/Caches/ms-playwright/ on macOS). Anything you log into during a session stays logged in next time. Only one browser can use a persistent profile at once, so parallel agents in the same workspace conflict; the README’s fix is --isolated or a separate --user-data-dir per client.

--isolated starts each session clean. To begin logged in as a test user, save a Playwright storage state file and pass it with --storage-state.

--extension goes the other way: with the Playwright extension installed in Chrome or Edge, the server connects to your running browser and its existing tabs and sessions. --cdp-endpoint attaches to a browser over the Chrome DevTools Protocol. Both hand the agent whatever that browser is signed into.

Capabilities

--caps turns on tool groups that are off by default. The README lists vision (coordinate-based mouse tools), pdf (browser_pdf_save) and devtools (tracing, video and element highlighting), and the tool reference also documents network (request routing), storage (cookies and local storage) and testing (browser_generate_locator and browser_verify_* assertions). Only enable the ones the task needs: each group adds tool definitions to the model’s context, and storage gives it direct read access to cookies.

What Playwright MCP is good for

Verifying a UI change. After editing a component, ask the agent to open the page on your dev server, take a snapshot and confirm the new label, state or error message appears. browser_console_messages and browser_network_requests catch the failures that don’t show on screen.

Reproducing a bug report. Paste the steps from the issue and let the agent follow them. The snapshot after each step tells you exactly where reality diverged from the report, and browser_evaluate can read page state when the DOM isn’t enough.

Generating tests. The server generates Playwright code for the actions it runs (TypeScript by default; --codegen picks Python, Java, C# or none), and the testing capability adds locator generation and assertions. A useful loop is: the agent explores the flow through MCP, then writes a normal Playwright test you commit and run in CI without any agent involved.

Checking emulated conditions. browser_emulate_media switches light and dark color schemes and reduced motion, and --device emulates a phone.

Risks of an agent driving a logged-in browser

The README is direct about it: Playwright MCP is not a security boundary. The risk comes from combining three things the server makes easy.

First, the browser carries your identity. With the persistent profile, --extension or --cdp-endpoint, every site the browser is signed into is reachable, and the agent can act there as you.

Second, web pages are untrusted input. A snapshot includes all the text on the page, so a hostile page, a comment in an issue tracker or a support ticket can carry instructions the model may follow. That is prompt injection, and MCP security risks covers why a client can’t filter it out reliably.

Third, some tools run code. browser_evaluate executes JavaScript in the page, and browser_run_code_unsafe runs Playwright code in the server process; its own description calls it RCE-equivalent. File upload and drag-and-drop take local file paths, and the storage tools read and write cookies.

Practical limits:

  • Use --isolated with a test account’s --storage-state for anything involving login, and keep the agent out of your everyday profile.
  • Point it at local or staging origins, and add --allowed-origins as a guardrail even though it isn’t containment.
  • In Claude Code, put mcp__playwright__browser_run_code_unsafe and mcp__playwright__browser_evaluate under ask or deny. The Claude Code permissions guide shows the rule syntax.
  • Don’t expose --port on a shared network. The HTTP mode binds to localhost by default for a reason.

Playwright MCP vs Chrome DevTools MCP

Google’s Chrome DevTools MCP server overlaps with Playwright MCP but leans toward debugging: it officially supports only Chrome, automates it through Puppeteer, and adds performance traces, network inspection and source-mapped console errors. Use Playwright MCP to click through flows across browsers and turn them into tests, and reach for Chrome DevTools MCP when the question is why a page is slow. Chrome DevTools MCP covers its setup and flags.

Playwright MCP and remote MCP gateways

Playwright MCP runs on your machine because the browser does. It’s a stdio server, or an HTTP server on localhost when you pass --port. A remote-only gateway such as Toolstile’s hosted service can’t reach it and doesn’t govern it: the hosted service connects to public HTTPS MCP servers only, as what an MCP gateway is explains. Keep Playwright MCP configured directly in each client and control it with that client’s own permission rules, and use a gateway for the remote servers (issue trackers, docs, observability) that sit alongside it.