Playwright Automation MCP Server

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.

Category
访问服务器

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.

Playwright TypeScript MCP

🌟 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

  1. No Remote Browser: Browser runs locally, not in cloud
  2. Real Interactions: Actual website calls, not mocked responses
  3. MCP Protocol: Standard communication between AI and tools
  4. Persistent Sessions: Browser state maintained across function calls
  5. 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

  1. Install Claude Desktop from claude.ai

  2. 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
  3. Create/edit the config file:

{
  "mcpServers": {
    "playwright-automation": {
      "command": "node",
      "args": ["dist/index.js"],
      "cwd": "/absolute/path/to/your/playwright-automation-mcp"
    }
  }
}
  1. Start your local MCP server:
cd /path/to/playwright-automation-mcp
npm run build
npm start
  1. 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

  1. Install Cursor from cursor.sh

  2. Configure MCP in your project:

# In your project root
mkdir -p .cursor
  1. Create .cursor/mcp.json:
{
  "mcpServers": {
    "playwright-automation": {
      "command": "node",
      "args": ["dist/index.js"],
      "cwd": "."
    }
  }
}
  1. Start MCP server separately:
npm run build
npm start
  1. In Cursor, enable MCP integration:
    • Open Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
    • Search for "MCP" settings
    • Ensure MCP integration is enabled

🔧 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.js exists 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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

🙋 Support

📚 Documentation & Resources

👨‍💻 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>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选