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.
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.
The standard configuration works with most MCP clients:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest"
]
}
}
}
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:
Cursor Settings → MCP → Add new MCP Servercommand type with the command npx @playwright/mcp@latestFor other clients, consult the client-specific installation instructions for your preferred MCP client.
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 millisecondsFor more complex configurations, you can use a JSON configuration file:
npx @playwright/mcp@latest --config path/to/config.json
Playwright MCP supports different profile modes:
All login information is stored in a persistent profile. Default locations:
%USERPROFILE%\AppData\Local\ms-playwright\mcp-{channel}-profile~/Library/Caches/ms-playwright/mcp-{channel}-profile~/.cache/ms-playwright/mcp-{channel}-profileYou can override the location with the --user-data-dir argument.
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}"
]
}
}
}
You can connect to existing browser tabs using the Playwright MCP Chrome Extension, which leverages your logged-in sessions and browser state.
You can configure initial browser state in several ways:
--user-data-dir for persistent browser data--storage-state to load cookies and local storage from a file--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 });
};
--init-script with a JavaScript file that will run in every page:// init-script.js
window.isPlaywrightMCP = true;
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"
}
}
}
Playwright MCP provides a rich set of tools for browser automation, including:
browser_navigate, browser_navigate_back)browser_click, browser_type, browser_hover)browser_fill_form, browser_select_option)browser_evaluate, browser_run_code)browser_snapshot, browser_take_screenshot)browser_resize, browser_close)browser_file_upload)Additional capabilities can be enabled with the --caps flag for features like PDF generation, vision-based interaction, and 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