Playwright MCP vs CLI: Which Should Your AI Agent Use in 2026?

We’ve used both extensively in production — running hundreds of browser automation tasks daily with Claude Code, Cursor, and custom AI agents (we use it daily to automate publishing across platforms). This guide breaks down exactly how they differ, when to use each, and the real-world trade-offs nobody talks about.
What Is Playwright MCP?
Playwright MCP is a Model Context Protocol server that acts as a bridge between AI models (LLMs) and Playwright-managed browsers. It exposes browser actions as MCP “tools” that the AI can call directly — navigate, click, type, take screenshots, and more.
The key innovation: MCP uses the browser’s accessibility tree (a semantic, hierarchical representation of the page) instead of screenshots. This means it works with pure text — no vision models required. The AI sees structured data about every element on the page, including roles, labels, and interactive states.
How it works:
- MCP server launches and manages a browser instance
- AI model calls MCP tools (e.g.,
browser_navigate,browser_click,browser_snapshot) - MCP executes the action and returns the result (including page accessibility snapshot) directly into the AI’s context window
- The AI reasons about the result and decides what to do next
What Is Playwright CLI?
Playwright CLI is a command-line interface that gives AI agents (and humans) direct shell-level control over a Playwright browser. Instead of MCP tools, the agent runs shell commands like playwright-cli goto URL, playwright-cli click ref, playwright-cli snapshot.
The critical architectural difference: CLI saves everything to disk, not to the AI’s context window. Snapshots, screenshots, and console logs are written as files. The AI agent can choose to read them or ignore them — keeping its context window lean.
How it works:
- Agent runs
playwright-cli opento start a browser daemon process - Commands travel over a Unix socket to the daemon — the browser stays running between commands
- Each command returns a brief result; full snapshots are saved to disk files
- Agent reads files only when needed, keeping token usage minimal
Playwright MCP vs CLI: Head-to-Head Comparison
| Feature | Playwright MCP | Playwright CLI |
|---|---|---|
| Architecture | MCP server + tool calls | Shell commands + Unix socket daemon |
| State management | In AI’s context window | On disk (files) |
| Token usage | ~114,000 tokens per task | ~27,000 tokens per task (4x less) |
| Page representation | Accessibility tree (structured) | Accessibility tree (saved to file) |
| Session persistence | While MCP server runs | Daemon persists across commands; --persistent saves profile to disk |
| Multiple sessions | One browser per MCP instance | Named sessions (-s=name) for multiple browsers |
| Setup complexity | Add MCP config to AI tool settings | npm install -g @playwright/cli |
| Screenshot support | Returns inline to AI | Saves to disk as file |
| Custom code execution | browser_run_code tool |
playwright-cli run-code "async page => ..." |
| Dialog handling | browser_handle_dialog |
playwright-cli dialog-accept |
| File uploads | browser_file_upload |
playwright-cli upload ./file |
| Long sessions (50+ steps) | Context window bloats, performance degrades | Stays lean — disk-based state doesn’t grow context |
| Agent requirements | MCP-compatible client (Claude Desktop, VS Code, etc.) | Any agent with shell/bash access |
| Best for | Short exploratory sessions, rich introspection | Long automation workflows, cost-sensitive production |
| Maintained by | Microsoft (Playwright team) | Microsoft (Playwright team) |
Token Cost: The 4x Difference
This is the elephant in the room. The Playwright team’s own benchmarks showed that a typical browser automation task consumed:
- MCP: ~114,000 tokens per task
- CLI: ~27,000 tokens per task
That’s roughly a 4x reduction in token usage — and early adopters report savings of 4-10x depending on the task complexity. For production AI agents running hundreds of browser tasks daily, this is the difference between a manageable API bill and a terrifying one.
Why the difference? With MCP, every browser interaction returns the full accessibility snapshot into the AI’s context window. After 20-30 interactions, the context is stuffed with page snapshots that the AI has to process on every subsequent turn. With CLI, snapshots go to disk — the AI only reads them when it explicitly needs to.
Video: Playwright CLI vs MCP — official comparison from the Playwright team (94K views)

When to Use Playwright MCP
MCP is the better choice when:
- Short exploratory sessions — browsing a few pages, testing a quick flow (under 15 interactions)
- Rich page introspection — when the AI needs to deeply understand page structure before acting
- Sandboxed environments — where the AI doesn’t have shell/filesystem access (e.g., Claude Desktop, some IDE integrations)
- Self-healing tests — where the AI needs continuous awareness of page state to adapt to UI changes
- Iterative reasoning — when the AI needs to “think” about what it sees on the page over multiple turns
When to Use Playwright CLI
CLI wins for:
- Long automation workflows — 50+ step sequences (forms, CMS operations, social media posting)
- Cost-sensitive production — when you’re running hundreds of tasks and token costs matter
- Agents with shell access — Claude Code, Codex, Devin, or custom agents with
bashcapabilities - Persistent login sessions — CLI’s
--persistentflag keeps login cookies across browser restarts - Multiple concurrent browsers — named sessions let you run separate browsers for different tasks
- Script-heavy workflows —
run-codecommand gives full Playwright API access for complex DOM manipulation
Our Production Experience: MCP First, CLI Fallback
After months of using both tools daily for social media automation, CMS operations, and web scraping at SaveDelete.com, here’s our real-world setup:
- Start with MCP — it’s the default in Claude Code and requires zero setup. For quick tasks (reading an article, checking a page), MCP is faster to use.
- Switch to CLI when MCP drops — MCP connections occasionally crash (error -32000). When this happens, CLI is the instant fallback with the same capabilities.
- Use CLI for long CMS sessions — publishing articles involves 20-40 browser interactions (fill forms, upload images, set TinyMCE content, save). CLI keeps this lean.
- Use CLI for persistent logins — the
--persistent --profile=/pathflag lets us maintain login sessions across browser restarts for X.com, Facebook, ChatGPT, and more.
The ideal pattern isn’t “pick one” — it’s use both, with MCP as primary and CLI as fallback. They share the same Playwright engine, so switching between them is seamless.
Command Mapping: MCP ↔ CLI
| Action | MCP Tool | CLI Command |
|---|---|---|
| Navigate | browser_navigate |
playwright-cli goto URL |
| Click element | browser_click |
playwright-cli click ref |
| Type text | browser_type |
playwright-cli type "text" |
| Take snapshot | browser_snapshot |
playwright-cli snapshot |
| Screenshot | browser_take_screenshot |
playwright-cli screenshot |
| Run custom code | browser_run_code |
playwright-cli run-code "async page => ..." |
| Upload file | browser_file_upload |
playwright-cli upload ./file |
| Handle dialog | browser_handle_dialog |
playwright-cli dialog-accept |
| Press key | browser_press_key |
playwright-cli press Key |
| Manage tabs | browser_tabs |
playwright-cli tab-new / tab-select |

Setup Guide
Installing Playwright MCP
Add to your MCP client configuration (e.g., Claude Desktop, VS Code):
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
Installing Playwright CLI
# Install globally
npm install -g @playwright/cli
# Start a browser session
playwright-cli open --headed --persistent
# Run commands
playwright-cli goto https://example.com
playwright-cli snapshot
playwright-cli click e15
How Playwright Compares to Other Browser Automation Tools
Playwright MCP and CLI aren’t the only options. Here’s how they stack up against the competition:
| Tool | AI Agent Support | Cross-Browser | Speed | Best For |
|---|---|---|---|---|
| Playwright MCP | Native (MCP protocol) | Chromium, Firefox, WebKit | Fast | AI agents in sandboxed environments |
| Playwright CLI | Shell-based (any agent) | Chromium, Firefox, WebKit | Fast | Production AI workflows, cost efficiency |
| Selenium | Limited (requires custom wrappers) | All major browsers | Slower | Legacy enterprise testing |
| Puppeteer | Limited (Node.js API only) | Chromium only | Fast | Chrome-specific automation |
| Cypress | None | Chromium, Firefox | Fast | Frontend developer testing (non-AI) |
Bottom line: For AI agent browser automation in 2026, Playwright (MCP or CLI) is the clear winner. It’s the only framework with native AI agent support, cross-browser compatibility, and an accessibility-tree-based approach that eliminates the need for vision models.
The Verdict
For most AI agent workflows in 2026, Playwright CLI is the better default. The 4x token savings, disk-based state management, persistent sessions, and full Playwright API access make it the practical choice (especially on a powerful development laptop) for production automation. CLI also works with any AI agent that has shell access — not just MCP-compatible clients.
Playwright MCP remains valuable for sandboxed environments, short exploratory tasks, and situations where you need the AI to deeply reason about page structure without managing files. It’s also the easier option if you’re just getting started — zero setup in MCP-compatible tools.
The best approach? Use both. Start with MCP for its convenience, fall back to CLI for long workflows or when MCP drops. They’re complementary tools from the same team, built on the same engine.
Frequently Asked Questions
Is Playwright MCP or CLI better for AI agents?
For most production AI agent workflows, Playwright CLI is better due to 4x lower token costs, disk-based state management, and persistent sessions. MCP is better for short exploratory tasks and sandboxed environments where the AI doesn’t have shell access.
How much do tokens cost with Playwright MCP vs CLI?
According to the Playwright team’s benchmarks, a typical browser automation task uses ~114,000 tokens with MCP versus ~27,000 with CLI — roughly a 4x difference. Early adopters report 4-10x savings depending on task complexity.
Can I use both Playwright MCP and CLI together?
Yes, and this is the recommended approach. Use MCP as your primary tool for convenience, and fall back to CLI for long workflows or when MCP connections drop. Note that MCP and CLI use separate browser instances — they don’t share tabs or state.
Does Playwright CLI work with Claude Code?
Yes. Claude Code has bash/shell access, making Playwright CLI a natural fit. You can run CLI commands via the Bash tool. Many Claude Code users set up CLI as a fallback for when the Playwright MCP server disconnects.