The Playwright MCP server provides browser automation capabilities using structured accessibility snapshots rather than screenshots, making it ideal for LLMs to interact with web pages.
To install the Playwright MCP server, you'll need:
You can install the server with your MCP client using the standard configuration:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest"
]
}
}
}
Most MCP clients offer multiple ways to add the Playwright MCP server:
The Playwright MCP server accepts various command-line arguments to customize its behavior:
# Run with custom viewport size
npx @playwright/mcp@latest --viewport-size=1280x720
# Run in headless mode
npx @playwright/mcp@latest --headless
# Specify browser type
npx @playwright/mcp@latest --browser firefox
# Enable additional capabilities
npx @playwright/mcp@latest --caps vision,pdf
The server supports three profile modes:
Persistent profile (default): Stores browser state between sessions
# Default behavior, no special flags needed
npx @playwright/mcp@latest
Isolated profile: Creates a temporary profile for each session
npx @playwright/mcp@latest --isolated
Browser Extension: Connects to existing browser tabs
npx @playwright/mcp@latest --extension
Set up the browser state before automation:
# Load cookies and storage from a file
npx @playwright/mcp@latest --storage-state=auth.json
# Run initialization script before automation
npx @playwright/mcp@latest --init-script=setup.js
# Initialize page with custom TypeScript code
npx @playwright/mcp@latest --init-page=init-page.ts
Instead of command-line arguments, you can use a JSON configuration file:
npx @playwright/mcp@latest --config playwright-mcp-config.json
Example configuration file:
{
"browser": {
"browserName": "chromium",
"launchOptions": {
"headless": false
},
"contextOptions": {
"viewport": {
"width": 1280,
"height": 720
}
}
},
"capabilities": ["core", "pdf"],
"testIdAttribute": "data-testid"
}
To run as a standalone server (useful for environments without displays):
npx @playwright/mcp@latest --port 8931
Then configure your MCP client:
{
"mcpServers": {
"playwright": {
"url": "http://localhost:8931/mcp"
}
}
}
The Playwright MCP server provides several tool categories:
--caps=vision)--caps=pdf)--caps=testing)--caps=tracing)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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json2. Add this to your configuration file:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect