Doramagic Project Pack ยท Human Manual

mcp-playwright

The project serves as a bridge between AI assistants and browser automation, exposing Playwright's browser control capabilities as MCP tools. This allows AI agents to perform web navigatio...

Project Introduction

Related topics: Getting Started, Architecture Overview

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Core Components

Continue reading this section for the full explanation and source context.

Section Package Managers

Continue reading this section for the full explanation and source context.

Section Claude Code

Continue reading this section for the full explanation and source context.

Related topics: Getting Started, Architecture Overview

Project Introduction

The Playwright MCP Server (mcp-playwright) is a Model Context Protocol (MCP) server implementation that provides browser automation capabilities through Playwright. It enables AI assistants like Claude, Cursor, and other MCP-compatible clients to interact with web pages through a standardized tool interface.

Overview

The project serves as a bridge between AI assistants and browser automation, exposing Playwright's browser control capabilities as MCP tools. This allows AI agents to perform web navigation, content extraction, form interactions, and other browser-related tasks using natural language commands.

Key Characteristics:

AttributeValue
Project Namemcp-playwright
Package Name@executeautomation/playwright-mcp-server
LicenseMIT
Node.js Version20+
ProtocolModel Context Protocol (MCP)

Sources: package.json:1-20

Architecture

The server follows a client-server architecture where AI assistants act as MCP clients communicating with the Playwright MCP server.

graph TD
    A["AI Assistant<br/>(Claude, Cursor, etc.)"] -->|MCP Protocol| B["Playwright MCP Server"]
    B -->|stdin/stdout| A
    B -->|HTTP/SSE| B
    C["Browser Instances<br/>(Chromium, Firefox, WebKit)"] -->|Playwright API| B
    
    B -->|Browser Automation| C
    C -->|Page Content| B
    B -->|Tool Results| A

Core Components

ComponentPurpose
MCP SDKHandles MCP protocol communication
Tool HandlersProcesses tool calls and executes Playwright operations
Browser ManagerManages browser lifecycle and instances
Logging SystemCaptures request/response data and error tracking

Sources: src/logging/middleware.ts:1-20

Installation Methods

The project supports multiple installation approaches to accommodate different deployment scenarios.

Package Managers

# npm
npm install -g @executeautomation/playwright-mcp-server

# mcp-get
npx @michaellatman/mcp-get@latest install @executeautomation/playwright-mcp-server

# Smithery (automated)
npx @smithery/cli install @executeautomation/playwright-mcp-server --client claude

Claude Code

claude mcp add --transport stdio playwright npx @executeautomation/playwright-mcp-server

Sources: README.md:40-65

Operation Modes

The server supports two primary operation modes based on the transport mechanism.

STDIO Mode (Default)

STDIO mode is the recommended configuration for Claude Desktop and other clients that communicate via standard input/output streams.

graph LR
    A["MCP Client"] -->|"stdio"| B["Playwright MCP Server"]
    B -->|"stdio"| A
    C["Playwright<br/>Browser"] -->|Control| B

Configuration Example:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}
Note: In stdio mode, logging is automatically directed to files only to maintain clean JSON-RPC communication. Logs are written to ~/playwright-mcp-server.log.

Sources: README.md:20-30

HTTP Mode (Standalone Server)

HTTP mode enables the server to run as a standalone HTTP server, suitable for VS Code, custom clients, and remote deployments.

npx @executeautomation/playwright-mcp-server --port 8931

Available Endpoints:

EndpointMethodPurpose
/sseGETSSE Stream for server-sent events
/messages?sessionId=<id>POSTSend messages to a session
/mcpGET/POSTUnified MCP protocol endpoint
/healthGETHealth check endpoint

Client Configuration:

{
  "mcpServers": {
    "playwright": {
      "url": "http://localhost:8931/mcp"
    }
  }
}

Sources: README.md:35-55 Sources: examples/http-mode-example.md:1-30

Docker Deployment

The project provides official Docker images for containerized deployments.

Basic Usage

docker run -i --rm mcp-playwright:latest

Docker Configuration

{
  "mcpServers": {
    "playwright-docker": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "mcp-playwright:latest"]
    }
  }
}

Environment Variables

VariablePurposeDefault
PLAYWRIGHT_SKIP_BROWSER_DOWNLOADSkip browser installation1
NODE_ENVNode environmentproduction

Volume Mounts

docker run -i --rm \
  -v $(pwd)/data:/app/data \
  -v $(screenshots):/app/screenshots \
  mcp-playwright:latest
Note: The Docker image skips browser downloads by default to reduce size (~200MB). Browsers are downloaded on first use.

Sources: DOCKER.md:1-80

Supported Tools

The server exposes a comprehensive set of Playwright operations as MCP tools.

Browser Control Tools

Tool CategoryToolsDescription
Navigationplaywright_navigateNavigate to URLs with multi-browser support
Interactionplaywright_click, playwright_drag, playwright_press_keyElement interactions
Contentplaywright_get_visible_text, playwright_get_visible_htmlContent extraction
Outputplaywright_save_as_pdfPage to PDF conversion

Browser Support

BrowserSupport
Chromiumโœ… Default
Firefoxโœ… Since v1.0.2
WebKitโœ… Since v1.0.2

Sources: CHANGELOG.md:1-30

Dependencies

Production Dependencies

PackageVersionPurpose
@modelcontextprotocol/sdk1.24.3MCP protocol implementation
playwright1.57.0Browser automation framework
@playwright/browser-chromium1.57.0Chromium browser
@playwright/browser-firefox1.57.0Firefox browser
@playwright/browser-webkit1.57.0WebKit browser
express^4.21.1HTTP server for HTTP mode
cors^2.8.5Cross-origin resource sharing
uuid11.1.0Session ID generation
mcp-evals^2.0.1Evaluation utilities

Development Dependencies

PackageVersionPurpose
typescript^5.8.3TypeScript compilation
jest^29.7.0Testing framework
jest-playwright-preset4.0.0Playwright test integration
ts-jest^29.2.6TypeScript Jest transformer

Sources: package.json:20-50

Logging System

The server includes a comprehensive logging system for debugging and monitoring.

Log Location

Log Features

FeatureDescription
Request LoggingCaptures tool execution with sanitized arguments
Error ContextIncludes stack traces and browser state
Log RotationAutomatic rotation with configurable max files
Sensitive Data RedactionPasswords, tokens, and secrets automatically masked

Sources: src/logging/logger.ts:1-50 Sources: src/logging/middleware.ts:1-30

Troubleshooting

Common Issues

IssueSolution
Container exits immediatelyEnsure -i flag is used for Docker
Browser not foundUse custom Dockerfile with npx playwright install
Permission issuesUse --user $(id -u):$(id -g) flag
Tool name too longKeep names under 60 characters (server + tool name)
Important: When adding new tools, ensure tool names are short enough to not exceed the 60-character limit for combined server and tool name (server_name:tool_name). The server name is playwright-mcp.

Sources: README.md:15-18

Version History

VersionDateKey Changes
1.0.8CurrentLatest stable release
1.0.72024-12Advanced screenshot and content tools
1.0.22024-11-10Multi-browser support (Firefox, WebKit)
1.0.02024-11-01First major release with Bearer Auth support

Sources: CHANGELOG.md:1-50

Next Steps

For more detailed information, refer to:

Sources: [package.json:1-20]()

Getting Started

Related topics: Project Introduction, Docker Deployment, Configuration Guide

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Method 1: npm Package (Recommended)

Continue reading this section for the full explanation and source context.

Section Method 2: Docker Container

Continue reading this section for the full explanation and source context.

Section Claude Desktop

Continue reading this section for the full explanation and source context.

Related topics: Project Introduction, Docker Deployment, Configuration Guide

Getting Started

This guide provides everything you need to install, configure, and run the Playwright MCP Server. The server enables AI assistants like Claude to interact with web browsers through a comprehensive set of automation tools.

Overview

The Playwright MCP Server is a Model Context Protocol (MCP) server that provides programmatic control over Playwright browsers. It allows AI assistants to perform web automation tasks including navigation, interaction, content extraction, and screenshot capture.

Key Features:

  • Multi-browser support (Chromium, Firefox, WebKit)
  • 143 device presets for mobile emulation
  • Screenshot and PDF generation
  • Web scraping and content extraction
  • Keyboard and mouse automation
  • HTTP and stdio communication modes

Sources: README.md:1-45

Prerequisites

Before installing the Playwright MCP Server, ensure your system meets these requirements:

RequirementMinimum VersionNotes
Node.js20.x or higherLTS recommended
npm9.x or higherComes with Node.js
Docker (optional)20.x or higherFor containerized deployment
Playwright browsersLatestAuto-installed on first use

System Dependencies for Playwright:

  • Linux: npx playwright install-deps
  • macOS: Xcode Command Line Tools
  • Windows: Visual Studio Build Tools

Sources: package.json:23-36

Installation Methods

Install the package globally for CLI access:

npm install -g @executeautomation/playwright-mcp-server

Or use it directly with npx (no installation required):

npx -y @executeautomation/playwright-mcp-server

Sources: README.md:56-65

Method 2: Docker Container

Pull the pre-built image from Docker Hub:

docker pull mcp-playwright:latest

Or build from source:

git clone https://github.com/executeautomation/mcp-playwright.git
cd mcp-playwright
docker build -t mcp-playwright:latest .

The Docker image is approximately 200MB (without browsers) and uses a Debian-based slim Node.js image.

Sources: DOCKER.md:80-100

Configuration

Claude Desktop

Edit your Claude Desktop configuration file:

File Locations:

OSPath
macOS~/Library/Application Support/Claude/claude_desktop_config.json
Windows%APPDATA%\Claude\claude_desktop_config.json
Linux~/.config/Claude/claude_desktop_config.json

stdio Mode (Default):

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}

Sources: README.md:56-65

VS Code MCP Extension

For VS Code with the MCP extension, add this to your MCP settings:

{
  "name": "playwright",
  "command": "npx",
  "args": ["-y", "@executeautomation/playwright-mcp-server"]
}

Sources: DOCKER.md:12-20

Docker Configuration

Basic Configuration:

{
  "mcpServers": {
    "playwright-docker": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "mcp-playwright:latest"]
    }
  }
}

With Environment Variables:

docker run -i --rm \
  -e PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
  -e NODE_ENV=production \
  mcp-playwright:latest

With Volume Mounts:

docker run -i --rm \
  -v $(pwd)/data:/app/data \
  -v $(pwd)/screenshots:/app/screenshots \
  mcp-playwright:latest

Sources: DOCKER.md:1-50

Running Modes

stdio Mode (Interactive)

The default mode for Claude Desktop where the server communicates via stdin/stdout:

# Using npx
npx -y @executeautomation/playwright-mcp-server

# Using global installation
playwright-mcp-server

In stdio mode, logs are automatically directed to files only (~/playwright-mcp-server.log) to maintain clean JSON-RPC communication.

Sources: README.md:56-65

HTTP Mode (Standalone Server)

For VS Code, custom clients, or remote deployments where you need a headed browser:

# Using npx
npx @executeautomation/playwright-mcp-server --port 8931

# Using global installation
playwright-mcp-server --port 8931

HTTP Mode Endpoints:

EndpointMethodDescription
/sseGETSSE stream for server-sent events
/messagesPOSTSend messages (requires sessionId query param)
/mcpGET/POSTUnified MCP endpoint
/healthGETHealth check

Security Note: The HTTP server binds to localhost only (127.0.0.1) to prevent external access. For remote access, use SSH tunneling.

Sources: README.md:67-90 Sources: src/http-server.ts:1-50

Claude Desktop HTTP Configuration:

{
  "mcpServers": {
    "playwright": {
      "url": "http://localhost:8931/mcp"
    }
  }
}

Sources: examples/http-mode-example.md:1-30

Architecture Overview

graph TD
    subgraph "AI Assistant"
        A[Claude / Cursor / VS Code]
    end
    
    subgraph "MCP Client"
        B[MCP SDK Client]
    end
    
    subgraph "Playwright MCP Server"
        C[Transport Layer]
        D[Tool Handlers]
        E[Browser Manager]
    end
    
    subgraph "Playwright"
        F[Chromium]
        G[Firefox]
        H[WebKit]
    end
    
    A --> B
    B --> C
    C --> D
    D --> E
    E --> F
    E --> G
    E --> H

Available Tools

The server exposes the following tool categories:

Navigation Tools

ToolDescription
playwright_navigateNavigate to a URL with optional browser type
playwright_go_backNavigate backward in history
playwright_go_forwardNavigate forward in history

Interaction Tools

ToolDescription
playwright_clickClick on an element
playwright_fillFill input fields
playwright_press_keyPress keyboard keys
playwright_dragDrag elements

Content Tools

ToolDescription
playwright_get_visible_textExtract visible text
playwright_get_visible_htmlGet HTML content with filtering options
playwright_evaluateExecute JavaScript in browser context

Output Tools

ToolDescription
playwright_screenshotCapture page screenshots
playwright_save_as_pdfSave page as PDF

Device Emulation

// Test on iPhone 13
await playwright_resize({ device: "iPhone 13" });

// Test on iPad with landscape
await playwright_resize({ device: "iPad Pro 11", orientation: "landscape" });

// Test desktop
await playwright_resize({ device: "Desktop Chrome" });

Sources: README.md:25-50 Sources: CHANGELOG.md:1-30

First Steps

1. Verify Installation

After configuration, restart your AI client and verify the server is connected:

Health check endpoint (HTTP mode):
curl http://localhost:8931/health

Expected response:

{
  "status": "ok",
  "version": "1.0.10",
  "activeSessions": 0
}

Sources: src/http-server.ts:40-48

2. Basic Browser Operations

Once connected, you can use natural language to control the browser:

"Navigate to https://example.com"
"Take a screenshot"
"Click on the login button"
"Fill in the search box with 'test'"
"Get the page title"

3. Device Emulation

Test responsive designs:

"Test on iPhone 13"
"Switch to iPad Pro view"
"Rotate to landscape"

Sources: README.md:30-45

Troubleshooting

Container Exits Immediately

MCP servers wait for input on stdin. Ensure you're running with the -i flag:

docker run -i --rm mcp-playwright:latest

Sources: DOCKER.md:55-60

Browser Not Found

The Docker image skips browser downloads by default. Create a custom Dockerfile:

FROM mcp-playwright:latest
RUN npx playwright install chromium --with-deps

Sources: DOCKER.md:65-72

Permission Issues with Volumes

docker run -i --rm \
  -v $(pwd)/data:/app/data \
  --user $(id -u):$(id -g) \
  mcp-playwright:latest

Sources: DOCKER.md:75-82

Connection Issues (HTTP Mode)

ProblemSolution
Server not startingCheck if port 8931 is available
External access blockedBy design - server binds to localhost only
Remote access neededUse SSH tunneling: ssh -L 8931:localhost:8931 user@remote

Sources: README.md:103-110

Logging

The server includes comprehensive logging for debugging:

Log File Location (stdio mode):

~/playwright-mcp-server.log

Logged Information:

  • Tool execution requests and responses
  • Error categorization (validation, system, resource)
  • Request duration metrics
  • Memory and uptime statistics

The logger captures:

  • Request IDs for traceability
  • Sanitized request bodies (sensitive fields redacted)
  • Stack traces for errors
  • Platform and environment information

Sources: src/logging/logger.ts:1-50 Sources: src/logging/middleware.ts:1-80

Testing

Run the test suite to verify your installation:

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Run custom tests
npm run test:custom

Tests are located in src/__tests__ and use Jest with Playwright preset.

Sources: README.md:113-125

Resource Limits (Docker)

Limit CPU and memory usage:

docker run -i --rm \
  --cpus="2.0" \
  --memory="2g" \
  mcp-playwright:latest

Or in docker-compose.yml:

services:
  playwright-mcp:
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G

Sources: DOCKER.md:115-130

Next Steps

TopicDescription
Device EmulationFull list of 143 device presets
Docker DeploymentAdvanced Docker configuration
HTTP ModeStandalone server setup
API ReferenceComplete tool documentation

Sources: [README.md:1-45]()

Architecture Overview

Related topics: Project Introduction, Transport Modes, Browser Automation Tools

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Tool Interface

Continue reading this section for the full explanation and source context.

Section ToolCall Interface

Continue reading this section for the full explanation and source context.

Section Request Handler Component

Continue reading this section for the full explanation and source context.

Related topics: Project Introduction, Transport Modes, Browser Automation Tools

Architecture Overview

Introduction

The mcp-playwright project is a Model Context Protocol (MCP) server that exposes Playwright browser automation capabilities to AI assistants such as Claude. The architecture follows a modular, tool-based design pattern where each browser automation operation is exposed as a discrete tool that MCP clients can invoke through JSON-RPC calls.

The server is designed to operate in two distinct transport modes: stdio mode for direct integration with MCP clients like Claude Desktop, and HTTP mode for remote deployments, VS Code integration, or headless browser scenarios. This dual-mode architecture provides flexibility while maintaining a consistent internal structure for tool registration, execution, and logging.

Sources: README.md:1-20

High-Level Architecture

The architecture consists of four primary layers that work together to process tool requests and execute browser automation tasks.

graph TD
    A[MCP Client<br/>Claude Desktop / VS Code] --> B[Transport Layer<br/>stdio or HTTP]
    B --> C[Request Handler<br/>requestHandler.ts]
    C --> D[Tool Handler<br/>toolHandler.ts]
    D --> E[Tool Registry<br/>tools.ts]
    E --> F[Browser Tools<br/>playwright API]
    F --> G[Chromium / Firefox / WebKit]

The Transport Layer handles the communication protocol, converting between the client's transport mechanism and the internal request format. The Request Handler validates and routes incoming requests to the appropriate tool. The Tool Handler manages tool execution, error handling, and response formatting. Finally, the Browser Tools layer wraps the Playwright API to provide browser automation capabilities.

Sources: src/index.ts

Core Data Structures

The type system defines the fundamental interfaces used throughout the codebase. These types establish the contract between components and ensure type safety across the architecture.

Sources: src/types.ts:1-17

Tool Interface

export interface Tool {
  name: string;
  description: string;
  parameters: {
    type: string;
    properties: Record<string, unknown>;
    required?: string[];
  };
  handler: (args: any) => Promise<any>;
}

The Tool interface represents a single automation capability exposed to MCP clients. Each tool contains a unique name identifier, a human-readable description, a JSON Schema-compatible parameters definition, and an asynchronous handler function that executes the actual automation logic.

ToolCall Interface

export interface ToolCall {
  name: string;
  parameters: Record<string, unknown>;
  result?: CallToolResult;
}

The ToolCall interface tracks the lifecycle of a tool invocation, capturing the tool name, input parameters, and the computed result.

Request Processing Pipeline

The request processing pipeline transforms incoming MCP requests into executed browser automation operations.

graph LR
    A[Incoming Request] --> B[Parse & Validate]
    B --> C[Route to Tool Handler]
    C --> D[Execute Tool Handler]
    D --> E{Check Result}
    E -->|Success| F[Return CallToolResult]
    E -->|Error| G[Log Error Context]
    G --> H[Return Error Response]

Request Handler Component

The request handler acts as the entry point for all incoming requests. It is responsible for parsing the incoming JSON-RPC messages, validating the request structure, and delegating to the appropriate tool handler.

Sources: src/requestHandler.ts

Tool Registration and Management

The tool registry maintains a collection of all available automation tools. New tools are registered through the BROWSER_TOOLS array, which contains all browser-related automation operations.

graph TD
    A[Tool Definition<br/>src/tools/browser/*.ts] --> B[BROWSER_TOOLS Array]
    B --> C[Tool Handler Registration]
    C --> D[MCP Server<br/>Tool List]

Tool Handler

The tool handler manages the execution context for all tools. It provides the following capabilities:

CapabilityDescription
Tool RegistrationRegisters tools with the MCP SDK
Execution ContextProvides shared state between tool invocations
Error HandlingCatches and formats errors from tool execution
Logging IntegrationIntegrates with the logging middleware for observability

Sources: src/toolHandler.ts

Available Tool Categories

The tools are organized into logical categories based on their function:

CategoryToolsPurpose
Navigationplaywright_navigate, playwright_go_back, playwright_reloadPage navigation and history
Interactionplaywright_click, playwright_fill, playwright_hover, playwright_dragUser interaction simulation
Content Extractionplaywright_get_visible_text, playwright_get_visible_htmlContent retrieval
Outputplaywright_screenshot, playwright_save_as_pdfVisual output generation
Emulationplaywright_resizeDevice emulation with 143 presets

Sources: CHANGELOG.md:1-30

Logging and Observability

The logging middleware provides comprehensive observability into tool execution. It captures request context, execution duration, error details, and system metrics.

graph TD
    A[Tool Execution Start] --> B[Generate Request ID]
    B --> C[Log Request Start]
    C --> D[Execute Handler]
    D --> E{Result Type}
    E -->|Success| F[Log Success<br/>Duration: Xms]
    E -->|Error| G[Capture Error Context]
    G --> H[Categorize Error]
    H --> I[Log Error<br/>with Stack Trace]

Error Categorization

The middleware categorizes errors into distinct types for better debugging and monitoring:

CategoryTriggersExample Messages
validationInvalid parameters"invalid", "required", "missing parameter"
resourceBrowser/page issues"closed", "disconnected", "protocol error"
authenticationAuth failures"unauthorized", "forbidden", "access denied"
rate_limitRate limiting"rate limit", "too many requests"
systemTimeout/element errors"timeout", "element not found", "navigation"

Sources: src/logging/middleware.ts:80-120

Request Sanitization

The logging middleware automatically sanitizes sensitive data from tool arguments before logging:

Field PatternSanitization
password, token, secret, key, authReplaced with [REDACTED]
Request bodies > 1000 charactersTruncated with character count

Sources: src/logging/middleware.ts:150-170

Transport Modes

stdio Mode

In stdio mode, the server communicates over standard input and output streams. This mode is designed for direct integration with MCP clients like Claude Desktop.

AspectConfiguration
Launch Commandnpx -y @executeautomation/playwright-mcp-server
Log OutputFile only (~/playwright-mcp-server.log)
JSON-RPCstdin/stdout streaming

Sources: README.md:30-45

HTTP Mode

HTTP mode exposes the server as a standalone HTTP server with multiple endpoints:

EndpointMethodPurpose
/sseGETServer-Sent Events stream
/messagesPOSTSend messages with session ID
/mcpGET/POSTUnified MCP protocol endpoint
/healthGETHealth check

The default port is 8931, configurable via the --port flag.

Sources: README.md:55-70

graph LR
    A[MCP Client] -->|HTTP POST /mcp| B[HTTP Server]
    B --> C[Request Handler]
    C --> D[Tool Handler]
    D --> E[Browser Automation]
    E --> F[Response]
    F --> B
    B --> A

Browser Context Management

The architecture supports multiple browser engines:

BrowserPackageDefault
Chromium@playwright/browser-chromiumYes
Firefox@playwright/browser-firefoxNo
WebKit@playwright/browser-webkitNo

The browserType parameter in playwright_navigate allows selection of the browser engine:

await playwright_navigate({ 
  url: "https://example.com",
  browserType: "firefox"  // chromium, firefox, or webkit
});

Sources: CHANGELOG.md:15-20

Deployment Architecture

Docker Deployment

The Docker deployment provides a containerized environment for the MCP server:

graph TD
    A[Docker Host] --> B[mcp-playwright:latest]
    B --> C[Node.js Runtime]
    C --> D[MCP Server]
    D --> E[Playwright Browsers]
    E --> F[Chromium<br/>Firefox<br/>WebKit]

The Docker image is optimized for size (~200MB without browsers) and supports environment variable configuration:

VariablePurposeDefault
PLAYWRIGHT_SKIP_BROWSER_DOWNLOADSkip browser installation1
NODE_ENVNode environmentproduction

Sources: DOCKER.md:40-60

Claude Desktop Configuration

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}

For HTTP mode with remote deployments:

{
  "mcpServers": {
    "playwright": {
      "url": "http://localhost:8931/mcp"
    }
  }
}

Sources: README.md:35-40

Sources: [README.md:1-20](https://github.com/executeautomation/mcp-playwright/blob/main/README.md)

Transport Modes

Related topics: Architecture Overview, Configuration Guide

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Purpose and Architecture

Continue reading this section for the full explanation and source context.

Section How STDIO Mode Works

Continue reading this section for the full explanation and source context.

Section Configuration for Claude Desktop

Continue reading this section for the full explanation and source context.

Related topics: Architecture Overview, Configuration Guide

Transport Modes

The mcp-playwright server supports two distinct transport modes for communicating with MCP clients: STDIO Transport and HTTP/SSE Transport. Each mode serves different deployment scenarios and client requirements.

Overview

The transport mode determines how the MCP protocol messages are exchanged between the Playwright MCP server and connected clients. The server automatically detects the appropriate mode based on command-line arguments or environment configuration.

Transport ModeUse CaseDefault PortSecurity
STDIOLocal MCP clients (Claude Desktop, Cursor)N/AProcess-bound
HTTP/SSERemote clients, headed browsers, IDE integrations8931Localhost only

STDIO Transport Mode

Purpose and Architecture

STDIO (Standard Input/Output) is the default transport mode for MCP servers. It provides process-based communication where messages are exchanged through the parent process's standard input and output streams.

graph LR
    A[MCP Client<br/>Claude Desktop] <-->|stdin/stdout pipes| B[playwright-mcp-server<br/>STDIO Mode]
    B <-->|Playwright API| C[Browser Instance]

How STDIO Mode Works

  1. The MCP client spawns the server as a child process
  2. JSON-RPC messages are sent via process stdin
  3. Responses are received via process stdout
  4. The server runs in headless mode by default
  5. Logging is automatically redirected to ~/playwright-mcp-server.log

Sources: README.md

Configuration for Claude Desktop

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}

Sources: README.md

Docker Considerations

When running in Docker containers, STDIO mode requires the -i flag to keep STDIN open for interactive communication:

docker run -i --rm mcp-playwright:latest
Docker FlagPurpose
-iKeep STDIN open for interactive communication
--rmAutomatically remove container when it exits

Sources: DOCKER.md

HTTP/SSE Transport Mode

Purpose and Architecture

HTTP/SSE transport runs the MCP server as a standalone HTTP server. This mode is designed for scenarios where STDIO communication is impractical, such as:

  • Running headed browsers on headless systems
  • Integration with IDE worker processes
  • Remote client access via HTTP
  • Multi-client concurrent connections
graph TD
    A[MCP Client<br/>VS Code / Custom] -->|HTTP/REST| B[HTTP Server<br/>127.0.0.1:8931]
    B --> C[SSE Transport<br/>Server-Sent Events]
    B --> D[Message Handler<br/>POST /messages]
    C --> E[Session Manager]
    D --> E
    E --> F[Playwright MCP<br/>Tool Handler]
    F --> G[Browser Instance]

Available Endpoints

The HTTP server exposes the following endpoints:

EndpointMethodPurpose
/sseGETServer-Sent Events stream for push notifications
/messages?sessionId=<id>POSTSend JSON-RPC messages for a specific session
/mcpGETMCP unified endpoint (GET)
/mcp?sessionId=<id>POSTMCP unified endpoint (POST)
/healthGETHealth check endpoint

Sources: src/http-server.ts

Starting the HTTP Server

# Using npx
npx @executeautomation/playwright-mcp-server --port 8931

# Or after global installation
npm install -g @executeautomation/playwright-mcp-server
playwright-mcp-server --port 8931

Sources: examples/http-mode-example.md

HTTP Server Output

When started successfully, the server displays:

==============================================
Playwright MCP Server (HTTP Mode)
==============================================
Listening: 127.0.0.1:8931 (localhost only)
Version: <version>

SECURITY: Server is bound to localhost only.
          Not accessible from external networks.

ENDPOINTS:
- SSE Stream:     GET  http://localhost:8931/sse
- Messages:       POST http://localhost:8931/messages?sessionId=<id>
- MCP (unified):  GET  http://localhost:8931/mcp
- MCP (unified):  POST http://localhost:8931/mcp?sessionId=<id>
- Health Check:   GET  http://localhost:8931/health

Sources: src/http-server.ts

Client Configuration

#### Claude Desktop (HTTP)

{
  "mcpServers": {
    "playwright": {
      "url": "http://localhost:8931/mcp"
    }
  }
}

#### VS Code MCP Extension

{
  "name": "playwright",
  "url": "http://localhost:8931/mcp"
}

#### Health Check

curl http://localhost:8931/health

Sources: examples/http-mode-example.md

Security Model

The HTTP server binds exclusively to 127.0.0.1 (localhost) for security reasons:

SECURITY: Server binds to localhost only. Not accessible from external networks.

For remote access, SSH tunneling is recommended:

ssh -L 8931:localhost:8931 user@remote-server

Sources: src/http-server.ts

Mode Selection

Automatic Selection

The server automatically selects the transport mode based on:

  1. Presence of --port argument โ†’ HTTP/SSE mode
  2. Absence of --port argument โ†’ STDIO mode

Health Check Response

FieldDescription
statusHealth status (ok when healthy)
versionServer version
activeSessionsNumber of active MCP sessions

Example response:

{
  "status": "ok",
  "version": "1.0.10",
  "activeSessions": 2
}

Transport Comparison

AspectSTDIOHTTP/SSE
Communicationstdin/stdout pipesHTTP/REST
Multi-clientNoYes
Session supportNoYes (via sessionId)
Browser modeHeadlessHeadless or Headed
Claude Desktopโœ… SupportedโŒ Not supported
VS Codeโœ… Supportedโœ… Supported
Health endpointNoYes
Process lifecycleTied to clientIndependent

Sources: README.md

Logging Behavior

STDIO Mode

  • Logging automatically directed to files only
  • Console output kept clean for JSON-RPC communication
  • Logs written to ~/playwright-mcp-server.log

HTTP Mode

  • Standard logging to console and file
  • Request/response logging via middleware
  • Error context capture including:
  • Stack traces
  • Memory usage
  • Platform information
  • Request duration

Sources: src/logging/middleware.ts

Environment Variables

VariablePurposeApplicable Modes
PLAYWRIGHT_SKIP_BROWSER_DOWNLOADSkip browser binary downloadBoth
NODE_ENVSet runtime environmentBoth
PORTHTTP server port (alternative to CLI)HTTP

Sources: DOCKER.md

Sources: [README.md](https://github.com/executeautomation/mcp-playwright/blob/main/README.md)

Browser Automation Tools

Related topics: Device Emulation, API Testing Tools, Code Generation and Recording

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Tool Architecture

Continue reading this section for the full explanation and source context.

Section Base Class (BrowserToolBase)

Continue reading this section for the full explanation and source context.

Section Navigate Tool (playwrightnavigate)

Continue reading this section for the full explanation and source context.

Related topics: Device Emulation, API Testing Tools, Code Generation and Recording

Browser Automation Tools

Overview

The Browser Automation Tools constitute the core module of the mcp-playwright project, providing a comprehensive set of MCP (Model Context Protocol) tools for browser-based web automation and testing. These tools enable AI assistants and automated systems to interact with web pages programmatically, performing actions such as navigation, element interaction, content extraction, and response monitoring.

The module supports multiple browser engines (Chromium, Firefox, WebKit) and provides both headless and headed execution modes, making it suitable for a wide range of automation scenarios from simple web scraping to complex end-to-end testing.

Architecture Overview:

graph TD
    A[MCP Client] -->|JSON-RPC| B[Tool Handler]
    B --> C[Browser Tool Executor]
    C --> D[Browser Engine]
    D --> E[Chromium<br/>Firefox<br/>WebKit]
    
    F[Base Class] -->|Inheritance| C
    F --> G[Error Handling]
    F --> H[Page Validation]
    F --> I[Safe Execution]

Core Components

Tool Architecture

The browser automation tools follow an object-oriented architecture with a base class pattern. All browser tools inherit from BrowserToolBase, which provides common functionality including error handling, page validation, and safe execution wrappers.

Class Hierarchy:

graph TD
    A[BrowserToolBase] --> B[navigation.ts<br/>NavigateTool]
    A --> C[interaction.ts<br/>ClickTool, FillTool, etc.]
    A --> D[screenshot.ts<br/>ScreenshotTool]
    A --> E[console.ts<br/>ConsoleLogsTool]
    A --> F[output.ts<br/>PdfTool]
    A --> G[resize.ts<br/>ResizeTool]
    A --> H[useragent.ts<br/>CustomUserAgentTool]
    A --> I[response.ts<br/>ExpectResponseTool, AssertResponseTool]
    A --> J[visiblePage.ts<br/>VisibleTextTool, VisibleHtmlTool]
    
    K[ToolContext] --> A
    L[Browser, Page] --> A

Base Class (BrowserToolBase)

The BrowserToolBase class provides the foundation for all browser tools:

MethodPurpose
ensurePage(context)Returns the current page or null if unavailable
validatePageAvailable(context)Returns error response if page not initialized
safeExecute(context, operation)Wraps browser operations with error handling

File Reference: src/tools/browser/base.ts

Browser Tools Registry

All browser-requiring tools are registered in the BROWSER_TOOLS array and exposed through the MCP tool interface:

File Reference: src/tools/browser/index.ts, src/tools.ts

export const BROWSER_TOOLS = [
  "playwright_navigate",
  "playwright_screenshot",
  "playwright_click",
  "playwright_iframe_click",
  "playwright_iframe_fill",
  "playwright_fill",
  "playwright_select",
  "playwright_hover",
  "playwright_evaluate",
  "playwright_console_logs",
  "playwright_close",
  "playwright_get_visible_text",
  "playwright_get_visible_html",
  "playwright_click_and_switch_tab",
  "playwright_drag",
  "playwright_press_key",
  "playwright_save_as_pdf"
];

Navigation Tools

Navigate Tool (`playwright_navigate`)

The primary navigation tool for loading web pages in the browser.

Parameters:

ParameterTypeRequiredDescription
urlstringYesTarget URL to navigate to
browserTypestringNoBrowser engine: "chromium", "firefox", "webkit" (default: "chromium")
widthnumberNoViewport width in pixels (default: 1280)
heightnumberNoViewport height in pixels (default: 720)
timeoutnumberNoNavigation timeout in milliseconds
waitUntilstringNoNavigation wait condition
headlessbooleanNoRun browser in headless mode (default: false)

Multi-Browser Support:

Starting from version 1.0.2, the navigate tool supports specifying the browser type:

Multi-Browser Support: Firefox and WebKit in addition to Chromium
New browserType parameter for playwright_navigate tool
Supported browser types: "chromium" (default), "firefox", "webkit"
Sources: CHANGELOG.md

File Reference: src/tools/browser/navigation.ts

Interaction Tools

Interaction tools enable programmatic control over browser elements, including clicking, filling forms, hovering, and keyboard input.

Click Tool (`playwright_click`)

Clicks an element identified by a CSS selector.

Parameters:

ParameterTypeRequiredDescription
selectorstringYesCSS selector for the element to click
buttonstringNoMouse button: "left", "right", "middle" (default: "left")
clickCountnumberNoNumber of clicks (default: 1)
delaynumberNoDelay in milliseconds between key down and up
forcebooleanNoForce click even if element obscured
timeoutnumberNoTimeout in milliseconds
noWaitAfterbooleanNoDon't wait for navigation after click

Fill Tool (`playwright_fill`)

Fills input fields with text content.

Parameters:

ParameterTypeRequiredDescription
selectorstringYesCSS selector for the input element
valuestringYesText value to fill
delaynumberNoDelay between keystrokes in milliseconds
noWaitAfterbooleanNoDon't wait for navigation after fill

Select Tool (`playwright_select`)

Selects options in dropdown menus (select elements).

Parameters:

ParameterTypeRequiredDescription
selectorstringYesCSS selector for the select element
valuestring/arrayYesOption value(s) to select
indexarrayNoOption index(es) to select
labelstring/arrayNoOption label(s) to select
timeoutnumberNoTimeout in milliseconds

Hover Tool (`playwright_hover`)

Hovers over an element.

Parameters:

ParameterTypeRequiredDescription
selectorstringYesCSS selector for the element to hover
timeoutnumberNoTimeout in milliseconds

Keyboard Interaction

Drag Tool (playwright_drag):

ParameterTypeRequiredDescription
sourceSelectorstringYesCSS selector for source element
targetSelectorstringYesCSS selector for target element

Press Key Tool (playwright_press_key):

ParameterTypeRequiredDescription
selectorstringNoCSS selector for element to focus
keystringYesKey to press (e.g., "Enter", "Tab", "Escape")

iFrame Interaction

The project supports interaction with elements inside iframes through dedicated tools:

ToolDescription
playwright_iframe_clickClick element within an iframe
playwright_iframe_fillFill input within an iframe

File Reference: src/tools/browser/interaction.ts

Screenshot Tools

Screenshot Tool (`playwright_screenshot`)

Captures screenshots of the current page or specific elements.

Parameters:

ParameterTypeRequiredDescription
namestringNoName for the screenshot
selectorstringNoCSS selector for element to screenshot
widthnumberNoWidth in pixels (default: 800)
heightnumberNoHeight in pixels (default: 600)
storeBase64booleanNoStore in base64 format (default: true)
fullPagebooleanNoScreenshot entire page (default: false)
savePngbooleanNoSave as PNG file (default: false)
downloadsDirstringNoCustom downloads directory path

File Reference: src/tools/browser/screenshot.ts

Content Extraction Tools

Visible Text Tool (`playwright_get_visible_text`)

Extracts visible text content from the page or specific elements.

Parameters:

ParameterTypeRequiredDescription
selectorstringNoCSS selector to extract text from specific element
includeHiddenbooleanNoInclude hidden elements (default: false)
removeLineBreaksbooleanNoRemove line breaks (default: false)
trimTextbooleanNoTrim whitespace (default: true)

Visible HTML Tool (`playwright_get_visible_html`)

Retrieves HTML content from the page or elements.

Parameters:

ParameterTypeRequiredDescription
selectorstringNoCSS selector for specific element
removeScriptsbooleanNoRemove script tags
removeCommentsbooleanNoRemove HTML comments
removeStylesbooleanNoRemove style tags
removeMetabooleanNoRemove meta tags
cleanHtmlbooleanNoApply all cleanup filters
minifybooleanNoMinify the HTML output

Content Filtering Pipeline:

graph LR
    A[Raw HTML] --> B{removeScripts?}
    B -->|Yes| C[Remove script tags]
    B -->|No| D[Continue]
    C --> E{removeStyles?}
    E -->|Yes| F[Remove style tags]
    E -->|No| G[Continue]
    F --> H{removeMeta?}
    H -->|Yes| I[Remove meta tags]
    H -->|No| J[Continue]
    I --> K{removeComments?}
    K -->|Yes| L[Remove comments]
    K -->|No| M[Continue]
    L --> N{minify?}
    M --> N
    N -->|Yes| O[Minify HTML]
    N -->|No| P[Return Clean HTML]

File Reference: src/tools/browser/visiblePage.ts

Output Tools

PDF Generation Tool (`playwright_save_as_pdf`)

Saves the current page as a PDF document.

Parameters:

ParameterTypeRequiredDescription
outputPathstringYesPath where PDF will be saved
namestringNoPDF filename (default: "page.pdf")
formatstringNoPage format: "A4", "Letter", etc.
printBackgroundbooleanNoInclude background graphics
marginobjectNoPage margins (top, right, bottom, left)

File Reference: src/tools/browser/output.ts

Console Tools

Console Logs Tool (`playwright_console_logs`)

Retrieves console messages from the browser page.

Parameters:

ParameterTypeRequiredDescription
typestringNoFilter by message type: "log", "info", "warn", "error"
textstringNoFilter by text content (partial match)
regexstringNoFilter by regex pattern

Console Message Types:

TypeDescription
logGeneral console logs
infoInformational messages
warnWarning messages
errorError messages

File Reference: src/tools/browser/console.ts

Response Monitoring Tools

Expect Response Tool (`playwright_expect_response`)

Sets up expectations for network responses.

Parameters:

ParameterTypeRequiredDescription
urlstringNoURL pattern to match (regex or string)
statusCodenumberNoExpected HTTP status code
timeoutnumberNoTimeout in milliseconds
methodstringNoHTTP method filter

Assert Response Tool (`playwright_assert_response`)

Asserts that a network response meets specified criteria.

Parameters:

ParameterTypeRequiredDescription
urlstringNoURL pattern to match
statusCodenumberNoExpected HTTP status code
methodstringNoHTTP method filter

File Reference: src/tools/browser/response.ts

Viewport and Device Emulation

Resize Tool (`playwright_resize`)

Configures viewport dimensions and enables device emulation.

Parameters:

ParameterTypeRequiredDescription
devicestringNoDevice name for emulation (e.g., "iPhone 13", "iPad Pro 11")
widthnumberNoViewport width in pixels
heightnumberNoViewport height in pixels
orientationstringNoDevice orientation: "portrait", "landscape"
scalenumberNoDevice scale factor
mobilebooleanNoEnable mobile emulation

Device Emulation Features:

  • 143 real device presets including iPhone, iPad, Pixel, Galaxy, and Desktop browsers
  • Automatic user-agent string configuration
  • Touch event support emulation
  • Device pixel ratio configuration

Natural Language Support:

AI assistants can use natural language prompts such as:

  • "Test on iPhone 13"
  • "Switch to iPad view"
  • "Rotate to landscape"

File Reference: src/tools/browser/resize.ts

User Agent Tools

Custom User Agent Tool (`playwright_custom_user_agent`)

Sets a custom user agent string for the browser context.

Parameters:

ParameterTypeRequiredDescription
userAgentstringYesCustom user agent string

File Reference: src/tools/browser/useragent.ts

Browser Lifecycle Management

Close Tool (`playwright_close`)

Closes the current browser context and page.

Parameters:

ParameterTypeRequiredDescription
closeBrowserbooleanNoClose the entire browser (default: false)

Error Handling

The browser tools implement comprehensive error handling through the middleware system:

Error Categories:

CategoryIndicators
validationInvalid parameters, missing required fields
resourceBrowser closed, page disconnected, protocol errors
authenticationUnauthorized, forbidden, access denied
rate_limitToo many requests, throttling
systemTimeout, element not found, navigation failures

Enhanced Error Context:

The logging middleware captures detailed error context including:

  • Error name and message
  • Stack trace
  • Timestamp
  • Node.js version and platform
  • Memory usage statistics
  • Browser state information

File Reference: src/logging/middleware.ts

Tool Execution Flow

Complete Tool Execution Pipeline:

sequenceDiagram
    participant Client
    participant MCP_Server
    participant Middleware
    participant Tool
    participant Browser
    
    Client->>MCP_Server: Tool Request
    MCP_Server->>Middleware: Intercept Request
    Middleware->>Middleware: Log Start
    Middleware->>Tool: Execute Tool
    Tool->>Browser: Browser Operation
    Browser-->>Tool: Operation Result
    Tool-->>Middleware: Tool Response
    Middleware->>Middleware: Log Completion
    Middleware-->>Client: Response

Summary

The Browser Automation Tools module provides a comprehensive, MCP-compatible interface for browser automation tasks. Key features include:

Feature CategoryCapabilities
NavigationMulti-browser support (Chromium, Firefox, WebKit), configurable viewport
InteractionClick, fill, select, hover, drag, keyboard input, iframe support
Content ExtractionVisible text, HTML with filtering/minification
OutputScreenshots, PDF generation
MonitoringConsole logs, network response expectations
Emulation143 device presets, custom user agents

All tools follow a consistent pattern with base class inheritance, comprehensive error handling, and structured logging for debugging and monitoring purposes.

Source: https://github.com/executeautomation/mcp-playwright / Human Manual

Device Emulation

Related topics: Browser Automation Tools

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Component Flow

Continue reading this section for the full explanation and source context.

Section Tool: playwrightresize

Continue reading this section for the full explanation and source context.

Section Popular Devices

Continue reading this section for the full explanation and source context.

Related topics: Browser Automation Tools

Device Emulation

Device Emulation is a core feature of the Playwright MCP Server that enables AI assistants and automated testing tools to simulate real-world mobile and desktop devices directly within the browser automation framework. By leveraging Playwright's built-in device descriptor library, the server provides 143 real device presets with accurate viewport dimensions, user-agent strings, touch capabilities, and device pixel ratios.

Overview

The Device Emulation system integrates with the playwright_resize tool to provide a seamless interface for switching between device profiles. When a device preset is selected, the system automatically configures multiple browser properties simultaneously:

  • Viewport dimensions for accurate screen rendering
  • User-Agent strings for proper server-side device detection
  • Touch capabilities for mobile device simulation
  • Device pixel ratio for high-DPI display accuracy

Sources: README.md

Architecture

graph TD
    A[AI Assistant / MCP Client] --> B[playwright_resize Tool]
    B --> C{Device Preset?}
    C -->|Yes| D[Lookup in Playwright devices]
    C -->|No| E[Direct Dimensions]
    D --> F[Extract Device Properties]
    F --> G[page.setViewportSize]
    F --> H[page.setExtraHTTPHeaders]
    G --> I[Browser Context Updated]
    H --> I
    E --> G

Component Flow

  1. Client Request: The AI assistant or MCP client sends a playwright_resize call with a device parameter
  2. Device Lookup: The system searches Playwright's device descriptor library using the provided name
  3. Property Extraction: Device properties including viewport, user-agent, mobile flag, touch support, and scale factor are extracted
  4. Browser Configuration: Playwright APIs apply the settings to the active page context

Sources: src/tools/browser/resize.ts:17-48

API Reference

Tool: `playwright_resize`

The primary tool for device emulation and viewport control.

#### Parameters

ParameterTypeRequiredDescription
devicestringNoDevice preset name (e.g., "iPhone 13", "iPad Pro 11")
widthnumberConditionalViewport width in pixels (default: 1280)
heightnumberConditionalViewport height in pixels (default: 720)
orientationstringNo"portrait" or "landscape" (only valid with device preset)
maxLengthnumberNoMaximum response length for HTML content (default: 20000)

#### Device Preset Detection

The system validates device names against Playwright's device library and returns helpful suggestions if the device is not found:

if (!device) {
  return createErrorResponse(
    `Device "${args.device}" not found. Popular devices: ${popularDevices.join(', ')}. ` +
    `Use playwright.devices to see all ${Object.keys(devices).length} available devices.`
  );
}

Sources: src/tools/browser/resize.ts:36-43

Supported Devices

The Playwright MCP Server includes support for 143 device presets covering major device categories:

CategoryDevices
iPhoneiPhone 13, iPhone 13 Pro, iPhone 14, iPhone 15, iPhone 15 Pro Max
iPadiPad Pro 11, iPad Pro 12.9, iPad Air, iPad Mini
PixelPixel 5, Pixel 7, Pixel 8, Pixel 8 Pro
GalaxyGalaxy S9+, Galaxy S10+, Galaxy S24, Galaxy S24 Ultra
DesktopDesktop Chrome, Desktop Firefox, Desktop Safari

Device Properties Extracted

When using a device preset, the following properties are automatically configured:

// Extract device properties from Playwright's device library
width = device.defaultBrowserViewport.width;
height = device.defaultBrowserViewport.height;
userAgent = device.defaultUserAgent;
isMobile = device.defaultBrowserType === 'mobile';
hasTouch = device.hasTouch;
deviceScaleFactor = device.deviceScaleFactor || 1;

Sources: src/tools/browser/resize.ts:48-54

Orientation Support

Device emulation supports both portrait and landscape orientations. When an orientation is specified with a device preset, the width and height values are swapped:

// Portrait orientation (default)
await playwright_resize({ device: "iPhone 13", orientation: "portrait" });

// Landscape orientation
await playwright_resize({ device: "iPad Pro 11", orientation: "landscape" });

Orientation Logic

graph LR
    A[Device Preset] --> B{orientation === "landscape"}
    B -->|Yes| C[Swap width โ†” height]
    B -->|No| D[Keep original dimensions]
    C --> E[Apply to Viewport]
    D --> E

The orientation parameter is validated to ensure it is only used with device presets:

if (args.orientation && !args.device) {
  throw new Error("Orientation can only be set when using a device preset");
}

Sources: src/tools/browser/resize.ts:71-74

Validation Rules

The device emulation system enforces several validation constraints:

Dimension Constraints

RuleValueError Message
Minimum dimension> 0"Width and height must be positive integers"
Maximum dimensionโ‰ค 7680 ร— 4320"Width and height must not exceed 7680x4320 (8K resolution)"

Parameter Constraints

ConstraintCondition
Orientation requires deviceorientation parameter cannot be used standalone
Device validationName must exist in Playwright's device library

Sources: src/tools/browser/resize.ts:81-91

Natural Language Support

The device emulation system is designed to work seamlessly with AI assistants that use natural language commands. Common prompt patterns include:

  • "Test on iPhone 13"
  • "Switch to iPad view"
  • "Rotate to landscape"
  • "Test desktop view"

These natural language commands are interpreted by the AI assistant and translated into playwright_resize tool calls with the appropriate device and orientation parameters.

Sources: README.md

Implementation Details

Base Class Integration

The ResizeTool extends BrowserToolBase, which provides the foundation for browser interaction:

export class ResizeTool extends BrowserToolBase {
  async execute(args: any, context: ToolContext): Promise<ToolResponse> {
    return this.safeExecute(context, async (page) => {
      // Device emulation logic
    });
  }
}

Error Handling

The implementation uses a safe execution pattern with comprehensive error handling:

private categorizeError(error: Error): 'validation' | 'system' | 'unknown' {
  const message = error.message.toLowerCase();
  
  if (message.includes('invalid') || message.includes('validation') || message.includes('required')) {
    return 'validation';
  }
  
  if (message.includes('browser') || message.includes('page') || message.includes('connection')) {
    return 'system';
  }
  
  return 'unknown';
}

Sources: src/tools/browser/resize.ts:7-11 Sources: src/logging/middleware.ts

Response Format

Success Response

When device emulation is successfully applied, the response includes:

Browser viewport resized to iPhone 13 (390x844) [mobile, touch, 3x scale]

The response includes:

  • Device name and dimensions
  • Orientation (if specified)
  • Applied features: mobile, touch, device scale factor

Error Response

If device emulation fails, an error response is returned with:

  • Specific error message explaining the failure
  • Suggestions for popular devices when device name is not found
  • Reference to available device count

Sources: src/tools/browser/resize.ts:95-120

Tool Registration

The playwright_resize tool is registered in the central tools registry:

{
  name: "playwright_resize",
  description: "Resize browser viewport with optional device emulation",
  inputSchema: {
    type: "object",
    properties: {
      device: { type: "string", description: "Device preset name" },
      width: { type: "number", description: "Viewport width in pixels" },
      height: { type: "number", description: "Viewport height in pixels" },
      orientation: { type: "string", description: "Device orientation" }
    }
  }
}

Sources: src/tools.ts

Dependencies

The device emulation feature relies on the following package dependencies:

PackageVersionPurpose
playwright1.57.0Core browser automation with device descriptors
@playwright/browser-chromium1.57.0Chromium browser support
@playwright/browser-firefox1.57.0Firefox browser support
@playwright/browser-webkit1.57.0WebKit browser support

Sources: package.json

Usage Examples

Basic Device Emulation

// Test on iPhone 13
await playwright_resize({ device: "iPhone 13" });

// Result: Browser viewport resized to iPhone 13 (390x844) [mobile, touch, 2x scale]

Landscape Orientation

// iPad in landscape mode
await playwright_resize({ device: "iPad Pro 11", orientation: "landscape" });

// Result: Browser viewport resized to iPad Pro 11 (1194x834) in landscape orientation [mobile, touch, 2x scale]

Desktop Browser

// Switch to desktop Chrome view
await playwright_resize({ device: "Desktop Chrome" });

// Result: Browser viewport resized to Desktop Chrome (1280x720)

Custom Dimensions

// Direct viewport control without device preset
await playwright_resize({ width: 1920, height: 1080 });

// Result: Browser viewport resized to 1920x1080

Integration with Other Tools

Device emulation settings persist across multiple tool calls within a session. Other tools that may interact with device emulation include:

ToolInteraction
playwright_screenshotCaptures screenshots at device resolution
playwright_get_visible_htmlExtracts HTML content rendered at device viewport
playwright_navigateCan be combined with device presets for full mobile testing

The viewport and user-agent settings remain active until explicitly changed by another playwright_resize call.

Sources: src/tools/browser/visiblePage.ts Sources: src/tools/browser/screenshot.ts

Sources: [README.md](https://github.com/executeautomation/mcp-playwright/blob/main/README.md)

API Testing Tools

Related topics: Browser Automation Tools, Code Generation and Recording

Section Related Pages

Continue reading this section for the full explanation and source context.

Section High-Level Architecture

Continue reading this section for the full explanation and source context.

Section Module Structure

Continue reading this section for the full explanation and source context.

Section API Tool Base Class

Continue reading this section for the full explanation and source context.

Related topics: Browser Automation Tools, Code Generation and Recording

API Testing Tools

Overview

The API Testing Tools module in MCP Playwright provides a comprehensive framework for executing and validating HTTP API requests directly within the Model Context Protocol server environment. This module enables AI assistants and automated testing systems to perform REST API testing operations with full request/response tracking, assertion capabilities, and detailed logging support.

The API Testing Tools extend the MCP Playwright server's functionality beyond browser automation to include robust HTTP client capabilities. This allows for seamless integration of API testing workflows alongside browser-based UI testing, enabling end-to-end testing scenarios that span both frontend and backend interactions.

Architecture

High-Level Architecture

graph TD
    A[MCP Client Request] --> B[Tool Router]
    B --> C[API Testing Module]
    C --> D[Request Executor]
    D --> E[HTTP Client]
    E --> F[External API]
    F --> G[Response Handler]
    G --> H[Assertion Engine]
    H --> I[Tool Response]
    D --> J[Logging Middleware]
    J --> K[Request Logs]
    
    L[Request Builder] --> D
    M[Auth Handler] --> L
    N[Header Manager] --> L

Module Structure

The API Testing Tools are organized into three primary components following the project's modular architecture pattern:

ComponentFileResponsibility
API Indexsrc/tools/api/index.tsTool registration and routing
API Basesrc/tools/api/base.tsBase class with common functionality
Request Handlersrc/tools/api/requests.tsHTTP request execution and response handling

Core Components

API Tool Base Class

The base class for all API tools provides common functionality that mirrors the browser tool architecture while adapting for HTTP operations. This design ensures consistency with the broader MCP Playwright tool framework.

// Pattern inherited from browser base architecture
export abstract class ApiToolBase implements ToolHandler {
  protected server: any;
  
  constructor(server: any) {
    this.server = server;
  }
  
  abstract execute(args: any, context: ToolContext): Promise<ToolResponse>;
  
  protected ensureContext(context: ToolContext): ApiContext | null;
  protected validateRequest(args: any): ToolResponse | null;
  protected safeExecute(context: ToolContext, operation: ...): Promise<ToolResponse>;
}

Sources: src/tools/api/base.ts

Tool Registry and Handler

The API module registers its tools with the MCP server through the standard tool handler interface defined in the types system:

export interface Tool {
  name: string;
  description: string;
  parameters: {
    type: string;
    properties: Record<string, unknown>;
    required?: string[];
  };
  handler: (args: any) => Promise<any>;
}

Sources: src/types.ts:1-15

Request Builder and Executor

The request handler component manages the construction and execution of HTTP requests, supporting various HTTP methods and authentication mechanisms.

Sources: src/tools/api/requests.ts

Available API Testing Tools

Response Expectation Tool

The playwright_expect_response tool allows tests to verify expected HTTP response characteristics before proceeding with further assertions. This tool enables proactive validation of API responses.

Parameters:

ParameterTypeRequiredDescription
urlstringYesTarget API endpoint URL
methodstringNoHTTP method (GET, POST, PUT, DELETE, etc.)
expectedStatusnumberNoExpected HTTP status code
expectedBodyobjectNoExpected response body content
timeoutnumberNoRequest timeout in milliseconds

Sources: CHANGELOG.md

Response Assertion Tool

The playwright_assert_response tool provides comprehensive response validation capabilities, comparing actual API responses against expected values with detailed error reporting.

Parameters:

ParameterTypeRequiredDescription
urlstringYesTarget API endpoint URL
expectedHeadersobjectNoExpected response headers
expectedBodyobjectNoExpected response body pattern
schemaobjectNoJSON Schema for response validation
exactMatchbooleanNoWhether to require exact body matching

Sources: CHANGELOG.md

Custom User Agent Tool

The playwright_custom_user_agent tool enables modification of the User-Agent header for API requests, supporting scenarios requiring specific client identification or browser emulation.

Parameters:

ParameterTypeRequiredDescription
userAgentstringYesCustom User-Agent string
persistbooleanNoWhether to persist for subsequent requests

Sources: CHANGELOG.md

Optional Bearer Authorization

API testing tools support optional Bearer token authentication for secured endpoints. This is configured at the request level and follows RFC 6750 specifications.

Configuration:

{
  "url": "https://api.example.com/protected",
  "method": "GET",
  "authorization": {
    "type": "bearer",
    "token": "${API_TOKEN}"
  }
}

Sources: CHANGELOG.md

Request Lifecycle

sequenceDiagram
    participant MCP as MCP Client
    participant API as API Tool Module
    participant LOG as Logging Middleware
    participant HTTP as HTTP Client
    participant EXT as External API
    
    MCP->>API: Tool Call Request
    API->>LOG: Log Tool Start
    LOG->>LOG: Capture Request Context
    API->>API: Validate Parameters
    API->>HTTP: Execute Request
    HTTP->>EXT: HTTP Request
    EXT-->>HTTP: HTTP Response
    HTTP-->>API: Raw Response
    API->>API: Process Response
    API->>API: Run Assertions
    API->>LOG: Log Tool Completion
    LOG-->>API: Log Entry Created
    API-->>MCP: Tool Response

Logging and Monitoring

Request Logging

The logging middleware captures detailed information about API tool executions, following the same pattern used for browser tools. Each API request generates a structured log entry with timing information and sanitized parameter data.

Logging Context Structure:

interface RequestLogContext {
  method: 'TOOL_CALL';
  url: string;
  body?: any;
  statusCode?: number;
  duration?: number;
}

Sources: src/logging/middleware.ts:10-16

Error Handling and Categorization

The logging middleware provides comprehensive error categorization for API-related errors:

Error CategoryDetection PatternsDescription
validationinvalid, validation, required, missing parameterRequest validation failures
resourcebrowser, page, connection, closed, disconnectedResource availability issues
authenticationunauthorized, forbidden, access deniedAuth-related failures
rate_limitrate limit, too many requests, throttleRate limiting responses

Sources: src/logging/middleware.ts:85-120

Sanitization

Sensitive data within API requests is automatically sanitized in logs:

const sensitiveFields = ['password', 'token', 'secret', 'key', 'auth'];
// These fields are replaced with '[REDACTED]' in logs

Sources: src/logging/middleware.ts:180-190

Integration with Browser Tools

The API Testing Tools are designed to work alongside browser automation tools, enabling comprehensive end-to-end testing scenarios:

graph LR
    A[playwright_navigate] --> B[Browser Actions]
    B --> C[Extract Data]
    C --> D[API Validation]
    D --> E[playwright_expect_response]
    E --> F[API Assertions]
    F --> G[playwright_assert_response]
    G --> H[Test Results]

This integration allows for scenarios such as:

  1. Data-Driven Testing: Extract test data from the UI using browser tools, then validate against API responses
  2. State Verification: Use API tools to verify backend state after browser interactions
  3. Hybrid Workflows: Combine UI automation with API validation for complete coverage

Configuration

Environment Variables

VariableDescriptionDefault
PLAYWRIGHT_SKIP_BROWSER_DOWNLOADSkip browser downloads (for API-only usage)0
NODE_ENVNode environment settingproduction
OPENAI_API_KEYAPI key for evaluation framework-

Sources: DOCKER.md

Timeout Configuration

API tool timeouts are configurable at the tool call level and can be set per-request:

{
  "timeout": 30000,  // 30 seconds
  "retries": 0       // No automatic retries by default
}

Error Handling Patterns

Tool Response Structure

All API tools return responses following the standard ToolResponse format:

interface ToolResponse {
  content: Array<{
    type: 'text';
    text: string;
  }>;
  isError?: boolean;
}

Sources: src/tools/common/types.ts

Common Error Scenarios

ScenarioError TypeHandling
Invalid URLvalidationReturn error response with message
Connection timeoutresourceLog with timeout details
Invalid JSON responsevalidationInclude parse error in response
Server error (5xx)systemLog with response details

Best Practices

  1. Use Assertions Early: Use playwright_expect_response for early failure detection in test suites
  2. Sanitize Sensitive Data: Ensure credentials are not logged by using environment variables
  3. Set Appropriate Timeouts: Configure timeouts based on expected API response times
  4. Combine with Browser Tools: Leverage both API and browser tools for comprehensive testing
  5. Monitor Logs: Review logging output for performance analysis and debugging

Source: https://github.com/executeautomation/mcp-playwright / Human Manual

Code Generation and Recording

Related topics: Browser Automation Tools, API Testing Tools

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Core Components

Continue reading this section for the full explanation and source context.

Section CodegenAction

Continue reading this section for the full explanation and source context.

Section CodegenSession

Continue reading this section for the full explanation and source context.

Related topics: Browser Automation Tools, API Testing Tools

Code Generation and Recording

The Code Generation and Recording system is a module within the MCP Playwright server that enables automatic conversion of MCP tool interactions into executable Playwright test code. This feature captures user actions performed through MCP tools during browser automation sessions and transforms them into structured test cases that can be replayed using Playwright's native test runner.

Overview

The codegen module serves as a bridge between exploratory testing and automated test creation. When developers or AI assistants interact with web applications using MCP Playwright tools (such as playwright_click, playwright_navigate, playwright_fill, etc.), the codegen system records these actions with their parameters and results. Upon session completion, this recorded data can be converted into self-contained Playwright test files.

Sources: src/tools/codegen/index.ts:1-30

Architecture

The codegen system follows a two-phase architecture: Recording and Generation.

graph TD
    A[MCP Tool Execution] --> B[ActionRecorder]
    B --> C[CodegenSession Store]
    C --> D[Session Actions]
    D --> E[PlaywrightGenerator]
    E --> F[Generated Test Code]
    G[CodegenOptions] --> E
    
    style A fill:#e1f5fe
    style F fill:#c8e6c9
    style B fill:#fff3e0
    style E fill:#fff3e0

Core Components

ComponentFileResponsibility
ActionRecorderrecorder.tsCaptures and stores tool execution data
PlaywrightGeneratorgenerator.tsTransforms recorded sessions into test code
CodegenSessiontypes.tsData model for tracking a recording session
CodegenOptionstypes.tsConfiguration for code generation behavior

Sources: src/tools/codegen/types.ts:1-35

Data Models

The codegen module defines several TypeScript interfaces that structure the recording and generation process.

CodegenAction

Represents a single recorded action during a codegen session.

export interface CodegenAction {
  toolName: string;
  parameters: Record<string, unknown>;
  timestamp: number;
  result?: unknown;
}
FieldTypeDescription
toolNamestringThe name of the MCP tool that was executed
parametersRecord<string, unknown>Arguments passed to the tool
timestampnumberUnix timestamp when the action occurred
resultunknownOptional result returned by the tool execution

Sources: src/tools/codegen/types.ts:1-10

CodegenSession

Represents an entire recording session containing multiple actions.

export interface CodegenSession {
  id: string;
  actions: CodegenAction[];
  startTime: number;
  endTime?: number;
  options?: CodegenOptions;
}
FieldTypeDescription
idstringUnique identifier for the session
actionsCodegenAction[]Ordered list of recorded actions
startTimenumberSession start timestamp
endTimenumberOptional session end timestamp
optionsCodegenOptionsOptional generation configuration

Sources: src/tools/codegen/types.ts:12-20

CodegenOptions

Configuration options that control code generation behavior.

export interface CodegenOptions {
  outputPath?: string;
  testNamePrefix?: string;
  includeComments?: boolean;
}
OptionTypeDefaultDescription
outputPathstring'e2e'Directory path where generated test files are written
testNamePrefixstring'Test'Prefix added to generated test names
includeCommentsbooleantrueWhether to include explanatory comments in generated code

Sources: src/tools/codegen/types.ts:26-32

CodegenResult

Output returned after generating test code from a session.

export interface CodegenResult {
  testCode: string;
  filePath: string;
  sessionId: string;
}
FieldTypeDescription
testCodestringThe generated Playwright test code
filePathstringPath where the test file was or will be written
sessionIdstringReference to the originating session

Sources: src/tools/codegen/types.ts:34-40

Available Tools

The codegen module exposes the following MCP tools for managing sessions.

start_codegen_session

Initiates a new recording session for capturing MCP tool actions.

export const startCodegenSession: Tool = {
  name: 'start_codegen_session',
  description: 'Start a new code generation session to record MCP tool actions',
  parameters: {
    type: 'object',
    properties: {
      options: {
        type: 'object',
        description: 'Code generation options',
        properties: {
          outputPath: { type: 'string' },
          testNamePrefix: { type: 'string' },
          includeComments: { type: 'boolean' }
        }
      }
    }
  },
  // ...
};

Parameters:

ParameterTypeRequiredDescription
optionsobjectNoConfiguration for the codegen session
options.outputPathstringNoCustom output directory for generated tests
options.testNamePrefixstringNoPrefix for generated test names
options.includeCommentsbooleanNoEnable/disable code comments

Sources: src/tools/codegen/index.ts:37-58

PlaywrightGenerator Class

The PlaywrightGenerator class handles the transformation of recorded sessions into executable Playwright test code.

Constructor and Configuration

export class PlaywrightGenerator {
  private static readonly DEFAULT_OPTIONS: Required<CodegenOptions> = {
    outputPath: 'tests',
    testNamePrefix: 'MCP',
    includeComments: true,
  };

  private options: Required<CodegenOptions>;

  constructor(options: CodegenOptions = {}) {
    this.validateOptions(options);
    this.options = { ...PlaywrightGenerator.DEFAULT_OPTIONS, ...options };
  }
}
Default OptionValueDescription
outputPath'tests'Default directory for generated test files
testNamePrefix'MCP'Default prefix for test names
includeCommentstrueComments included by default

Sources: src/tools/codegen/generator.ts:1-20

Options Validation

The generator performs strict validation on provided options before initializing.

private validateOptions(options: CodegenOptions): void {
  if (options.outputPath && typeof options.outputPath !== 'string') {
    throw new Error('outputPath must be a string');
  }
  if (options.testNamePrefix && typeof options.testNamePrefix !== 'string') {
    throw new Error('testNamePrefix must be a string');
  }
  if (options.includeComments !== undefined && typeof options.includeComments !== 'boolean') {
    throw new Error('includeComments must be a boolean');
  }
}

All options are validated for correct types before being applied, ensuring runtime errors are prevented during test generation.

Sources: src/tools/codegen/generator.ts:22-33

Test Generation Process

async generateTest(session: CodegenSession): Promise<CodegenResult> {
  if (!session || !Array.isArray(session.actions)) {
    throw new Error('Invalid session data');
  }

  const testCase = this.createTestCase(session);
  const testCode = this.generateTestCode(testCase);
  const filePath = this.getOutputFilePath(session);

  return {
    testCode,
    filePath,
    sessionId: session.id,
  };
}

The generation process consists of three steps:

  1. Create Test Case - Transforms session actions into a structured PlaywrightTestCase
  2. Generate Test Code - Converts the test case into Playwright test syntax
  3. Determine Output Path - Resolves the file path based on session ID and configuration

Sources: src/tools/codegen/generator.ts:35-50

Recording Workflow

sequenceDiagram
    participant User
    participant MCP as MCP Server
    participant Recorder as ActionRecorder
    participant Store as CodegenSession Store
    
    User->>MCP: start_codegen_session(options)
    MCP->>Recorder: createSession(options)
    Recorder->>Store: initialize session
    Note over Store: Session ID generated
    
    User->>MCP: playwright_click(selector)
    MCP->>Recorder: record(toolName, args, result)
    Recorder->>Store: append action
    
    User->>MCP: playwright_navigate(url)
    MCP->>Recorder: record(toolName, args, result)
    Recorder->>Store: append action
    
    User->>MCP: stop_codegen_session()
    MCP->>Recorder: finalize session
    Recorder->>Store: set endTime

PlaywrightTestCase Structure

The intermediate representation used during code generation:

export interface PlaywrightTestCase {
  name: string;
  steps: string[];
  imports: Set<string>;
}
FieldTypeDescription
namestringTest case name derived from prefix and session info
stepsstring[]Lines of Playwright test code
importsSet<string>Required import statements for the test

Sources: src/tools/codegen/types.ts:22-26

Output Path Resolution

The system uses the workspace root as the base directory for generated tests:

const getWorkspaceRoot = () => {
  return process.cwd();
};

const DEFAULT_OPTIONS: Required<CodegenOptions> = {
  outputPath: path.join(getWorkspaceRoot(), 'e2e'),
  testNamePrefix: 'Test',
  includeComments: true
};

Output paths are handled as follows:

  • Absolute paths are used as-is
  • Relative paths are resolved from the current working directory

Sources: src/tools/codegen/index.ts:20-30

Integration with MCP Tool Execution

The recording system intercepts MCP tool calls to capture execution data. Each recorded action preserves:

  • The exact tool name (e.g., playwright_click, playwright_fill)
  • All parameters passed to the tool
  • The timestamp of execution
  • Optional result data from the tool

This captured data enables precise reproduction of user interactions when the generated test is executed.

Error Handling

The generator validates input at initialization and during generation:

ValidationConditionError
Session validityMust exist with actions array'Invalid session data'
Output path typeMust be string if provided'outputPath must be a string'
Test name typeMust be string if provided'testNamePrefix must be a string'
Comments typeMust be boolean if provided'includeComments must be a boolean'

Sources: src/tools/codegen/generator.ts:22-33

Usage Example

# Start a recording session with custom options
npx @executeautomation/playwright-mcp-server

# Within your MCP client, call:
# start_codegen_session with options { outputPath: "./tests", testNamePrefix: "E2E" }

# Perform actions using playwright_* tools
# playwright_navigate, playwright_click, etc. are recorded

# Generate test code from the session

The generated test code can then be executed with:

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

Sources: [src/tools/codegen/index.ts:1-30]()

Docker Deployment

Related topics: Getting Started, Configuration Guide

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Standard Build Process

Continue reading this section for the full explanation and source context.

Section Automated Build Script

Continue reading this section for the full explanation and source context.

Section Build with Custom Tag

Continue reading this section for the full explanation and source context.

Related topics: Getting Started, Configuration Guide

Docker Deployment

Overview

The Playwright MCP Server provides Docker containerization support, enabling isolated execution environments for browser automation tasks. Docker deployment offers consistent runtime across different systems, simplified dependency management, and easy distribution of the MCP server.

The containerized solution is designed to work with pre-built artifacts from a local build, ensuring minimal image size while maintaining full functionality for browser automation through the MCP protocol.

Sources: DOCKER.md

Architecture

graph TD
    subgraph "Host System"
        A[Local Build Directory] -->|npm install --omit=dev| B[node_modules]
        A -->|npm run build| C[dist/]
    end
    
    subgraph "Docker Container"
        D[Dockerfile] -->|COPY| E[mcp-playwright:latest]
        B -->|Production deps| E
        C -->|Built artifacts| E
    end
    
    subgraph "Runtime Components"
        E -->|stdin/stdout| F[MCP Client]
        E -->|Browser Automation| G[Playwright Browsers]
    end
    
    F -->|JSON-RPC| H[Claude Desktop / VS Code / Custom Client]

Prerequisites

ComponentRequirementPurpose
DockerInstalled on host systemContainer runtime
Docker ComposeOptional (included with Docker Desktop)Multi-container orchestration
Node.jsFor building locallyPre-build step
Local Buildnpm install --omit=dev && npm run buildGenerate artifacts for Docker COPY

Sources: DOCKER.md:prerequisites-section

Building the Docker Image

Standard Build Process

The Dockerfile copies node_modules and dist from the local build directory directly into the image. This approach requires building artifacts locally before containerization.

# 1. Install production dependencies only
npm install --omit=dev

# 2. Build the project
npm run build

# 3. Build the Docker image
docker build -t mcp-playwright:latest .

Automated Build Script

A convenience script is provided for the build process:

chmod +x docker-build.sh
./docker-build.sh

Sources: DOCKER.md:building-docker-image-section

Build with Custom Tag

docker build -t mcp-playwright:1.0.6 .

Building from Source Inside Docker

For environments where you prefer building inside the container:

FROM node:20-alpine AS builder

WORKDIR /app
COPY package*.json ./
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
RUN npm ci

COPY src ./src
COPY tsconfig.json ./
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package*.json ./
RUN npm ci --only=production
CMD ["node", "dist/index.js"]

Sources: DOCKER.md:building-from-source-section

Running the Server

MCP servers communicate via stdin/stdout, requiring interactive mode for proper operation:

docker run -i --rm mcp-playwright:latest
FlagPurpose
-iKeep STDIN open for interactive communication
--rmAutomatically remove container when it exits
mcp-playwright:latestImage name and tag

Sources: DOCKER.md:running-the-server-section

Using Docker Compose

# Start the server
docker compose run --rm playwright-mcp

# Or build and run
docker compose build
docker compose run --rm playwright-mcp

The provided docker-compose.yml:

services:
  playwright-mcp:
    build:
      context: .
      dockerfile: Dockerfile
    image: mcp-playwright:latest
    container_name: playwright-mcp-server
    stdin_open: true
    tty: true
    environment:
      - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1

Sources: docker-compose.yml

MCP Client Integration

Claude Desktop Configuration

Update the Claude Desktop configuration file:

OSConfiguration Location
macOS~/Library/Application Support/Claude/claude_desktop_config.json
Windows%APPDATA%\Claude\claude_desktop_config.json
Linux~/.config/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "playwright-docker": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "mcp-playwright:latest"]
    }
  }
}

Sources: DOCKER.md:claude-desktop-configuration-section

VS Code MCP Extension

{
  "mcpServers": {
    "playwright-docker": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "mcp-playwright:latest"]
    }
  }
}

Sources: DOCKER.md:vs-code-mcp-extension-section

Configuration Options

Environment Variables

VariableDefaultPurpose
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD1Skip browser downloads to reduce image size
NODE_ENVproductionRuntime environment

#### Using Environment Variables in Docker

docker run -i --rm \
  -e PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
  mcp-playwright:latest

#### Using Environment Variables in Docker Compose

services:
  playwright-mcp:
    environment:
      - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
      - NODE_ENV=production

Sources: DOCKER.md:environment-variables-section

Volume Mounts

For persistent data or file sharing with the container:

docker run -i --rm \
  -v $(pwd)/data:/app/data \
  mcp-playwright:latest
services:
  playwright-mcp:
    volumes:
      - ./data:/app/data
      - ./screenshots:/app/screenshots

Sources: DOCKER.md:volume-mounts-section

Resource Limits

docker run -i --rm \
  --cpus="2.0" \
  --memory="2g" \
  mcp-playwright:latest
services:
  playwright-mcp:
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G

Sources: DOCKER.md:resource-limits-section

Custom Network Configuration

# Create custom network
docker network create mcp-network

# Run container on custom network
docker run -i --rm --network mcp-network mcp-playwright:latest

Sources: DOCKER.md:advanced-usage-section

Troubleshooting

Container Exits Immediately

MCP servers wait for input on stdin. Ensure the -i flag is used:

docker run -i --rm mcp-playwright:latest

Sources: DOCKER.md:troubleshooting-section

Browser Not Found

The Docker image skips browser downloads by default to reduce size. Playwright downloads browsers on first use. To pre-install browsers:

FROM mcp-playwright:latest

# Install Playwright browsers
RUN npx playwright install chromium --with-deps

Sources: DOCKER.md:browser-not-found-section

Permission Issues

If encountering permission issues with mounted volumes:

docker run -i --rm \
  -v $(pwd)/data:/app/data \
  --user $(id -u):$(id -g) \
  mcp-playwright:latest

Sources: DOCKER.md:permission-issues-section

Health Checks

Add a health check to your docker-compose.yml:

services:
  playwright-mcp:
    healthcheck:
      test: ["CMD", "node", "-e", "process.exit(0)"]
      interval: 30s
      timeout: 10s
      retries: 3

Sources: DOCKER.md:health-checks-section

Security Considerations

PracticeImplementation
Non-root userAdd USER node to custom Dockerfile
Read-only root filesystemRun with --read-only flag
Vulnerability scanningdocker scan mcp-playwright:latest
FROM mcp-playwright:latest
USER node

Read-only Root Filesystem

docker run -i --rm --read-only mcp-playwright:latest

Vulnerability Scanning

docker scan mcp-playwright:latest

Sources: DOCKER.md:security-considerations-section

Image Optimization

OptimizationDescription
Base imageDebian-based slim Node.js (~200MB)
Artifact strategyCopies pre-built dist from host
DependenciesProduction-only via --omit=dev
Browser downloadsSkipped by default

Current image size: ~200MB (without browsers)

Sources: DOCKER.md:image-size-optimization-section

Workflow Summary

graph LR
    A[Local Build] -->|npm install --omit=dev| B[Dependencies]
    A -->|npm run build| C[dist/]
    B -->|COPY| D[Docker Build]
    C -->|COPY| D
    D -->|docker build| E[Image Created]
    E -->|Interactive Mode| F[MCP Server Running]
    F -->|JSON-RPC| G[MCP Client Connected]

Quick Reference

CommandDescription
docker build -t mcp-playwright:latest .Build image
docker run -i --rm mcp-playwright:latestRun in interactive mode
docker compose upRun via compose
docker scan mcp-playwright:latestSecurity scan

Sources: [DOCKER.md](https://github.com/executeautomation/mcp-playwright/blob/main/DOCKER.md)

Configuration Guide

Related topics: Getting Started, Transport Modes, Docker Deployment

Section Related Pages

Continue reading this section for the full explanation and source context.

Section Claude Desktop Configuration

Continue reading this section for the full explanation and source context.

Section VS Code MCP Extension

Continue reading this section for the full explanation and source context.

Section Starting the HTTP Server

Continue reading this section for the full explanation and source context.

Related topics: Getting Started, Transport Modes, Docker Deployment

Configuration Guide

This guide covers all configuration options for the mcp-playwright MCP server, including stdio mode, HTTP server mode, Docker deployment, and integration with AI assistants like Claude Desktop.

Overview

The mcp-playwright server provides browser automation capabilities through the Model Context Protocol (MCP). It supports multiple transport modes and can be configured to work with different MCP clients. Sources: package.json:1-50

graph TD
    A[MCP Client] --> B{Mode Selection}
    B --> C[Stdio Mode]
    B --> D[HTTP Mode]
    B --> E[Docker Mode]
    C --> F[stdin/stdout]
    D --> G[localhost:8931]
    E --> H[Docker Container]
    F --> I[Playwright Browser]
    G --> I
    H --> I

Stdio Mode Configuration

Stdio mode is the primary transport mechanism for MCP communication, using standard input/output streams. This mode is automatically selected when running via npx or direct node execution. Sources: README.md:1-30

Claude Desktop Configuration

For Claude Desktop integration, add the server configuration to your Claude Desktop config file:

PlatformConfig Location
macOS~/Library/Application Support/Claude/claude_desktop_config.json
Windows%APPDATA%\Claude\claude_desktop_config.json
Linux~/.config/Claude/claude_desktop_config.json

Configuration schema:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}

VS Code MCP Extension

For VS Code with MCP extension:

{
  "name": "playwright",
  "command": "npx",
  "args": ["-y", "@executeautomation/playwright-mcp-server"]
}
Note: In stdio mode, logging is automatically directed to files only (not console) to maintain clean JSON-RPC communication. Logs are written to ~/playwright-mcp-server.log. Sources: README.md:25-27

HTTP Mode Configuration

HTTP mode enables the MCP server to run as a standalone HTTP server, useful for remote deployments or IDE integrations that support HTTP transport. Sources: src/http-server.ts:1-50

Starting the HTTP Server

# Using npx
npx @executeautomation/playwright-mcp-server --port 8931

# Or after global installation
npm install -g @executeautomation/playwright-mcp-server
playwright-mcp-server --port 8931

HTTP Server Endpoints

EndpointMethodPurpose
/sseGETSSE Stream for Server-Sent Events
/messagesPOSTSend messages with session ID
/mcpGET/POSTUnified MCP endpoint
/healthGETHealth check endpoint

Security Configuration

The HTTP server binds to 127.0.0.1 (localhost only) by default to prevent external network access. Sources: src/http-server.ts:35-36

const host = '127.0.0.1';
const httpServer = app.listen(port, host, () => {
  logger.info(`Playwright MCP HTTP server listening on ${host}:${port}`);
});

Claude Desktop HTTP Configuration

{
  "mcpServers": {
    "playwright": {
      "url": "http://localhost:8931/mcp"
    }
  }
}

Health Check

curl http://localhost:8931/health

Response format:

{
  "status": "ok",
  "version": "1.0.10",
  "activeSessions": 0
}

Docker Configuration

The Docker image provides a containerized deployment option for the mcp-playwright server. Sources: DOCKER.md:1-50

Basic Docker Run

docker run -i --rm mcp-playwright:latest
FlagPurpose
-iKeep STDIN open for interactive communication
--rmAutomatically remove container on exit

Docker Compose Configuration

services:
  playwright-mcp:
    image: mcp-playwright:latest

Claude Desktop Docker Configuration

{
  "mcpServers": {
    "playwright-docker": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "mcp-playwright:latest"]
    }
  }
}

VS Code Docker Configuration

{
  "name": "playwright-docker",
  "command": "docker",
  "args": ["run", "-i", "--rm", "mcp-playwright:latest"]
}

Environment Variables

Configure server behavior using environment variables. Sources: DOCKER.md:20-35

Available Environment Variables

VariablePurposeDefault
PLAYWRIGHT_SKIP_BROWSER_DOWNLOADSkip browser downloads during image build1 (enabled)
NODE_ENVNode environment settingproduction

Docker Environment Variable Examples

Via docker run:

docker run -i --rm \
  -e PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
  -e NODE_ENV=production \
  mcp-playwright:latest

Via docker-compose.yml:

services:
  playwright-mcp:
    environment:
      - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
      - NODE_ENV=production

Volume Mounts

Share files and persist data between the host and container. Sources: DOCKER.md:36-50

Docker Volume Examples

Via docker run:

docker run -i --rm \
  -v $(pwd)/data:/app/data \
  -v $(pwd)/screenshots:/app/screenshots \
  mcp-playwright:latest

Via docker-compose.yml:

services:
  playwright-mcp:
    volumes:
      - ./data:/app/data
      - ./screenshots:/app/screenshots

User and Permissions

Handle permission issues with mounted volumes by specifying user:

docker run -i --rm \
  -v $(pwd)/data:/app/data \
  --user $(id -u):$(id -g) \
  mcp-playwright:latest

Resource Limits

Configure CPU and memory constraints for containerized deployments. Sources: DOCKER.md:85-100

Docker Resource Limits

services:
  playwright-mcp:
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G

Via docker run:

docker run -i --rm \
  --cpus="2.0" \
  --memory="2g" \
  mcp-playwright:latest

Network Configuration

Custom Network

docker network create mcp-network
docker run -i --rm --network mcp-network mcp-playwright:latest

Security Considerations

ConfigurationRecommendation
Run as non-root userOptional but recommended
Read-only root filesystemFor containers not needing write access
Vulnerability scanningUse docker scan mcp-playwright:latest

Health Checks

Add health check configuration to docker-compose.yml:

services:
  playwright-mcp:
    healthcheck:
      test: ["CMD", "node", "-e", "process.exit(0)"]
      interval: 30s
      timeout: 10s
      retries: 3

Troubleshooting Configuration Issues

Container Exits Immediately

MCP servers wait for input on stdin. Ensure the -i flag is used:

docker run -i --rm mcp-playwright:latest

Browser Not Found

The Docker image skips browser downloads by default. To pre-install browsers, create a custom Dockerfile:

FROM mcp-playwright:latest
RUN npx playwright install chromium --with-deps

Tool Name Length Constraints

When adding new tools, consider the combined server and tool name length. Some clients like Cursor have a 60-character limit for server_name:tool_name. Sources: README.md:10-15

Current server name: playwright-mcp

Ensure tool names are short enough to not exceed this limit when combined.

Image Specifications

AspectValue
Base imageDebian-based slim Node.js (~200MB)
Default size~200MB (without browsers)
DependenciesProduction only (no dev dependencies)

Building Custom Docker Images

Uses pre-built artifacts from local development:

FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY node_modules ./node_modules
COPY dist ./dist
CMD ["node", "dist/index.js"]

Full Build from Source

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
RUN npm ci

COPY src ./src
COPY tsconfig.json ./
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package*.json ./
RUN npm ci --only=production
CMD ["node", "dist/index.js"]

Dependencies Configuration

The package.json defines core dependencies for the MCP server. Sources: package.json:10-35

Runtime Dependencies

PackageVersionPurpose
@modelcontextprotocol/sdk1.24.3MCP protocol implementation
@playwright/browser-chromium1.57.0Chromium browser
@playwright/browser-firefox1.57.0Firefox browser
@playwright/browser-webkit1.57.0WebKit browser
express^4.21.1HTTP server framework
cors^2.8.5Cross-origin resource sharing
uuid11.1.0UUID generation

Development Dependencies

PackageVersionPurpose
typescript^5.8.3TypeScript compiler
jest^29.7.0Testing framework
@types/node^20.10.5Node.js type definitions
@types/express^4.17.21Express type definitions
jest-playwright-preset4.0.0Playwright Jest integration

Logging Configuration

In stdio mode, logs are automatically directed to files to maintain clean JSON-RPC communication. Sources: README.md:27

Log file location: ~/playwright-mcp-server.log

The logging middleware captures:

  • Request IDs for traceability
  • Tool execution timing and results
  • Error categorization (validation, system, resource, authentication, rate_limit)
  • Sanitized request bodies (sensitive fields redacted)

Summary

Transport ModeUse CaseConfig Key
StdioClaude Desktop, local MCP clientscommand: "npx"
HTTPRemote deployments, VS Codeurl: "http://localhost:8931/mcp"
DockerContainerized environmentscommand: "docker"

Source: https://github.com/executeautomation/mcp-playwright / Human Manual

Doramagic Pitfall Log

Source-linked risks stay visible on the manual page so the preview does not read like a recommendation.

high Playwright is asking for an specific browser version.

First-time setup may fail or require extra isolation and rollback planning.

high How to configure proxy and storageState when launching browser in Playwright MCP?

The project may affect permissions, credentials, data exposure, or host boundaries.

medium Configuration risk needs validation

Users may get misleading failures or incomplete behavior unless configuration is checked carefully.

medium Add Clarvia AEO score badge to README (AEO 32/100)

Users may get misleading failures or incomplete behavior unless configuration is checked carefully.

Doramagic Pitfall Log

Doramagic extracted 16 source-linked risk signals. Review them before installing or handing real data to the project.

1. Installation risk: Playwright is asking for an specific browser version.

  • Severity: high
  • Finding: Installation risk is backed by a source signal: Playwright is asking for an specific browser version.. Treat it as a review item until the current version is checked.
  • User impact: First-time setup may fail or require extra isolation and rollback planning.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: Source-linked evidence: https://github.com/executeautomation/mcp-playwright/issues/117

2. Security or permission risk: How to configure proxy and storageState when launching browser in Playwright MCP?

  • Severity: high
  • Finding: Security or permission risk is backed by a source signal: How to configure proxy and storageState when launching browser in Playwright MCP?. Treat it as a review item until the current version is checked.
  • User impact: The project may affect permissions, credentials, data exposure, or host boundaries.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: Source-linked evidence: https://github.com/executeautomation/mcp-playwright/issues/203

3. Configuration risk: Configuration risk needs validation

  • Severity: medium
  • Finding: Configuration risk is backed by a source signal: Configuration risk needs validation. Treat it as a review item until the current version is checked.
  • User impact: Users may get misleading failures or incomplete behavior unless configuration is checked carefully.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: capability.host_targets | github_repo:898077246 | https://github.com/executeautomation/mcp-playwright | host_targets=mcp_host, claude, cursor

4. Configuration risk: Add Clarvia AEO score badge to README (AEO 32/100)

  • Severity: medium
  • Finding: Configuration risk is backed by a source signal: Add Clarvia AEO score badge to README (AEO 32/100). Treat it as a review item until the current version is checked.
  • User impact: Users may get misleading failures or incomplete behavior unless configuration is checked carefully.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: Source-linked evidence: https://github.com/executeautomation/mcp-playwright/issues/212

5. Configuration risk: Add policy enforcement for browser automation and HTTP request tools

  • Severity: medium
  • Finding: Configuration risk is backed by a source signal: Add policy enforcement for browser automation and HTTP request tools. Treat it as a review item until the current version is checked.
  • User impact: Users may get misleading failures or incomplete behavior unless configuration is checked carefully.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: Source-linked evidence: https://github.com/executeautomation/mcp-playwright/issues/216

6. Capability assumption: README/documentation is current enough for a first validation pass.

  • Severity: medium
  • Finding: README/documentation is current enough for a first validation pass.
  • User impact: The project should not be treated as fully validated until this signal is reviewed.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: capability.assumptions | github_repo:898077246 | https://github.com/executeautomation/mcp-playwright | README/documentation is current enough for a first validation pass.

7. Project risk: How to pass in the `--ignore-https-errors` parameter?

  • Severity: medium
  • Finding: Project risk is backed by a source signal: How to pass in the --ignore-https-errors parameter?. Treat it as a review item until the current version is checked.
  • User impact: The project should not be treated as fully validated until this signal is reviewed.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: Source-linked evidence: https://github.com/executeautomation/mcp-playwright/issues/202

8. Maintenance risk: Maintainer activity is unknown

  • Severity: medium
  • Finding: Maintenance risk is backed by a source signal: Maintainer activity is unknown. Treat it as a review item until the current version is checked.
  • User impact: Users cannot judge support quality until recent activity, releases, and issue response are checked.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: evidence.maintainer_signals | github_repo:898077246 | https://github.com/executeautomation/mcp-playwright | last_activity_observed missing

9. Security or permission risk: no_demo

  • Severity: medium
  • Finding: no_demo
  • User impact: The project may affect permissions, credentials, data exposure, or host boundaries.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: downstream_validation.risk_items | github_repo:898077246 | https://github.com/executeautomation/mcp-playwright | no_demo; severity=medium

10. Security or permission risk: No sandbox install has been executed yet; downstream must verify before user use.

  • Severity: medium
  • Finding: No sandbox install has been executed yet; downstream must verify before user use.
  • User impact: The project may affect permissions, credentials, data exposure, or host boundaries.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: risks.safety_notes | github_repo:898077246 | https://github.com/executeautomation/mcp-playwright | No sandbox install has been executed yet; downstream must verify before user use.

11. Security or permission risk: no_demo

  • Severity: medium
  • Finding: no_demo
  • User impact: The project may affect permissions, credentials, data exposure, or host boundaries.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: risks.scoring_risks | github_repo:898077246 | https://github.com/executeautomation/mcp-playwright | no_demo; severity=medium

12. Security or permission risk: Feature Request: Add browser context persistence for login state (userDataDir/storageState)

  • Severity: medium
  • Finding: Security or permission risk is backed by a source signal: Feature Request: Add browser context persistence for login state (userDataDir/storageState). Treat it as a review item until the current version is checked.
  • User impact: The project may affect permissions, credentials, data exposure, or host boundaries.
  • Recommended check: Open the linked source, confirm whether it still applies to the current version, and keep the first run isolated.
  • Evidence: Source-linked evidence: https://github.com/executeautomation/mcp-playwright/issues/201

Source: Doramagic discovery, validation, and Project Pack records

Community Discussion Evidence

These external discussion links are review inputs, not standalone proof that the project is production-ready.

Sources 9

Count of project-level external discussion links exposed on this manual page.

Use Review before install

Open the linked issues or discussions before treating the pack as ready for your environment.

Community Discussion Evidence

Doramagic exposes project-level community discussion separately from official documentation. Review these links before using mcp-playwright with real data or production workflows.

Source: Project Pack community evidence and pitfall evidence