The Playwright MCP Server is the bridge between Claude AI and your running application. Once connected, Claude can navigate to any URL, read the live DOM, interact with elements, and generate production-ready Playwright tests — all from plain English. But you have to get the setup right first.
This guide is laser-focused on the setup. No theory, no conceptual overview — just every command, config file, flag, and fix you need to go from zero to a working MCP connection in under 10 minutes. If you want a conceptual introduction to what MCP is and what it can do, read our Playwright MCP Server + Claude AI overview first.
Prerequisites
Before you start, verify these are in place:
- Node.js 18+ — run
node --versionto check. If you're below 18, download the LTS version. - A Playwright project — if you don't have one yet:
npm init playwright@latest. See our Playwright for beginners guide for a walkthrough. - Claude access — you need one of: Claude Desktop (free tier works for testing), Claude Pro ($20/month for heavier use), Claude Code CLI, or an Anthropic API key.
# Check Node.js version (must be 18+) node --version # v20.15.0 ✓ # Check npm is available npm --version # 10.8.1 ✓ # Check npx is available (ships with npm 5.2+) npx --version # 10.8.1 ✓
Step 1: Install Playwright MCP Server
You have three installation options. Pick the one that fits your workflow:
| Method | Command | When to use |
|---|---|---|
| On-demand (npx) | npx @playwright/mcp@latest |
Default choice. No install needed — always runs the latest version. |
| Global install | npm install -g @playwright/mcp |
Faster startup (~2s vs ~5s). Good if you use MCP daily. |
| Project dependency | npm install --save-dev @playwright/mcp |
Pin a specific version. Good for teams that need reproducibility. |
Recommendation: Start with the npx approach. It always pulls the latest version and requires zero setup. Switch to global install later if the 3-second startup difference matters to your workflow.
To verify the package is accessible, run it directly:
# Should start the MCP server and wait for connections npx @playwright/mcp@latest # You'll see output like: # Playwright MCP Server listening on stdio # Press Ctrl+C to stop
If you see the "listening" message, the package works. Press Ctrl+C to stop it — your AI client will start it automatically.
Step 2A: Configure Claude Desktop
Claude Desktop is the GUI app for Mac, Windows, and Linux. This is the easiest way to get started with Playwright MCP Server.
Open the Claude Desktop config file
Go to Claude Desktop → Settings → Developer → Edit Config. This opens your claude_desktop_config.json file. If it doesn't exist yet, Claude will create it.
Config file locations by platform:
# macOS ~/Library/Application Support/Claude/claude_desktop_config.json # Windows %APPDATA%\Claude\claude_desktop_config.json # Linux ~/.config/Claude/claude_desktop_config.json
Add the Playwright MCP Server entry
Paste this JSON into your config. If the file already has content, merge the mcpServers object with any existing entries.
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
Restart Claude Desktop
Fully quit Claude Desktop (not just close the window) and reopen it. Look for the hammer/tools icon in the chat input area — click it and you should see Playwright listed as a connected tool.
Windows users: If Claude can't find npx, use the full path: "command": "C:\\Program Files\\nodejs\\npx.cmd". This is the most common Windows setup issue.
Step 2B: Configure Claude Code (CLI)
Claude Code is the terminal-based Claude client — recommended for developers. You can configure MCP servers at the project level or globally.
Option A: Project-level config (recommended)
This keeps the MCP config scoped to your Playwright project. Create or edit .claude/settings.json in your project root:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"],
"env": {}
}
}
}
Option B: Global config
If you want Playwright MCP available in every Claude Code session, add it to your global settings:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
Start a new Claude Code session (claude in your terminal). Type /mcp to verify Playwright appears as a connected server.
Step 2C: Configure VS Code
If you use the Claude extension for VS Code, you can configure MCP servers directly in the extension settings:
Open VS Code settings
Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux), type "Claude: Settings", and open the Claude extension settings.
Add MCP server configuration
Find the MCP Servers section and add a new entry with the same JSON structure used for Claude Desktop.
Reload the extension
Run "Developer: Reload Window" from the command palette. Playwright will appear as an available tool in the Claude sidebar.
Alternatively, add the config directly to your workspace .vscode/settings.json:
{
"claude.mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
}
}
Step 3: Verify Your Setup Works
Run this quick smoke test in any Claude client. Type:
Navigate to https://playwright.dev and take a snapshot.
Tell me what the page title is and list the main navigation links.
If everything is configured correctly, Claude will:
- Launch a browser via the MCP server
- Navigate to the Playwright docs site
- Return the page's accessibility tree with the title and navigation elements
If this works, your setup is complete. You're ready to start generating tests with Claude + MCP.
Advanced Configuration Options
The basic setup works for most people, but Playwright MCP Server has several flags that unlock more powerful workflows.
Headed mode (see the browser)
By default, MCP runs headless — no visible browser window. Add --headed to watch Claude interact with your app in real time:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--headed"]
}
}
}
When to use headed mode: Great for demos, debugging MCP issues, and learning how Claude interacts with pages. Switch back to headless for daily use — it's faster and doesn't steal window focus.
Browser selection
MCP defaults to Chromium. You can switch to Firefox or WebKit:
# Firefox "args": ["@playwright/mcp@latest", "--browser", "firefox"] # WebKit (Safari engine) "args": ["@playwright/mcp@latest", "--browser", "webkit"]
Custom viewport size
Set a specific viewport to test responsive layouts or mobile views:
"args": ["@playwright/mcp@latest", "--viewport-size", "375,812"]
Saved authentication state
Testing pages behind login is one of the biggest challenges with AI-driven testing. Playwright MCP Server solves this with saved auth state:
Log in manually once and save the state
Use Playwright's storageState to capture cookies, localStorage, and session tokens after logging in.
import { chromium } from 'playwright'; const browser = await chromium.launch({ headless: false }); const context = await browser.newContext(); const page = await context.newPage(); // Navigate and log in manually in the browser window await page.goto('https://your-app.com/login'); await page.pause(); // Browser stays open — log in manually // After logging in, save the state await context.storageState({ path: './auth/state.json' }); await browser.close();
Point MCP Server to the saved auth directory
Add the --saved-auth-dir flag to your config. Claude will now start every session already logged in.
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest",
"--saved-auth-dir",
"./auth"
]
}
}
}
Security: Add your auth state directory to .gitignore. It contains session tokens that should never be committed to version control.
Complete flags reference
| Flag | Default | Description |
|---|---|---|
--headed |
off | Show the browser window while Claude navigates |
--browser |
chromium | Browser engine: chromium, firefox, or webkit |
--viewport-size |
1280,720 | Viewport dimensions as width,height |
--saved-auth-dir |
none | Directory containing saved storageState for authenticated sessions |
--port |
stdio | Run as HTTP server on a specific port instead of stdio |
--host |
localhost | Host to bind when using --port |
Environment Variables & Proxy
If your application runs behind a corporate proxy or needs specific environment variables, pass them through the MCP config:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"],
"env": {
"HTTP_PROXY": "http://proxy.company.com:8080",
"HTTPS_PROXY": "http://proxy.company.com:8080",
"NO_PROXY": "localhost,127.0.0.1",
"BASE_URL": "http://localhost:3000"
}
}
}
}
Troubleshooting: 10 Common Setup Issues
If your setup isn't working, find your error below. These cover 95% of Playwright MCP Server setup problems reported in 2026.
1. "npx: command not found"
Cause: Node.js isn't installed or isn't on your PATH.
Fix: Install Node.js 18+ from nodejs.org. On Windows, use the MSI installer which adds Node to PATH automatically. On Mac, use brew install node.
2. "Cannot find module @playwright/mcp"
Cause: The package doesn't exist in the npx cache and the network request failed.
Fix: Run npx @playwright/mcp@latest manually in your terminal first. If you're behind a firewall, check your proxy settings or install globally: npm install -g @playwright/mcp.
3. Claude Desktop shows no tools / Playwright not listed
Cause: Config file has a JSON syntax error, or Claude wasn't fully restarted.
Fix: Validate your JSON at jsonlint.com. Then fully quit Claude Desktop (Cmd+Q on Mac, not just close window) and reopen it.
4. "Browser closed unexpectedly" or "Browser executable not found"
Cause: Playwright browsers aren't installed.
Fix: Run npx playwright install to download Chromium, Firefox, and WebKit. For just Chromium: npx playwright install chromium.
# Install all browsers npx playwright install # Install Chromium only (faster) npx playwright install chromium # Install with system dependencies (Linux) npx playwright install --with-deps
5. Windows: "spawn npx ENOENT"
Cause: Claude can't find npx on Windows because it's not in the system PATH for the Claude process.
Fix: Use the full path to npx:
{
"mcpServers": {
"playwright": {
"command": "C:\\Program Files\\nodejs\\npx.cmd",
"args": ["@playwright/mcp@latest"]
}
}
}
6. "Connection refused" when navigating to localhost
Cause: Your dev server isn't running, or it's on a different port than what you told Claude.
Fix: Start your dev server first (npm run dev), then ask Claude to navigate. Verify the port matches.
7. MCP Server starts but Claude says "tool call failed"
Cause: Usually a version mismatch or the MCP Server crashed mid-session.
Fix: Update to the latest version: npx @playwright/mcp@latest. If you installed globally, run npm update -g @playwright/mcp. Restart Claude.
8. Pages behind login return "redirected to /login"
Cause: No saved authentication state — Claude starts a fresh browser session each time.
Fix: Use the saved auth state approach described above. Save your login cookies once, then point MCP to the auth directory.
9. Linux: "No usable sandbox"
Cause: Chromium needs a sandbox and the user namespace isn't configured.
Fix: Install system dependencies: npx playwright install --with-deps. If running in Docker, add --no-sandbox to the browser launch args or use the official Playwright Docker image.
10. Slow startup (~15+ seconds)
Cause: npx downloads the package fresh each time if your npm cache is cold.
Fix: Install globally (npm install -g @playwright/mcp) and change your config to use the global binary:
{
"mcpServers": {
"playwright": {
"command": "playwright-mcp",
"args": []
}
}
}
Platform-Specific Configs (Copy & Paste)
Here are ready-to-use configs for the three most common setups:
macOS + Claude Desktop + Headed Mode
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest", "--headed"]
}
}
}
Windows + Claude Desktop + Full Path
{
"mcpServers": {
"playwright": {
"command": "C:\\Program Files\\nodejs\\npx.cmd",
"args": ["@playwright/mcp@latest", "--headed"]
}
}
}
Linux + Claude Code + Auth State + Firefox
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest",
"--browser", "firefox",
"--saved-auth-dir", "./auth"
],
"env": {}
}
}
}
MCP Server vs Playwright Codegen: When to Use Which
Both tools generate test code, but they work differently. Use the right tool for the right job:
| Playwright MCP Server | Playwright Codegen | |
|---|---|---|
| How it works | AI reads the page and writes tests from descriptions | Records your manual clicks and generates code |
| Input | Plain English prompt | Manual browser interaction |
| Selector quality | Role-based (getByRole, getByLabel) — highly resilient | Mixed — often falls back to CSS/XPath |
| Test structure | Full tests with assertions, edge cases, and POM support | Linear recording — no assertions by default |
| Best for | Generating entire test suites, debugging, self-healing | Quick recordings, learning selectors, simple flows |
| Requires | Claude subscription or API key | Nothing — built into Playwright |
For a deep dive into Codegen, see our Playwright Codegen tutorial. For most teams in 2026, MCP + Claude is the primary workflow and Codegen is a quick supplementary tool.
What to Do After Setup
Now that your Playwright MCP Server is running, here's your learning path:
- Generate your first test — follow our MCP + Claude test generation guide
- Connect MCP to Playwright Agents — run
npx playwright init agents --loop claudeto scaffold the tri-agent pipeline (planner, generator, healer) with MCP as the browser interface. See the Playwright Test Agents guide for the full setup. - Learn self-healing locators — see self-healing locators with AI
- Set up CI/CD with Docker — run MCP-powered tests headlessly in CI using the official Playwright Docker image:
# .github/workflows/playwright-mcp.yml name: Playwright MCP Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest container: image: mcr.microsoft.com/playwright:v1.56.0-noble steps: - uses: actions/checkout@v4 - name: Install dependencies run: npm ci - name: Run Playwright tests (heal mode) run: npx playwright test --agent heal env: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- Master the full workflow — the Playwright + Claude AI course covers everything end to end
Frequently Asked Questions
How do I install Playwright MCP Server?
Run npx @playwright/mcp@latest — no separate install needed. For faster startup, install globally with npm install -g @playwright/mcp. Then add the server to your Claude Desktop, Claude Code, or VS Code MCP settings.
Does Playwright MCP Server work on Windows, Mac, and Linux?
Yes. It works on all three platforms. On Windows, you may need to use the full path to npx (C:\Program Files\nodejs\npx.cmd) in your config if Claude can't find it on the PATH.
Can I use Playwright MCP Server with VS Code?
Yes. Configure it in the Claude VS Code extension settings or via Claude Code in VS Code's integrated terminal. Both approaches give Claude full browser access through the MCP Server.
Why is Playwright MCP Server not connecting?
The most common causes: Node.js not installed or below v18, npx not on your system PATH, a JSON syntax error in your config, or not fully restarting Claude after editing the config. Test the server manually first: npx @playwright/mcp@latest.
Can Playwright MCP Server test pages behind login?
Yes. Use the --saved-auth-dir flag pointing to a directory containing saved authentication state. Log in manually once, save the state with storageState, and the MCP Server reuses those cookies and tokens for all sessions.
What is the difference between Playwright MCP Server and Playwright Codegen?
Codegen records your manual browser interactions and generates code from them. MCP Server gives Claude direct browser access so it autonomously navigates, inspects, and generates tests from plain English — no manual recording needed. MCP also supports debugging, self-healing, and POM generation.
How do I use Playwright MCP Server with Playwright Test Agents?
Run npx playwright init agents --loop claude after setting up the MCP Server. This scaffolds a CLAUDE.md that tells Claude Code how to invoke the planner, generator, and healer agents — with MCP providing the live browser connection. The agents use MCP to capture ARIA snapshots and navigate your application during test generation and healing.
Can Playwright MCP Server run in Docker for CI/CD?
Yes. Use the official mcr.microsoft.com/playwright Docker image, which includes all browser binaries. Set your ANTHROPIC_API_KEY as a CI secret and run npx playwright test --agent heal for heal-only CI mode. This prevents agents from generating new tests in CI while still auto-fixing broken selectors on every run.
What is the difference between Playwright MCP and Claude in Chrome?
Playwright MCP runs a controlled Playwright browser that Claude interacts with via structured tool calls — ideal for test generation and CI. Claude in Chrome uses a browser extension to give Claude access to your existing Chrome session — better for one-off debugging and accessibility checks. See the full MCP vs Claude in Chrome comparison.
How do I update Playwright MCP Server to the latest version?
Run npm install -g @playwright/mcp@latest to update the global install, or npx @playwright/mcp@latest always uses the latest version without a global install. Check the current version with npx @playwright/mcp --version. Update your Playwright test package separately with npm install @playwright/test@latest — the two packages version independently.
Does Playwright MCP Server work with Cursor and Windsurf?
Yes. Any MCP-compatible client works with the Playwright MCP Server. For Cursor, add the server to your .cursor/mcp.json. For Windsurf, add it to .windsurf/mcp.json. The config format is identical to Claude Code's .mcp.json — same command and args structure. Only the file path differs per client.
Asim Noaman
Senior QA Automation Engineer & AI Testing Specialist
With years of hands-on experience building test automation frameworks for production applications, Asim specializes in combining traditional QA methodologies with cutting-edge AI tools. He has helped teams adopt Playwright and AI-driven testing workflows to ship faster with fewer bugs.