Playwright-MCP is a tool that bridges the gap between AI assistants and web browsers, allowing AI tools to understand and interact with web pages in real-time. This enables the creation of accurate, non-flaky Playwright tests by giving AI assistants direct access to page DOM, elements, and interactions, rather than forcing them to make educated guesses.
Before installing playwright-mcp, ensure you have:
playwright-mcp
npx -y playwright-mcp
If clicking on "Add new MCP server" opens a file (.cursor/mcp.json), paste the following code and save:
{
"mcpServers": {
"playwright-mcp": {
"command": "npx",
"args": [
"-y",
"playwright-mcp"
]
}
}
}
Install playwright-mcp globally:
npm install -g playwright-mcp
Locate and update the Claude configuration file:
%APPDATA%\Claude\claude_desktop_config.json
~/Library/Application Support/Claude/claude_desktop_config.json
Add the following configuration:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["-y", "playwright-mcp"]
}
}
}
Restart Claude Desktop to apply the changes
Verify the installation by asking Claude to "List all available MCP tools." If properly installed, it should list tools like:
get-context
get-full-dom
get-screenshot
execute-code
init-browser
validate-selectors
After installation, your AI assistant will have access to several powerful capabilities:
Ask your AI assistant to initialize a browser using the init-browser
command. A browser window will open after your approval.
Playwright-MCP provides several tools for interacting with web pages:
Once connected, you can ask your AI assistant to:
For detailed tutorials on using playwright-mcp with Claude or Cursor, visit the Claude tutorial or Cursor tutorial.
For comprehensive documentation, visit the official playwright-mcp documentation.
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 > 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.