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.
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"
]
}
}
}
The Playwright MCP server supports numerous configuration options that can be provided as arguments:
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
You can run the server with different profile configurations:
# Run in isolated mode with specific storage state
npx @playwright/mcp@latest --isolated --storage-state=path/to/storage.json
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
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
}
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"
}
}
}
The Playwright MCP server provides a rich set of tools for browser automation:
--caps=pdf)--caps=vision)--caps=testing)--caps=tracing)Here's a simple example of how to use the MCP server to navigate and interact with a web page:
Navigate to a URL:
browser_navigate with URL "https://example.com"
Type text into a field:
browser_type with element "Search field", ref "element-ref-from-snapshot", text "search query"
Click a button:
browser_click with element "Submit button", ref "element-ref-from-snapshot"
Take a snapshot to view the page structure:
browser_snapshot
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