Skip to main content
Glama
Playwright DevTools MCP Server

Playwright DevTools MCP Server

by ariangibson
README.md
# Playwright DevTools MCP Server ๐ŸŽญ

A specialized Model Context Protocol (MCP) server that provides AI models with comprehensive Chrome DevTools access through Playwright. Unlike existing MCP servers focused on basic browser automation, this enables autonomous debugging, performance analysis, and security inspection capabilities.

[![npm version](https://badge.fury.io/js/playwright-devtools-mcp.svg)](https://badge.fury.io/js/playwright-devtools-mcp)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## ๐Ÿš€ What Makes This Different

**Existing Playwright MCP Servers**: Focus on DOM automation (clicking, typing, form filling)  
**Our DevTools MCP Server**: **Debugging-first approach** via Chrome DevTools Protocol

- ๐Ÿ› **Console log analysis** - Real-time error detection and debugging
- ๐ŸŒ **Network monitoring** - Request/response inspection and failure analysis  
- โšก **Performance metrics** - Core Web Vitals and resource timing
- ๐Ÿ’พ **Storage inspection** - localStorage, sessionStorage, cookies with clearing
- ๐ŸŽจ **Visual debugging** - Screenshots, DOM analysis, element property inspection
- ๐Ÿ”’ **Security analysis** - SSL certificates, headers, CSP violations *(coming soon)*

## ๐Ÿ“ฆ Installation

```bash
npm install -g playwright-devtools-mcp
```

Or for local development:
```bash
git clone https://github.com/agibson/playwright-devtools-mcp.git
cd playwright-devtools-mcp
npm install
```

## ๐Ÿ”ง Quick Start

### 1. Claude Desktop Setup

Add to your Claude Desktop configuration (`~/claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "playwright-devtools": {
      "command": "npx",
      "args": ["playwright-devtools-mcp"],
      "env": {
        "PLAYWRIGHT_HEADLESS": "true"
      }
    }
  }
}
```

### 2. Complete Debugging Example

```javascript
// In Claude Desktop, start a debugging session:

// 1. Launch browser context
const launch = await browser_launch({
  headless: false,
  viewport: { width: 1280, height: 720 }
});
const contextId = launch.data.contextId;

// 2. Navigate to problematic page
await browser_navigate({
  contextId,
  url: "https://example.com/problematic-page",
  waitFor: "load"
});

// 3. Analyze issues
const errors = await console_get_logs({
  contextId,
  types: ["error", "warn"],
  limit: 20
});

const failed = await network_get_failed_requests({
  contextId,
  limit: 10
});

const vitals = await performance_get_core_vitals({
  contextId,
  timeout: 5000
});

// 4. Visual debugging
const screenshot = await debug_take_screenshot({
  contextId,
  fullPage: true,
  format: "png"
});

const element = await debug_get_element_properties({
  contextId,
  selector: ".broken-component",
  includeComputedStyles: true,
  includeDimensions: true
});

// 5. Clean up
await browser_close({ contextId });
```

### 3. Alternative Claude Desktop Configurations

**For development (local project):**
```json
{
  "mcpServers": {
    "playwright-devtools": {
      "command": "node",
      "args": ["./src/index.js"],
      "cwd": "/path/to/playwright-devtools-mcp",
      "env": {
        "PLAYWRIGHT_HEADLESS": "false",
        "DEBUG": "playwright-devtools:*"
      }
    }
  }
}
```

**For production (npm package):**
```json
{
  "mcpServers": {
    "playwright-devtools": {
      "command": "npx",
      "args": ["playwright-devtools-mcp"],
      "env": {
        "PLAYWRIGHT_HEADLESS": "true"
      }
    }
  }
}
```

## ๐Ÿ“‹ Response Format

All tools return a consistent response format:

```javascript
{
  "success": true,
  "data": {
    // Tool-specific data
  },
  "metadata": {
    "timestamp": 1234567890,
    "duration": 1500,
    "contextId": "context-id"
  },
  "error": null
}
```

**Error Response Example:**
```javascript
{
  "success": false,
  "data": null,
  "metadata": {
    "timestamp": 1234567890,
    "contextId": "context-123"
  },
  "error": {
    "code": "NAVIGATION_FAILED",
    "message": "Failed to navigate: timeout exceeded",
    "details": {
      "url": "https://example.com",
      "timeout": 30000
    }
  }
}
```

## ๐Ÿ› ๏ธ Available Tools

### Browser Management
- **`browser_launch`** - Create browser context with custom viewport/user agent
- **`browser_navigate`** - Navigate to URLs with configurable wait conditions
- **`browser_close`** - Clean up browser contexts and resources

### Browser Safety & Recovery โœ… *New in v0.2.1!*
- **`browser_navigate_safe`** - Navigation with automatic retry and context recovery
- **`browser_health_check`** - Context health validation and auto-healing  
- **`browser_force_recreate`** - Force recreation of problematic contexts

### Console & DevTools โœ…
- **`console_get_logs`** - Collect console messages and errors with filtering
- **`console_clear_logs`** - Clear stored console data to free memory
- **`console_evaluate_javascript`** - Execute JavaScript in browser console and see results

### Network Analysis โœ…
- **`network_get_requests`** - Monitor HTTP requests and responses with filtering
- **`network_get_failed_requests`** - Get failed requests (4xx, 5xx, connection errors)
- **`network_clear_requests`** - Clear stored network data to free memory

### Performance Monitoring โœ…
- **`performance_get_metrics`** - Collect navigation timing and resource metrics
- **`performance_get_core_vitals`** - Measure Core Web Vitals (LCP, FID, CLS)

### Storage Inspection โœ… 
- **`storage_get_local_storage`** - Get localStorage data with size analysis
- **`storage_get_session_storage`** - Get sessionStorage data with filtering
- **`storage_get_cookies`** - Get cookies with security attributes and expiry info
- **`storage_clear_data`** - Selectively clear storage by type (localStorage, sessionStorage, cookies)

### Debug & Visual Tools โœ… *New in v0.3.0!*
- **`debug_take_screenshot`** - Screenshot capture (viewport OR full-page) with quality options
- **`debug_get_page_source`** - Current DOM state extraction with comprehensive statistics
- **`debug_get_element_properties`** - Deep element inspection (styles, attributes, computed values, dimensions, accessibility)
- **`debug_get_dom_tree`** - Structured DOM representation for analysis with depth control

### Security Analysis *(Coming Soon)*
- **`security_analyze_headers`** - Inspect security configurations
- **`security_get_certificates`** - SSL/TLS certificate analysis

## ๐Ÿ”„ Development Status

**Current**: โœ… Complete Visual Debugging Suite (v0.3.0)  
- โœ… Browser management with safety features and auto-recovery
- โœ… Console log analysis with JavaScript execution
- โœ… Network request monitoring and failure analysis
- โœ… Performance metrics & Core Web Vitals
- โœ… Complete storage inspection (localStorage, sessionStorage, cookies)
- โœ… **Visual debugging** - Screenshots, DOM analysis, element property inspection
- โœ… **Advanced element debugging** - Computed styles, dimensions, accessibility properties

**Next**: ๐Ÿšง Enhanced network analysis tools (slow requests, waterfalls, request interception)  
**Future**: ๐Ÿ“‹ Security analysis, HAR export, device simulation

## ๐Ÿ—๏ธ Architecture

```
src/
โ”œโ”€โ”€ index.js          # MCP server entry point
โ”œโ”€โ”€ server.js         # Tool registry and execution
โ”œโ”€โ”€ tools/            # Individual MCP tools
โ”‚   โ””โ”€โ”€ browser.js    # Browser management tools
โ”œโ”€โ”€ utils/            # Shared utilities
โ”‚   โ””โ”€โ”€ browser-manager.js  # Browser lifecycle management
โ””โ”€โ”€ config/           # Configuration system
    โ””โ”€โ”€ defaults.js   # Default settings
```

## โš™๏ธ Configuration

### Environment Variables
```bash
PLAYWRIGHT_BROWSER_TYPE=chromium    # chromium|firefox|webkit
PLAYWRIGHT_HEADLESS=true           # true|false
PLAYWRIGHT_TIMEOUT=30000           # milliseconds
MCP_MAX_CONCURRENT_PAGES=3         # resource limits
DEBUG=playwright-devtools:*        # debug logging
```

### Runtime Options
```javascript
browser_launch({
  headless: false,              // Override headless mode
  viewport: { width: 1920, height: 1080 },
  userAgent: "Custom User Agent"
});
```

## ๐Ÿงช Testing

```bash
# Run all tests
npm test

# Run with debug logging
DEBUG=playwright-devtools:* npm start

# Development mode with auto-reload
npm run dev
```

## ๐Ÿ” Authentication & Security

**๐Ÿ›ก๏ธ Security-First Approach:**
- **No password storage** - This server does NOT store or manage authentication credentials
- **Session-based workflow** - Users log in manually, AI works with existing sessions
- **Cookie inspection** - AI can analyze and manage cookies from existing authenticated sessions
- **Human-in-the-loop** - Authentication requires human interaction for security

**๐Ÿ’ก Recommended workflow:**
1. User manually logs into websites they want to debug
2. AI uses the MCP server to inspect the authenticated session
3. AI can analyze storage, cookies, and debug authenticated pages
4. No credentials are stored or transmitted through the MCP server

## ๐Ÿค Contributing

We welcome contributions! This is a **weekend MVP project** designed for community growth.

**๐Ÿš€ Quick Contribution Guide:**
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-devtools-tool`
3. Follow the existing tool patterns in `src/tools/`
4. Add your tool to `src/server.js` tool registry
5. Test it works and submit a pull request

**๐Ÿ“ Architecture is Extension-Ready:**
- **Modular design** - Each tool is a self-contained module
- **Consistent APIs** - Follow existing patterns for easy maintenance
- **Simple registration** - Just import and add to the TOOLS array
- **Clear examples** - Every tool has comprehensive examples

### Development Philosophy
- **Keep it simple** - Focus on core debugging use cases, avoid over-engineering
- **AI-first design** - APIs should work well with AI model capabilities  
- **Weekend MVP mindset** - Clean, functional, extensible - not enterprise-hardened

## ๐Ÿ“ License

MIT License - see [LICENSE](LICENSE) file for details.

## ๐Ÿ”— Related Projects

- [Microsoft's Playwright MCP](https://github.com/microsoft/playwright-mcp) - General browser automation
- [MCP Servers](https://github.com/modelcontextprotocol/servers) - Official MCP server collection
- [Playwright](https://playwright.dev/) - Browser automation framework

## โญ Support

If this project helps you debug web applications with AI, please consider:
- โญ Starring the repository
- ๐Ÿ› Reporting issues and bugs
- ๐Ÿ’ก Suggesting new DevTools capabilities
- ๐Ÿค Contributing code or documentation

---

**Built for the AI-powered debugging future** ๐Ÿค–โœจ

TDQS

B3.2/5.0

Scored across 22 tools

Disambiguation3/5

Most tools are clearly separated by domain prefixes (storage_, debug_, console_, network_, performance_), but there are real overlaps: browser_navigate vs browser_navigate_safe, and performance_get_core_vitals vs performance_get_metrics (which explicitly also collects Core Web Vitals). The recovery cluster (browser_health_check, browser_force_recreate, browser_navigate_safe) also has fuzzy boundaries for an agent deciding which to call.

Naming Consistency5/5

Every tool follows a consistent snake_case pattern of domain_verb_noun (browser_navigate, storage_get_cookies, debug_take_screenshot, console_clear_logs). Domain prefixes are used uniformly and make grouping predictable, with only trivial stylistic variance such as 'take_screenshot' vs 'get_*'.

Tool Count4/5

22 tools is on the heavy side, but they distribute cleanly across six genuine capability areas (lifecycle, storage, debug, console, network, performance), so each earns roughly its place. A few recovery/health tools could arguably be folded into navigate/launch to slim the surface.

Completeness3/5

The read/debug surface is broad (DOM, console, network, storage, vitals, screenshots), but storage is read-and-clear only with no tool to set localStorage/sessionStorage/cookies, and there is no element selection/interaction or viewport control. For a pure debugging server these are workable gaps, but they create dead ends for common diagnostic workflows.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues