Playwright MCP Automation

Playwright MCP Automation

Enables AI assistants to control browser automation through natural language prompts using Playwright, supporting visual element interaction, PDF generation, screenshots, and testing assertions.

Category
Visit Server

README

šŸŽ­ Playwright MCP Automation

Bridge the gap between AI assistants and browser automation — Control Playwright directly from natural language prompts using the Model Context Protocol (MCP).


🌟 Overview

This project integrates Playwright with the Model Context Protocol (MCP), enabling AI tools like GitHub Copilot, Claude Desktop, or Cursor to perform browser automation tasks through simple conversational prompts.

Why MCP + Playwright?

  • Natural Language Control: Describe what you want instead of writing test code
  • AI-Powered Testing: Let AI assistants handle browser interactions
  • Rapid Prototyping: Test ideas without manual script writing
  • Flexible Automation: Combine vision-based clicking, PDF generation, and assertions

✨ What You Can Do

Simply ask your AI assistant:

"Open Google and search for Playwright"
"Verify the title contains 'Playwright' and take a screenshot"
"Click the Docs tab and generate a PDF of the page"
"Find the download button using visual recognition and click it"

The AI translates your request → MCP Protocol → Browser Actions → Results ✨

No need to run npx playwright test manually!


šŸ“ Project Structure

Playwright_MCP/
ā”œā”€ā”€ tests/
│   └── mcp-playwright.spec.ts    # Example Playwright test suite
ā”œā”€ā”€ scripts/
│   └── run-via-mcp.js             # Manual MCP client (optional)
ā”œā”€ā”€ mcp.config.json                # MCP server configuration
ā”œā”€ā”€ playwright.config.ts           # Playwright configuration
ā”œā”€ā”€ package.json                   # Dependencies
└── README.md                      # This file

šŸš€ Getting Started

Prerequisites

Ensure you have the following installed:

Tool Check Version Required Version
Node.js node --version v18.0.0 or higher
npm npm --version Latest stable
Playwright npx playwright --version Latest

Installation

  1. Clone or navigate to your project directory

  2. Install dependencies

    npm install
    
  3. Install Playwright browsers (if not already installed)

    npx playwright install
    

āš™ļø Configuration

MCP Server Setup

The MCP configuration is defined in mcp.config.json:

{
  "servers": {
    "playwright": {
      "command": "npx",
      "args": [
        "@playwright/mcp@latest",
        "--caps=vision,pdf,testing,tracing"
      ],
      "env": {}
    }
  }
}

Enabled Capabilities

Capability Description
vision Use coordinates and OCR for element interaction
pdf Generate PDF snapshots of web pages
testing Run assertions (visibility, text content, values)
tracing Collect debug traces for troubleshooting

šŸŽÆ Usage

Method 1: AI Assistant Integration (Recommended)

  1. Start the MCP server in a terminal:

    npx @playwright/mcp@latest --caps=vision,pdf,testing,tracing --output-dir=playwright-mcp-output
    

    You should see:

    Listening on http://localhost:8931
    

    āš ļø Keep this terminal running — the MCP server must stay active

  2. Open your AI tool (Claude Desktop, Cursor, GitHub Copilot, etc.)

  3. Issue natural language commands:

    "Open google.com, search 'Playwright', verify results appear, and take a screenshot"
    
  4. Watch the magic happen — the AI will:

    • Connect to your MCP server
    • Control the browser
    • Execute the automation
    • Return results/screenshots

Method 2: Manual MCP Client (Testing)

If you want to test MCP functionality without an AI assistant:

node scripts/run-via-mcp.js

This script will:

  • Launch a browser via MCP
  • Navigate to Google
  • Search for "Playwright"
  • Save a screenshot locally

Method 3: Traditional Playwright Tests

Run Playwright tests the standard way (without MCP):

npx playwright test tests/mcp-playwright.spec.ts

šŸ“¦ Output & Artifacts

All generated files are saved to:

playwright-mcp-output/

Example artifacts:

  • google-playwright-search.png — Screenshots
  • page.pdf — PDF exports
  • trace.zip — Playwright trace files

šŸ”§ Troubleshooting

Issue Solution
Error: spawn npx ENOENT Ensure the MCP server is running in a separate terminal
Server disconnected Restart the MCP server terminal window
Browser not launching Run npx playwright install to install browser binaries
Port 8931 already in use Kill the existing MCP process or change the port
Vision capabilities not working Ensure --caps=vision is included in server args

Debug Mode

Run the MCP server with verbose logging:

DEBUG=* npx @playwright/mcp@latest --caps=vision,pdf,testing,tracing

šŸŽÆ Roadmap & Future Enhancements

  • [ ] Automate complex login flows via MCP
  • [ ] Advanced cursor-based interactions
  • [ ] File download verification
  • [ ] Trace log streaming to AI assistants
  • [ ] Multi-browser support (Chromium, Firefox, WebKit)
  • [ ] CI/CD pipeline integration

šŸ¤ Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests

šŸ“„ License

This project is licensed under the MIT License.


šŸ”— Resources


Built with ā¤ļø using Playwright & MCP

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured