Playwright Browser Automation MCP server

Enables web browser control for navigating websites, capturing page snapshots, interacting with elements, and taking screenshots through Playwright's automation capabilities.
Back to servers
Setup instructions
Provider
Microsoft
Release date
Mar 22, 2025
Language
TypeScript
Package
Stats
10.38M downloads
23.4K stars

The Playwright MCP server enables LLMs to interact with web pages through structured accessibility snapshots rather than screenshots. This approach is faster, more lightweight, and provides deterministic tool application without requiring vision models.

Installation

To install the Playwright MCP server, you'll need Node.js 18 or newer and an MCP client like VS Code, Cursor, Windsurf, Claude Desktop, or Goose.

Standard Configuration

The standard configuration works with most MCP clients:

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

Client-Specific Installation

Many MCP clients provide one-click installation options or CLI commands to add the Playwright MCP server.

For VS Code:

code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'

For Cursor, you can use the UI installation:

  1. Go to Cursor SettingsMCPAdd new MCP Server
  2. Name it to your liking
  3. Use command type with the command npx @playwright/mcp@latest

For other clients, consult the client-specific installation instructions for your preferred MCP client.

Configuration Options

The Playwright MCP server supports numerous configuration options that can be provided as arguments:

npx @playwright/mcp@latest --headless --browser chrome

Key configuration options include:

  • --browser <browser>: Specify which browser to use (chrome, firefox, webkit, msedge)
  • --headless: Run in headless mode (default is headed mode)
  • --isolated: Keep browser profile in memory without saving to disk
  • --viewport-size <size>: Set browser viewport size (e.g., "1280x720")
  • --user-agent <ua string>: Specify a custom user agent
  • --proxy-server <proxy>: Specify proxy server
  • --timeout-navigation <timeout>: Set navigation timeout in milliseconds

Configuration File

For more complex configurations, you can use a JSON configuration file:

npx @playwright/mcp@latest --config path/to/config.json

User Profiles

Playwright MCP supports different profile modes:

Persistent Profile (Default)

All login information is stored in a persistent profile. Default locations:

  • Windows: %USERPROFILE%\AppData\Local\ms-playwright\mcp-{channel}-profile
  • macOS: ~/Library/Caches/ms-playwright/mcp-{channel}-profile
  • Linux: ~/.cache/ms-playwright/mcp-{channel}-profile

You can override the location with the --user-data-dir argument.

Isolated Mode

In isolated mode, each session runs in an isolated profile:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": [
        "@playwright/mcp@latest",
        "--isolated",
        "--storage-state={path/to/storage.json}"
      ]
    }
  }
}

Browser Extension Mode

You can connect to existing browser tabs using the Playwright MCP Chrome Extension, which leverages your logged-in sessions and browser state.

Initial State Configuration

You can configure initial browser state in several ways:

For Storage State:

  • Use --user-data-dir for persistent browser data
  • Use --storage-state to load cookies and local storage from a file

For Page Setup:

  • Use --init-page with a TypeScript file to run code on the page object:
// init-page.ts
export default async ({ page }) => {
  await page.context().grantPermissions(['geolocation']);
  await page.context().setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
};
  • Use --init-script with a JavaScript file that will run in every page:
// init-script.js
window.isPlaywrightMCP = true;

Standalone MCP Server

For headless environments or worker processes, you can run the MCP server with HTTP transport:

npx @playwright/mcp@latest --port 8931

Then configure your MCP client to connect to the HTTP endpoint:

{
  "mcpServers": {
    "playwright": {
      "url": "http://localhost:8931/mcp"
    }
  }
}

Core Tools

Playwright MCP provides a rich set of tools for browser automation, including:

  • Browser navigation (browser_navigate, browser_navigate_back)
  • Element interaction (browser_click, browser_type, browser_hover)
  • Form handling (browser_fill_form, browser_select_option)
  • Page evaluation (browser_evaluate, browser_run_code)
  • Snapshot capture (browser_snapshot, browser_take_screenshot)
  • Window management (browser_resize, browser_close)
  • File operations (browser_file_upload)

Additional capabilities can be enabled with the --caps flag for features like PDF generation, vision-based interaction, and tracing.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "playwright" '{"command":"npx","args":["@playwright/mcp@latest"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later