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.
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
-
Clone or navigate to your project directory
-
Install dependencies
npm install -
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 |
| 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)
-
Start the MCP server in a terminal:
npx @playwright/mcp@latest --caps=vision,pdf,testing,tracing --output-dir=playwright-mcp-outputYou should see:
Listening on http://localhost:8931⚠️ Keep this terminal running — the MCP server must stay active
-
Open your AI tool (Claude Desktop, Cursor, GitHub Copilot, etc.)
-
Issue natural language commands:
"Open google.com, search 'Playwright', verify results appear, and take a screenshot" -
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— Screenshotspage.pdf— PDF exportstrace.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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。
mcp-server-qdrant
这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。