Use the Playwright CLI safely
Playwright MCP and the Playwright CLI both connect AI agents to real browsers, but differ sharply in mode and safety needs.
- Skill Road
- Use the Playwright CLI safely
Published on 09.09.2026
Playwright MCP and the Playwright CLI at a glance
Playwright is an open-source browser automation and end-to-end testing framework developed by Microsoft. Around this core tool, two distinct paths have emerged for connecting AI-powered coding agents to real browsers: the Playwright MCP server and the newer Playwright CLI. The MCP server relies on the Model Context Protocol, an open standard for exchanging structured data between applications and AI models, and gives the connected language model tools to open pages, fill out forms, take screenshots, or inspect network traffic. The Playwright CLI, according to the provider, takes a different approach: instead of sending tool calls over a protocol, the agent runs ordinary shell commands and pulls in compact, on-demand instruction sets called skills only when it actually needs them. Both approaches build on the same underlying automation engine but differ substantially in cost, intended use, and operating mode.
When each approach makes sense
Per the official documentation, the MCP server suits specialized, exploratory automation scenarios where an AI model interacts with a web page step by step, working from accessibility-based state snapshots rather than interpreting pixels or screenshots. This mode opens a visible browser by default, which makes it easier to follow along but also consumes more compute and more context space in the language model, since tool schemas and page snapshots ride along with every request. The CLI variant, by contrast, targets coding agents such as Claude Code or GitHub Copilot that work across large codebases: it runs headless by default, returns terse text output, and loads specialized knowledge only when actually required. That keeps the language model's context usage lower, which matters noticeably during large-scale development tasks.
Setup and safe usage
Installing the MCP server means adding an entry to the target MCP client's configuration file that launches the server via npx; the CLI variant, in contrast, is installed globally as its own npm package and then invoked through a dedicated command-line tool. Both require Node.js, and the first run downloads the associated browser binaries. For safe use: automated browser sessions should only run against trusted, clearly scoped target sites, since an agent can, in a worst case, submit forms, trigger purchases, or expose credentials. According to the documentation, saved login state and cookies persist between sessions by default, which adds convenience but also means sensitive session data sits locally and needs to be protected accordingly. Advanced capabilities such as network mocking, storage access, or running unvetted code snippets should only be enabled deliberately, for tasks that genuinely need those permissions.
Practical value and limits
In practice, the MCP server works well for interactive assistance scenarios, for example when a user wants to try out, test, or analyze a web page directly inside a chat, while the CLI variant plays to its strengths in automated development and testing workflows within larger projects, where many small automation steps run without each one consuming expensive model context. Both approaches, however, hit limits once target sites deploy aggressive bot detection, complex multi-step logins, or dynamic interfaces that are hard to pin down; in those cases human oversight or additional error handling remains necessary. Teams that want to use both tools in the same project should first decide which tool serves which purpose, to avoid duplicate browser sessions and conflicting automation steps.
Frequently asked questions
Why take a new snapshot after navigation?
Navigation and DOM changes can make element references stale. A new snapshot provides the current reference for the next action.
Is a local browser run fully local?
Not necessarily. The browser may run locally while a connected agent sends content to a model provider.