playwright-mcp

MCP.Pizza Chef: Ashish-Bansal

playwright-mcp is an MCP server that exposes the full browser context of Playwright to AI models, enabling them to accurately understand and interact with web pages. It solves common issues in AI-assisted test writing such as flaky tests, broken scripts, and debugging difficulties by providing real-time, structured visibility into the web page's state and elements. This allows AI assistants to generate precise selectors and robust test scripts, improving automation reliability and developer productivity.

Use This MCP server To

Enable AI to generate accurate Playwright test selectors Provide real-time web page context to AI for test script generation Reduce flaky tests by improving AI understanding of page elements Automate debugging of Playwright tests with AI visibility Integrate AI-assisted test writing into CI/CD pipelines Enhance browser automation workflows with AI-driven insights

README

How to Use playwright-mcp?

npm version Docs

Introduction

Ever tried using Cursor or Claude to write Playwright tests? Yeah, it's kind of a mess.

Why? Because your AI assistant has no clue what's on your web page. It's like trying to describe a painting to someone who's blindfolded. The result?

  • Flaky tests → The AI is guessing selectors, and it gets them wrong.
  • Broken scripts → You spend more time fixing tests than writing them.
  • Debugging nightmares → The AI can't "see" what's happening, so you end up doing all the heavy lifting.

Wouldn't it be nice if your AI could actually understand your web page instead of just making educated guesses?

Enter playwright-mcp !

playwright-mcp gives your AI assistant superpowers by making the browser fully visible to it. Instead of working in the dark, your AI assistant now has real-time access to the page DOM, elements, and interactions.

How playwright-mcp Works (AKA How We Fix This Mess)

Once installed, playwright-mcp spins up a Playwright-controlled browser and gives your AI assistant full access to it. This unlocks:

  1. Recording interactions → Click, type, scroll—let playwright-mcp turn your actions into fully functional Playwright test cases.
  2. Taking screenshots → Capture elements or full pages so your AI gets actual visual context (no more guessing).
  3. Extracting the DOM → Grab the entire HTML structure so the AI can generate rock-solid selectors.
  4. Executing JavaScript → Run custom JS inside the browser for debugging, automation, or just for fun.

Why You'll Love playwright-mcp

🚀 AI-generated tests that actually work → No more flaky selectors, broken tests, or guesswork.

Massive time savings → Write and debug Playwright tests 5x faster.

🛠️ Fewer headaches → Your AI assistant gets live page context, so it can generate real test cases.

🔌 Works out of the box → Plug it into Cursor, Claude, WindSurf, or whatever you use—it just works.

Give Your AI the Context It Deserves

Tired of fixing AI-generated tests? Stop debugging AI's bad guesses—start writing flawless Playwright tests. Use the guide below to install playwright-mcp and let your AI assistant actually help you for once.


Installation: Get Up and Running in No Time

Prerequisites (a.k.a. What You Need Before You Start)

Before you install playwright-mcp, make sure you have:

✅ Node.js installed on your system (because, well… it's an npm package)

✅ Playwright and its Chromium browser installed

✅ An IDE that supports MCP, like Cursor

✅ A brain that's ready to automate Playwright tests like a pro

Setting Up playwright-mcp (It's Easy, I Promise)

Connect It to Your IDE (Cursor Setup)

If you're using Cursor, follow these steps to connect playwright-mcp like a boss:

  1. Open Cursor IDE

  2. Navigate to Settings (⚙️)

  3. Select Cursor Settings → Go to the MCP tab

  4. Click "Add new MCP server"

  5. Fill in the following details:

    Connect playwright-mcp to cursor

    • Name → playwright-mcp
    • Command → npx -y playwright-mcp
  6. Click "Add", and boom—you're connected! 🚀

Note: 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"
      ]
    }
  }
}

Now Cursor actually understands your web pages. No more random test suggestions based on zero context! Head to the Claude tutorial or Cursor tutorial to understand it in details.


Connect It to Claude desktop

Wait… Does It Work with Other AI Assistants? Yes! While playwright-mcp is a match made in heaven for IDEs, you can use it with Claude desktop to write tests as well.

  1. Install playwright-mcp (The Easy Part)

    1. First things first, fire up your terminal and run:
    2. npm install -g playwright-mcp
  2. Hook It Up to Claude Desktop

    1. Find the Configuration File
    2. On windows
      1. %APPDATA%\Claude\claude_desktop_config.json
    3. On macOS:
      1. ~/Library/Application Support/Claude/claude_desktop_config.json
    4. Update the config file
    {
      "mcpServers": {
        "playwright": {
          "command": "npx",
          "args": ["-y", "playwright-mcp"]
        }
      }
    }
  3. Restart Claude Desktop (Because It's a New Day)

    1. Close and reopen Claude Desktop to apply the changes.
  4. Verify That It's Working

    1. Once everything is set up, let's test if Claude can actually talk to Playwright now.
    2. Open Claude and ask: "List all available MCP tools."
    3. If playwright-mcp is installed correctly, it should list tools like:
      1. get-context
      2. get-full-dom
      3. get-screenshot
      4. execute-code
      5. init-browser
      6. validate-selectors
    4. Ask Claude to init browser and a browser should open up after your approval!

Now that the Calude has access to the web pages. You can ask it write highly contextual tests! Head to the Claude tutorial or Cursor tutorial to understand it in details.

📖 View Documentation

playwright-mcp FAQ

How does playwright-mcp improve AI-generated Playwright tests?
It exposes the full browser context to AI, allowing precise selector identification and reducing flaky tests.
Can playwright-mcp be integrated with existing Playwright test suites?
Yes, it works alongside existing Playwright setups to enhance AI interaction without disrupting workflows.
Does playwright-mcp support real-time updates of the web page state?
Yes, it provides real-time, structured visibility into the page, enabling dynamic AI responses.
Is playwright-mcp compatible with multiple LLM providers?
Yes, it is provider-agnostic and works with OpenAI, Claude, Gemini, and others.
What environments does playwright-mcp support?
It supports all environments where Playwright runs, including local, CI, and cloud environments.
How secure is the data exposed by playwright-mcp?
It follows MCP principles for secure, scoped, and observable model interaction to protect sensitive data.
Can playwright-mcp help with debugging test failures?
Yes, by giving AI visibility into the browser state, it helps diagnose and fix test issues faster.
How do I get started with playwright-mcp?
Installation and usage instructions are available in the official docs linked on the npm page.