Playwright Automation MCP Server
Enables AI-powered browser automation controlled through natural language, integrating Playwright with the Model Context Protocol to perform web interactions like navigation, form filling, and screenshots.
README
๐ AI-Powered Web Automation with MCP
Playwright + Model Context Protocol: Intelligent Browser Automation ๐ค
Transform your testing workflow with AI-driven automation! Combine Playwright's robust browser automation with MCP (Model Context Protocol) for intelligent, natural language-controlled testing.
๐ Overview
Experience the future of web automation where AI understands your testing intentions! Simply describe what you want to test in natural language, and watch as AI orchestrates complex browser interactions automatically.
๐ What is MCP (Model Context Protocol)?
MCP is an open protocol that standardizes how applications provide context to LLMs, acting like a "USB-C port for AI applications" that provides a standardized way to connect AI models to different data sources and tools. It enables seamless communication between AI assistants (like Claude) and your local automation tools, making complex web testing as simple as having a conversation.
๐ฏ What Makes This Revolutionary
- ๐ฃ๏ธ Natural Language Control: "Register a new user and add items to cart"
- ๐ง AI-Powered Execution: Smart element detection, timing, and error handling
- ๐ฒ Dynamic Test Data: Automatically generates realistic user data
- ๐ Self-Healing Tests: Adapts to UI changes intelligently
- ๐ Cross-Platform: Works with Claude Desktop, Cursor IDE, and other MCP clients
โจ Natural Language Examples
"Navigate to the website and create a new user account"
โ AI automatically generates user data and completes registration
"Browse women's clothing and add a blue dress to the cart"
โ AI navigates categories, finds products, and manages cart
"Login with the account we just created and verify it worked"
โ AI remembers credentials and validates successful authentication
"Take a screenshot of the current page"
โ AI captures and saves the current browser state
๐๏ธ Architecture & Execution Flow
๐ Complete Execution Architecture
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ You (Human User) โ โ Cloud AI Service โ โ Your Local Machine โ
โ โโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโ โ
โ โ Claude Desktopโ โโโโโบโ โ Claude AI โ โโโโโบโ โ MCP Server โ โ
โ โ or โ โ โ โ Assistant โ โ โ โ (Node.js) โ โ
โ โ Cursor IDE โ โ โ โ โ โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโ โ โ โโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโฌโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Playwright Engine โ
โ โโโโโโโโโโโโโโโโโโโ โ
โ โ Real Browser โ โ
โ โ (Chromium) โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโ โ โ
โ โ โReal Website โ โ โ
โ โ โInteractions โ โ โ
โ โ โโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ
๐ฏ Detailed Execution Flow
๐ Step-by-Step Process:
1. ๐ฌ Human Input (You)
โ
"Register a new user and add items to cart"
2. ๐ Client Application (Claude Desktop/Cursor)
โ
Sends request to Claude AI service over HTTPS
3. ๐ง Claude AI (Anthropic's Cloud)
โ
โข Understands natural language intent
โข Decides which automation functions to call
โข Generates parameters (random user data, etc.)
4. ๐ก MCP Protocol Communication
โ
Claude connects to your local MCP server via JSON-RPC
5. ๐ฅ๏ธ Your Local MCP Server (Node.js)
โ
โข Receives function calls from Claude
โข Validates parameters
โข Executes Playwright scripts
6. ๐ญ Playwright Engine (Local)
โ
โข Launches real browser (Chromium)
โข Performs actual web interactions
โข Manages browser state and timing
7. ๐ Real Website Interaction
โ
โข Actual HTTP requests to automationexercise.com
โข Real form submissions and user account creation
โข Genuine e-commerce interactions
8. โฌ
๏ธ Results Flow Back
โ
Website โ Browser โ Playwright โ MCP Server โ Claude AI โ You
๐ What Happens Behind the Scenes
When You Say: "Register a new user"
๐ง Claude AI Processing:
// Claude's internal decision making:
1. Parse intent: "User wants to register on the website"
2. Identify required function: register_new_user
3. Generate realistic test data:
- email: "testuser_1734721171547@example.com"
- password: "AutoPass2025!"
- name: "John Smith"
- address: "123 Main Street"
4. Send MCP function call to your local server
๐ฅ๏ธ Your Local MCP Server Execution:
// Actual Playwright code that executes:
async function registerNewUser(params) {
// 1. Navigate to signup page
await page.goto('https://automationexercise.com');
await page.click('a[href="/login"]');
// 2. Fill initial signup form
await page.fill('input[data-qa="signup-name"]', params.name);
await page.fill('input[data-qa="signup-email"]', params.email);
await page.click('button[data-qa="signup-button"]');
// 3. Fill detailed registration form
await page.fill('input[data-qa="first_name"]', params.firstName);
await page.fill('input[data-qa="password"]', params.password);
await page.selectOption('select[data-qa="country"]', params.country);
// ... more form filling
// 4. Submit registration
await page.click('button[data-qa="create-account"]');
// 5. Return success result
return { success: true, email: params.email };
}
๐ Real Browser Actions:
- ๐ Chromium browser window opens (headless by default)
- ๐ Actual page loads from automationexercise.com
- ๐ฑ๏ธ Real mouse clicks and keyboard typing
- ๐ Form data submitted to real servers
- โ Actual user account created in their database
๐ฅ๏ธ Platform-Specific Execution
๐ฅ๏ธ Claude Desktop Flow:
Your Computer:
โโโ Claude Desktop App (Electron)
โ โโโ Connects to Anthropic's Claude AI
โ โโโ MCP client built-in
โโโ Local MCP Server (Node.js process)
โ โโโ Receives MCP calls from Claude
โ โโโ Executes Playwright scripts
โโโ Browser Process (Chromium)
โโโ Real web interactions
โจ๏ธ Cursor IDE Flow:
Your Computer:
โโโ Cursor IDE (VS Code fork)
โ โโโ MCP extension/integration
โ โโโ Connects to Claude AI via API
โโโ Local MCP Server (Node.js process)
โ โโโ Started via npm start
โ โโโ Listens for MCP connections
โโโ Browser Process (Chromium)
โโโ Automated by Playwright
๐ Security & Isolation
- Local Execution: All browser automation happens on your machine
- Data Privacy: Test data never leaves your system
- Network Isolation: Only connects to specified test websites
- Process Isolation: Each browser session is isolated
- Credential Safety: Login details stored locally only
๐ก Key Technical Points
- No Remote Browser: Browser runs locally, not in cloud
- Real Interactions: Actual website calls, not mocked responses
- MCP Protocol: Standard communication between AI and tools
- Persistent Sessions: Browser state maintained across function calls
- Error Handling: Both AI and local server handle failures gracefully
๐ Quick Start
๐ Prerequisites
- Node.js 18+ installed
- npm or yarn package manager
- Git for cloning the repository
๐ฆ Installation
# 1. Clone the repository
git clone https://github.com/yourusername/playwright-automation-mcp.git
cd playwright-automation-mcp
# 2. Install dependencies
npm install
# 3. Install Playwright browsers
npx playwright install
# 4. Build the project
npm run build
โ๏ธ MCP Server Configuration
๐ Important: The MCP server runs locally on your machine, not in the cloud. Claude AI connects to your local server to execute automation.
๐ง Understanding the Setup:
- Claude AI: Runs in Anthropic's cloud, understands your requests
- MCP Server: Runs locally on your machine, executes Playwright
- Browser: Launches locally, performs real web interactions
Option 1: Claude Desktop
-
Install Claude Desktop from claude.ai
-
Locate config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
Create/edit the config file:
{
"mcpServers": {
"playwright-automation": {
"command": "node",
"args": ["dist/index.js"],
"cwd": "/absolute/path/to/your/playwright-automation-mcp"
}
}
}
- Start your local MCP server:
cd /path/to/playwright-automation-mcp
npm run build
npm start
- Verification Steps:
- โ MCP server shows: "Playwright Automation MCP Server started"
- โ Restart Claude Desktop completely
- โ In Claude, try: "Can you navigate to the automation exercise website?"
Option 2: Cursor IDE
-
Install Cursor from cursor.sh
-
Configure MCP in your project:
# In your project root
mkdir -p .cursor
- Create
.cursor/mcp.json:
{
"mcpServers": {
"playwright-automation": {
"command": "node",
"args": ["dist/index.js"],
"cwd": "."
}
}
}
- Start MCP server separately:
npm run build
npm start
- In Cursor, enable MCP integration:
- Open Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) - Search for "MCP" settings
- Ensure MCP integration is enabled
- Open Command Palette (
๐ง Configuration Troubleshooting:
# 1. Verify your project is built
ls -la dist/index.js # Should exist
# 2. Test MCP server manually
npm start # Should show "Server started" message
# 3. Check for port conflicts
lsof -i :3000 # Default MCP port
# 4. Kill any existing MCP processes
pkill -f "dist/index.js"
โ Connection Verification:
When properly configured, you should be able to:
๐ฅ๏ธ In Claude Desktop:
You: "Can you help me test a website?"
Claude: "I can help you with web automation! I have access to Playwright tools..."
โจ๏ธ In Cursor:
You: @mcp Can you list available automation functions?
Cursor: Shows list of playwright-automation functions
๐ฏ Verification
Start the MCP server to test your setup:
npm start
You should see:
โ
Playwright Automation MCP Server started
๐ Server ready for MCP connections
๐ญ Playwright browsers initialized
๐ฎ Usage
๐ค With AI Assistants (Recommended)
Simply chat with your AI assistant naturally:
You: "Can you test the user registration flow on the automation exercise website?"
AI Assistant: I'll help you test the registration flow. Let me:
1. Navigate to the website
2. Register a new user with random data
3. Verify the registration was successful
[Executes automation automatically...]
โ
Successfully registered user: testuser_1734721171547@example.com
โ
Account creation confirmed
โ
User can login with new credentials
๐ง Direct MCP Commands (Advanced)
For advanced users or debugging:
// Navigate to website
playwright-automation:navigate_to_automation_exercise
// Register new user (AI generates data automatically)
playwright-automation:register_new_user
{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "SecurePass123!",
"firstName": "John",
"lastName": "Doe",
"company": "Tech Corp",
"address": "123 Main St",
"city": "San Francisco",
"state": "California",
"zipCode": "94102",
"country": "United States",
"mobileNumber": "555-123-4567"
}
// Browse products by category
playwright-automation:browse_products
{
"category": "Women"
}
// Add product to cart
playwright-automation:add_product_to_cart
{
"productName": "Blue Top"
}
๐ ๏ธ Available Functions
| Function | Description | Parameters |
|---|---|---|
navigate_to_automation_exercise |
Launch AutomationExercise website | None |
register_new_user |
Register new account with full details | User details object |
login_user |
Login with existing credentials | email, password |
logout_user |
Logout current user | None |
browse_products |
Browse product catalog | category (optional) |
add_product_to_cart |
Add specific product to cart | productName |
view_cart |
Display cart contents | None |
take_screenshot |
Capture current page | filename (optional) |
click_continue |
Click continue button | None |
close_browser |
Close browser and cleanup | None |
๐งช Testing Scenarios
๐ฏ Complete User Journey
1. Website Navigation โ
2. User Registration โ
3. Account Verification โ
4. Product Browsing โ
5. Shopping Cart โ
6. User Authentication โ
7. Session Management โ
๐ฒ Dynamic Test Data
The system automatically generates:
- Unique email addresses with timestamps
- Realistic names and addresses
- Valid phone numbers
- Secure passwords
- Random but valid form data
๐ง Development
๐ Project Structure
src/
โโโ index.ts # MCP server entry point
โโโ playwright-automation.ts # Core automation functions
โโโ config.ts # Configuration management
โโโ demo.ts # Demonstration flows
โโโ utils/
โโโ helpers.ts # Utility functions
โโโ page-objects.ts # Page object models
โโโ test-data.ts # Test data generators
๐ ๏ธ Available Scripts
npm start # Start MCP server
npm run dev # Development mode with auto-reload
npm run build # Build TypeScript to JavaScript
npm run demo # Run demonstration automation
npm test # Execute test suite
npm run test:ui # Run tests with Playwright UI
npm run codegen # Generate Playwright code
๐ Debugging
Enable debug mode:
# Debug MCP communication
DEBUG=mcp:* npm start
# Debug Playwright actions
DEBUG=pw:api npm start
# Debug everything
DEBUG=* npm start
๐จ Troubleshooting
Common Issues & Solutions
โ MCP Server Not Connecting
# Check if server is running
ps aux | grep "dist/index.js"
# Kill existing instances
pkill -f "dist/index.js"
# Rebuild and restart
npm run build && npm start
โ Browser Not Launching
# Reinstall Playwright browsers
npx playwright install --force
# Check system dependencies (Linux)
npx playwright install-deps
โ Configuration Issues
- Verify absolute paths in config files
- Ensure
dist/index.jsexists after building - Check file permissions
- Restart AI client after config changes
โ Function Calls Failing
- Confirm MCP server is running
- Check browser is properly initialized
- Verify website is accessible
- Review error messages in server logs
๐ Health Check
Test your setup:
# Verify server health
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{"method": "tools/list"}'
๐ฏ Target Application & Website
This automation targets AutomationExercise, which provides:
- ๐ค User Management: Registration, login, logout flows
- ๐๏ธ Product Catalog: Categories, search, product details
- ๐ Shopping Cart: Add/remove items, checkout process
- ๐ฑ Responsive Design: Mobile and desktop layouts
- ๐งช Rich Test Scenarios: Perfect for automation practice
๐ค Contributing & Development
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ Support
๐ Documentation & Resources
- ๐ญ Playwright Documentation - Master browser automation with comprehensive guides, APIs, and examples
- ๐ค MCP Documentation - Learn Model Context Protocol for building AI-powered automation tools
- ๐ข Official Playwright MCP - Microsoft's official MCP server implementation (17.6k โญ)
๐จโ๐ป Author
Devendra Singh - Quality Engineering Specialist, AI & Automation Enthusiast
- ๐ LinkedIn Profile - Connect for professional opportunities and collaboration
- ๐ GitHub Profile - View other projects and contributions
- ๐ง Contact - Reach out through LinkedIn or GitHub for questions and partnerships
<div align="center">
๐ Transform Your Testing with AI-Powered Automation! ๐
</div>
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.