Blog /

Playwright CLI vs MCP: Which to Use for AI Agents

Playwright CLI vs MCP compared for coding agents: context use, control, setup and repeatability, with official docs and a plain verdict for each job.

Playwright CLIPlaywright MCPAI coding agents

Use Playwright CLI when a coding agent such as Claude Code or Copilot works in a large codebase and needs its context for code. Use Playwright MCP for exploratory automation and specialized agentic loops that need persistent browser state and structured tools. That is the split the Playwright MCP introduction itself recommends. Both drive the browser through Playwright, so the choice is about how browser work reaches the model, not about which browsers you can test.

The rest of this guide shows where the two differ in context use, control, setup and repeatability, using only the official Playwright docs, and ends with what neither of them does.

Playwright CLI vs MCP at a glance

Criterion
How the agent uses it
Playwright CLI
Runs shell commands and reads their output
Playwright MCP
Calls MCP tools with structured parameters
Criterion
Context cost (per the docs)
Playwright CLI
Lower: concise CLI output, skills loaded on demand
Playwright MCP
Higher: tool schemas and snapshots in context
Criterion
Control
Playwright CLI
JSON config file, flags per command
Playwright MCP
Config file, environment variables and command-line arguments; --caps turns on optional tool groups
Criterion
Setup
Playwright CLI
npm install -g @playwright/cli@latest
Playwright MCP
A client entry that runs npx @playwright/mcp@latest
Criterion
Repeatability
Playwright CLI
Loads .playwright/cli.config.json automatically if present
Playwright MCP
Settings layered in a fixed order of precedence
Criterion
Default browser mode
Playwright CLI
Headless
Playwright MCP
Headed
Criterion
Best fit (per the docs)
Playwright CLI
Coding agents (Claude Code, Copilot) working with large codebases
Playwright MCP
Specialized agentic loops, exploratory automation

Sources: Playwright MCP introduction, Playwright CLI getting started, Playwright MCP configuration options.

How each one reaches the agent, and what it costs in context

A shell workflow and a protocol workflow

Playwright CLI is a program the agent runs. It types a command such as playwright-cli open https://example.com, reads the short output, and decides on the next command. Browser state comes back as command output, not through an open protocol stream.

Playwright MCP is a server that speaks the Model Context Protocol. The MCP client discovers its browser tools when the session starts, and the model calls them with structured parameters. The docs describe it as snapshot-based: it works on the page's accessibility tree, not on pixels, and returns structured text that models parse naturally.

One small flow through both

Say the agent has to open a page, look at what is on it, click a link and read the result.

  • With the CLI: playwright-cli open <url>, then playwright-cli snapshot, then playwright-cli click e15 (the ref comes from the snapshot), then another snapshot only if it needs the new state. Four short commands, four short outputs.

  • With MCP: the same four steps are four tool calls. The tool definitions are already in context, and snapshots come back inside the conversation.

On the browser side, Playwright does exactly the same thing in both cases.

Where the context goes

The CLI guide says it plainly: "CLI commands avoid loading large tool schemas and verbose accessibility trees into the model context." When Claude Code already holds application files, test helpers and diffs, that leaves more room for the code.

MCP makes the opposite trade. Tool schemas and snapshots sit in context, and in return the model gets typed tools and page state that persists across turns. The docs recommend it for loops that need "persistent state and iterative reasoning over page structure".

If you want numbers for your own stack, measure them: run the same journey through both, with the same browser mode and sign-in state, and compare how much each adds to the agent's transcript.

Control over browser options and tools

Workflow settings versus exposed tools

The CLI reads a JSON config file. Every command the agent runs uses those settings, and the agent stays free to run any CLI command.

MCP takes settings from three layers. The configuration options reference gives them "in increasing order of precedence: a config file, environment variables, and command-line arguments." A flag overrides an environment variable, and an environment variable overrides the config file.

MCP also decides which optional tools the model sees. The --caps flag (or PLAYWRIGHT_MCP_CAPS) takes a comma-separated list. The config schema lists network, storage, testing, vision, pdf, devtools and config. For example:

bash
npx @playwright/mcp@latest --caps=network,devtools

Which control surface fits

  • A fixed sequence of steps: if the agent only needs to run a known set of commands with the same settings, a committed CLI config keeps it simple.

  • A curated tool list inside a client: if the agent should see only certain optional tools, --caps sets that list explicitly.

  • One source of MCP settings: because flags beat environment variables and environment variables beat the config file, keep settings in one committed place so a stray variable on one machine does not change behaviour.

How to add each one to your coding agent

  1. Install Playwright CLI: npm install -g @playwright/cli@latest. To give the agent its skills, run playwright-cli install --skills (add -g to install them in your home directory for every project).

  2. Try it: playwright-cli open https://demo.playwright.dev/todomvc/ --headed. The CLI runs headless by default; --headed lets you watch.

  3. Add a project config: put your settings in .playwright/cli.config.json. The CLI loads it automatically if it is present.

  4. Add Playwright MCP to Claude Code: claude mcp add playwright npx @playwright/mcp@latest (Playwright MCP getting started). For scopes, signed-in sessions and common errors, see our Playwright MCP setup guide for Claude Code.

  5. Add Playwright MCP to Codex: codex mcp add playwright npx "@playwright/mcp@latest", or add an mcp_servers.playwright entry to ~/.codex/config.toml (Playwright MCP README).

  6. Add Playwright MCP to Cursor: Cursor Settings → MCP → Add new MCP Server, choose the command type and enter npx @playwright/mcp@latest. Other clients take the standard JSON entry:

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

To run MCP without a visible window, add "--headless" to args. It runs headed by default.

Keeping setup repeatable

For the CLI, commit .playwright/cli.config.json so every developer and every agent session uses the same settings. For MCP, keep arguments and --caps in the committed client config and avoid machine-specific environment variables, because they override the config file.

To confirm either setup works, ask the agent to open a page and return a snapshot. With MCP, also check that the client lists the playwright server and its tools.

Where the evidence is when a step fails

Both get their facts from the same Playwright engine. Only the delivery differs.

Through CLI commands

The CLI guide lists commands that fit straight into an agent's terminal loop:

  • playwright-cli console [min-level] for console messages

  • playwright-cli requests to list network requests, and playwright-cli request <num> for one of them

  • playwright-cli route <pattern>, route-list and unroute to mock routes

If a checkout button stops moving to the confirmation page, a CLI-driven agent can click it, see that nothing changed, list the requests, open the failing one and read the console, all as short text.

Through MCP capabilities

With MCP, the core server gives navigation and interaction tools, and optional groups such as network, devtools and storage are switched on with --caps. The agent then sees those diagnostic tools by name. In open-ended debugging that menu helps it try angles it might skip in a shell; in a known, repeated check, those extra schemas are context it does not need.

For a general method of working from an error to a verified fix, AppJet's walkthrough on debugging codes is a useful companion.

Which job suits each one

Playwright CLI is the better choice for a coding agent in a large repository that reruns a known journey, pulls requests and console output, and needs its context for application code. Its limits follow from that: it is headless unless you ask for --headed, and a long investigation is a series of separate commands.

Playwright MCP is the better choice for exploring an unfamiliar interface, for work that depends on page state persisting across turns, and for agentic loops that need an explicit, typed tool list. Its limits follow too: it is headed by default, and its tool schemas and snapshots take context from the start.

Three everyday cases:

  • Checking a sign-in flow after a large change in Claude Code: the CLI keeps context lean and returns network and console evidence directly.

  • Exploring a settings screen the agent has never seen: MCP keeps the session and the accessibility snapshots across turns.

  • A diagnostic agent with a narrow tool list: MCP with --caps=network,devtools exposes just those optional groups beside the core tools.

Your agent says “done”. We check your app.

After each deploy and every day, we walk the journeys you choose on your live app and tell your agent what passed and what failed, with screenshots.

claude mcp add --scope user --transport http checkmyapp https://checkmyapp.dev/mcp

Free account: $3 of checks, no card · Cursor, Codex and the full install guide

Where both stop

Both give your own agent a browser on the machine it is running on. Neither one looks at your deployed app after the agent's session ends, and in both the agent that wrote the code is also the one deciding whether it works. A flow can pass locally and still fail in production: a sign-in redirect that never fires, a missing environment variable, a third-party script that behaves differently on the live domain. For what to look at after a release, see software deployment testing.

That gap is what CheckMyApp is for. Your agent says "done"; CheckMyApp uses your live app as a real user and tells your agent what broke. It runs separately from the agent's session, walks the journeys that matter on the deployed app, and brings the evidence back to Claude Code, Cursor or Codex over MCP. The agent still does the fixing. Why a separate check matters, with a real case · Connect your agent.

Pick the Playwright interface that matches the agent's daily job, commit its config so runs repeat, and keep the question "does the live app still work?" with something other than the agent that wrote the code.

This article was prepared with the help of AI. Found a mistake? Tell us.

More articles