MCP Official source

Playwright MCP

Microsoft's MCP server for browser automation through structured accessibility snapshots.

Quick start

codex mcp add playwright npx "@playwright/mcp@latest"

What it does

Playwright MCP gives an agent browser navigation, interaction, inspection, and testing capabilities using structured page data. It is useful when an agent needs persistent browser state or iterative reasoning over a live interface.

Best for

  • Exploratory QA and regression checks
  • Navigating web apps and extracting structured page information
  • Browser workflows where the agent needs to inspect and adapt after each step

Security note

Browser access can expose authenticated sessions and sensitive page content. Restrict allowed origins and filesystem access, use isolated profiles when appropriate, and never treat the server itself as a security boundary.

Setup and browser isolation

Start with a fresh browser profile and a low-risk test site. Decide whether the workflow needs persistent sessions; if it does not, use ephemeral browser state. Restrict navigation to expected origins where the host configuration allows it, and do not import a personal profile merely to avoid a login step. Downloads and uploads also cross a data boundary, so constrain the directories available to the process.

Testing checklist

Verify that the agent can identify the correct element after navigation, recover from a changed page, and report failures instead of continuing with a guessed action. Keep assertions in normal test code when they must be deterministic. Record screenshots or traces only when their retention is appropriate for the page data being handled.

Alternatives

Use Playwright’s standard test runner for repeatable CI regression tests. Choose Playwright MCP for exploratory flows where the agent needs to inspect and adapt between steps. A purpose-built API integration is usually safer and faster when the browser is only standing in for a stable service endpoint.

How it differs from a test suite

Playwright MCP lets a model inspect the current page and decide the next browser action. That is useful for exploratory QA, reproducing an unclear bug, and navigating interfaces whose state changes during the run. A normal Playwright test is still the better artifact for a deterministic regression: it is faster to repeat, easier to review, and does not require a model to rediscover the path.

A practical workflow uses both. Let the agent explore the application and capture the smallest reliable reproduction, then convert stable findings into ordinary tests with explicit selectors and assertions. Accessibility snapshots help the agent reason over page structure without relying only on screenshots, but visual issues still require image inspection or a visual comparison system.

Configure the browser boundary

Decide whether the server may use a fresh profile, a named persistent profile, or a remote browser. A fresh isolated profile is the safest default for public-page testing. Do not reuse a personal browser profile merely to avoid logging in; it may expose sessions, downloads, history, extensions, and unrelated tabs. For authenticated testing, create a dedicated low-privilege account and seed only the state required by the scenario.

Restrict origins and capabilities where the host supports it. Keep downloads in a disposable directory, avoid mounting secrets, and require approval before purchases, messages, account changes, or other irreversible actions. The stdio transport keeps the server local to the client process; HTTP deployment introduces an additional network and authentication surface that must be protected separately.

Validate the installation

After connecting the server, test three operations on a non-sensitive site: open a page, inspect its accessible structure, and complete a harmless interaction. Confirm that the process exits when the MCP client closes and that its browser data lands in the expected location. For CI or repeated checks, pin the package version after evaluation instead of relying indefinitely on @latest.