Playwright MCP is a Model Context Protocol server that provides browser automation capabilities using Playwright. It enables Large Language Models (LLMs) to interact with web pages through structured accessibility snapshots, which eliminates the need for screenshots or visually-tuned models.
You can install the Playwright MCP server in VS Code using the VS Code CLI:
# For VS Code
code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'
# For VS Code Insiders
code-insiders --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'
After installation, the Playwright MCP server will be available for use with your GitHub Copilot agent in VS Code.
Add the following to your configuration file:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest"
]
}
}
}
The Playwright MCP server offers two operational modes:
To enable Vision Mode, add the --vision
flag:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest",
"--vision"
]
}
}
}
For background or batch operations, you can run the browser without a GUI:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"@playwright/mcp@latest",
"--headless"
]
}
}
}
When running on a system without display, use the --port
flag:
npx @playwright/mcp@latest --port 8931
Then in your configuration:
{
"mcpServers": {
"playwright": {
"url": "http://localhost:8931/sse"
}
}
}
Playwright MCP creates a browser profile in the following locations:
%USERPROFILE%\AppData\Local\ms-playwright\mcp-chrome-profile
~/Library/Caches/ms-playwright/mcp-chrome-profile
~/.cache/ms-playwright/mcp-chrome-profile
You can delete this directory to clear the browser state between sessions.
These commands work with the default snapshot mode:
browser_navigate: Navigate to a URL
{"url": "https://example.com"}
browser_navigate_back: Go back to the previous page
browser_navigate_forward: Go forward to the next page
browser_click: Click on an element
{
"element": "Submit button",
"ref": "element-ref-from-snapshot"
}
browser_hover: Hover over an element
{
"element": "Dropdown menu",
"ref": "element-ref-from-snapshot"
}
browser_type: Type text into an element
{
"element": "Search input field",
"ref": "element-ref-from-snapshot",
"text": "search query",
"submit": true
}
browser_select_option: Select dropdown options
{
"element": "Country dropdown",
"ref": "element-ref-from-snapshot",
"values": ["United States"]
}
{"url": "https://example.com"}
{"index": 2}
{"index": 1}
browser_file_upload: Upload files
{"paths": ["/path/to/file1.jpg", "/path/to/file2.pdf"]}
browser_pdf_save: Save the current page as PDF
browser_wait: Wait for a specified time
{"time": 3}
browser_close: Close the page
browser_install: Install the browser specified in the config
The server supports several command-line options:
--browser <browser>
: Specify which browser to use (chrome, firefox, webkit, msedge)--headless
: Run browser in headless mode--port <port>
: Port to listen on for SSE transport--user-data-dir <path>
: Path to the user data directory--vision
: Use screenshot-based interaction mode--caps <caps>
: Specify comma-separated capabilities to enable--cdp-endpoint <endpoint>
: Connect to a specific CDP endpoint--executable-path <path>
: Use a specific browser executableThere 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 > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.