Playwright MCP Server


What is this?

The Playwright MCP Server is a specialized server that lets AI agents control browsers for automated web navigation, scraping, and UI testing through a standardized JSON-based interface. By wrapping Microsoft Playwright’s cross-browser automation (Chromium, Firefox, WebKit) in the Model Context Protocol, it enables agents to perform clicks, typing, navigation, and data extraction without bespoke scripts.

It works by exposing browser actions as MCP tools and resources over HTTP or WebSocket. Agents send simple JSON-RPC calls like “navigate,” “click,” or “evaluate,” and the server handles session management, sandboxing, and resource cleanup behind the scenes. With built-in support for headless or headed modes, media capture, and event streaming, it’s a universal layer for AI-driven browser orchestration.

Quick Start

Install the server using npm:

npm install @modelcontextprotocol/server-playwright

Then add it to your MCP client configuration:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-playwright"],
      "env": {
        "API_KEY": "your-api-key-here"
      }
    }
  }
}

Key Features

Feature 1: Unified JSON interface – Agents send standard MCP JSON-RPC calls to drive browsers without importing the Playwright SDK directly.

Feature 2: Multi-browser and mode support – Switch between Chromium, Firefox, and WebKit in headless or headed mode with a single configuration.

Feature 3: Session management & automation tools – Create isolated contexts, manage cookies, perform clicks, typing, JS evaluation, screenshots, and video recording.

Example Usage

Here’s how you might extract the page title in a single call:

// Example code
const result = await client.callTool({
  name: "evaluate",
  arguments: {
    pageFunction: "() => document.title"
  }
});

This code sends an “evaluate” request to the Playwright MCP Server and returns the current page title as a string.

Configuration

The server accepts the following environment variables:

API_KEY – Your MCP server API key for authenticating requests.

SETTING_1 (optional) – HEADLESS_MODE: set to “false” to run in headed mode, or “true” (default) for headless execution.

Available Tools/Resources

createSession: Instantiate a new browser session and receive a sessionId.

navigate: Load a given URL within the specified session.

Who Should Use This?

This server is perfect for:

Use case 1: LLM developers who need to integrate automated browser actions into their workflows.

Use case 2: QA engineers looking to drive UI tests with LLM-based automation.

Use case 3: Data engineers building retrieval-augmented generation pipelines with dynamic web content.

Conclusion

Ready to see how AI-driven browser automation can simplify your scraping, testing, and RAG workflows? Install the Playwright MCP Server, connect your agent, and get started in minutes.

Check out the GitHub repository for more information and to contribute.