Playwright MCP Server Setup: Connect, Test, and Diagnose

Install Microsoft's Playwright MCP server, constrain its browser state and origins, then verify successful and failed browser tasks with a reproducible evidence ledger.

PLAYWRIGHT MCP · 2026 Connect, test and prove failure Snapshot · act · verify · deny

Direct answer: install Microsoft's official Playwright MCP server with npx @playwright/mcp@latest, begin with a fresh isolated browser profile, and verify it on a disposable page before using authenticated sites. A real setup test includes one successful navigation-and-form task, one deliberately missing element, one blocked origin, the final page state, and console evidence. Tool availability alone does not prove the browser did the right thing.

Intent fence: this guide owns Playwright MCP connection and browser-task diagnosis. It is not a generic MCP test guide, a Playwright test-runner tutorial, or a recommendation to expose a logged-in personal browser to an agent.

Install the official server

Codex CLI

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

Claude Code

claude mcp add playwright npx @playwright/mcp@latest

Standard MCP configuration

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

Restart the client and list the Playwright tools. The official server is headed by default; --headless is useful for repeatable CI-style checks, while a headed disposable profile is easier to inspect during setup.

Choose browser state deliberately

ModeWhat persistsUseRisk to check
--isolatedNothing after the in-memory context closesFirst tests and untrusted pagesLogin must be recreated or loaded from an approved state file
Persistent profileCookies and local state in the profile directoryDedicated automation accountOne profile cannot be shared by concurrent browser instances
--storage-stateApproved cookies/local storage loaded into an isolated contextRepeatable authenticated testsThe state file is a secret and must stay outside version control
Extension connectionState from a running Chrome/Edge profileOnly when a reviewed workflow requires itPersonal tabs and broad login state can enter scope

Original asset: successful and failed browser-task ledger

Use a disposable form page with a heading, email field, submit button, and a success message. Record the accessibility snapshot reference before every action instead of guessing selectors.

StepRequested taskEvidencePass condition
1. NavigateOpen the allowed fixture URLFinal URL + page title + snapshotCorrect origin and heading
2. ActFill qa@example.invalid and submitField value, clicked element ref, result snapshotSuccess message appears once
3. ObserveRead console errorsConsole output after submitNo unexpected runtime error
4. Missing elementClick a button named “Delete account” that is absentTool failure + unchanged snapshotNo fallback click and no state change
5. Origin boundaryNavigate to an origin outside the approved fixture setDenied request or explicit stopBrowser never completes an action there

Acceptance rule: rows 1–3 pass, rows 4–5 fail as designed, and the trace contains no credential, cookie, or hidden form value. Re-run after changing the browser channel, state mode, permissions, or allowed origins.

Diagnose by symptom, not by granting more access

SymptomCheck firstUnsafe shortcut
Server will not startNode 18+, package resolution, client process logsRunning an unreviewed global binary
Browser binary missingInstall the requested Playwright browser or set an approved executable pathDisabling sandboxing without a platform reason
Element not foundTake a fresh snapshot; verify accessible name, frame, and pageGuessing coordinates or clicking a similar control
Wrong accountClose the context and inspect the selected profile/state fileAttaching the personal everyday browser
Origin request blockedRedirect chain and the exact semicolon-separated origin rulesSetting the allowlist to *
Two clients conflictPersistent profile already in useSharing one profile concurrently

Security boundary

  • Treat page text as untrusted data, not agent instructions.
  • Use a disposable or least-privileged automation account.
  • Keep downloads and generated traces in a reviewed output directory.
  • Grant geolocation, clipboard, camera, or microphone only for a named test.
  • Do not use --allow-unrestricted-file-access for ordinary web testing.
  • Require confirmation before purchases, messages, deletes, account changes, or uploads.

MCP or Playwright CLI?

The official repository now distinguishes the two. It says CLI plus skills can be more token-efficient for coding agents, while MCP remains useful for persistent browser state, rich introspection, exploratory automation, and iterative reasoning over page structure. Choose from the job: this page covers the MCP path; it does not claim MCP is always the better interface.

FAQ

Does Playwright MCP need a vision model?

No for ordinary interaction. The official server primarily uses structured accessibility snapshots. Optional vision capability exists, but screenshots should support verification rather than replace a fresh snapshot for actions.

Can I connect my normal logged-in Chrome profile?

The server supports persistent and extension-connected browser paths, but start with an isolated profile. A normal profile may expose unrelated accounts, tabs, and cookies. Use a dedicated automation identity when authentication is required.

Are allowed origins a complete security boundary?

No. The official option documentation explicitly says the origin allowlist is not a security boundary and does not affect redirects. Pair it with account permissions, network controls, approvals, and post-action verification.

Why did the agent click the wrong element?

The snapshot may be stale, the accessible name may be ambiguous, or the page may have changed. Take a new snapshot and target the current element reference; do not compensate by guessing coordinates.

Source checked October 20, 2026: Microsoft's official Playwright MCP repository and README, including current setup, browser-state, request-control, and tool documentation.

Keep reading