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
13.12M downloads
24.2K stars

The Playwright MCP server provides browser automation capabilities for LLMs through structured accessibility snapshots. It works with Playwright to enable web page interaction without requiring screenshots or 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, or Claude Desktop. Use the standard configuration in your client:

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

Configuration Options

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

Basic Options

npx @playwright/mcp@latest --browser <browser> # chrome, firefox, webkit, msedge
npx @playwright/mcp@latest --headless # run in headless mode (default is headed)
npx @playwright/mcp@latest --viewport-size 1280x720 # set viewport size

User Profile Options

You can run the server with different profile configurations:

  • Persistent profile (default): Maintains login information between sessions
  • Isolated profile: Creates a fresh session each time
# Run in isolated mode with specific storage state
npx @playwright/mcp@latest --isolated --storage-state=path/to/storage.json

Browser Initial State

You can configure the initial browser state using:

# Load storage state from file (cookies, localStorage)
npx @playwright/mcp@latest --storage-state=path/to/storage.json

# Run custom setup code on the page
npx @playwright/mcp@latest --init-page=init-page.ts

# Add initialization scripts to every page
npx @playwright/mcp@latest --init-script=init-script.js

Using a Configuration File

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

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

Example configuration file:

{
  "browser": {
    "browserName": "chromium",
    "isolated": true,
    "launchOptions": {
      "headless": false
    },
    "contextOptions": {
      "viewport": {
        "width": 1280,
        "height": 720
      }
    }
  },
  "server": {
    "port": 8931,
    "host": "localhost"
  },
  "capabilities": ["core", "pdf"],
  "saveTrace": true
}

Running as a Standalone Server

To run the MCP server as a standalone HTTP service:

npx @playwright/mcp@latest --port 8931

Then configure your client to connect to this URL:

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

Core Tools and Features

The Playwright MCP server provides a rich set of tools for browser automation:

Page Navigation

  • Navigate to URLs
  • Go back in history
  • Close the browser

Element Interaction

  • Click on elements
  • Type text into fields
  • Select options from dropdowns
  • Hover over elements
  • Drag and drop

Form Handling

  • Fill multiple form fields at once
  • Upload files
  • Handle dialogs

Page State

  • Capture page snapshots
  • Take screenshots
  • Resize the browser window
  • Run custom JavaScript code
  • Wait for text or time

Advanced Features (Opt-in)

  • PDF generation (with --caps=pdf)
  • Coordinate-based interactions (with --caps=vision)
  • Test assertions (with --caps=testing)
  • Tracing (with --caps=tracing)

Example Usage

Here's a simple example of how to use the MCP server to navigate and interact with a web page:

  1. Navigate to a URL:

    browser_navigate with URL "https://example.com"
    
  2. Type text into a field:

    browser_type with element "Search field", ref "element-ref-from-snapshot", text "search query"
    
  3. Click a button:

    browser_click with element "Submit button", ref "element-ref-from-snapshot"
    
  4. Take a snapshot to view the page structure:

    browser_snapshot
    

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