home / mcp / playwright mcp server
A Model Context Protocol server that provides browser automation capabilities using Playwright for structured page interaction.
Configuration
View docs{
"mcpServers": {
"microsoft-playwright-mcp": {
"url": "http://localhost:8931/mcp"
}
}
}You can automate browsing tasks by running a dedicated MCP server that exposes Playwright-based browser automation through structured page data. This enables language models to interact with web pages using accessible snapshots and page state rather than images, making automation deterministic and easier to reason about over time.
You use an MCP client to connect to the Playwright MCP server. Start the server on a port or run it as a remote HTTP service, then point your client’s mcpServers configuration to the server. The server exposes a rich set of automation tools that let you click, type, navigate, capture snapshots, inspect network activity, and perform scripted actions on web pages. Use the HTTP URL when running the server as a remote service, or use a local stdio setup to spawn the MCP process directly from your tooling.
Two common ways to connect are: either run the server as an HTTP endpoint and supply the URL to your client, or run a local process (stdio) that the client spawns and communicates with via standard input/output.
Prerequisites: you need Node.js 18 or newer installed on your machine.
Install and run the Playwright MCP server in stdio mode from a shell, then connect a client to it. The standard approach is to use the executable via a package manager to start the MCP server with the desired port.
Standalone server with HTTP transport is started by running the MCP server on a port, for example: npx @playwright/mcp@latest --port 8931. In this mode, clients connect via an HTTP URL such as http://localhost:8931/mcp.
You can also run the server in a Docker container. The minimal container-based configuration uses a stdio entry with Docker, for example: the server can be launched with a Docker run command and reached at port 8931.
Configuration for clients is typically provided as an mcpServers object, including either an http URL or a stdio command with arguments. Ensure each entry includes the required fields (url for http, command and args for stdio).
The server supports a wide range of options to customize behavior, timeouts, security, and profiling. You can specify browser type and launch options, context settings, storage state, initialization scripts, and various timeouts. The options are expressed in a JSON schema that aligns with the configuration object used to start the server. You can also enable optional features such as saving session data, traces, and videos, and you can control which origins and hosts the server can access.
Typical configuration sections include: browser settings (type, isolated mode, user data dir, launch options, context options), server transport (port, host, allowed hosts), capabilities (core features, pdf, vision, devtools), output and logging options, console level, network origins, test id attribute, timeouts, image handling, and tracing controls. You may also provide initial state via storage files or a preloaded storage state.
Run the MCP server in an environment with a display by starting it on a port to enable HTTP transport.
Example start command and client configuration:
npx @playwright/mcp@latest --port 8931
```
```js
{
"mcpServers": {
"playwright": {
"url": "http://localhost:8931/mcp"
}
}
}The Docker-based setup supports headless Chromium and exposes port 8931 for MCP clients.
Option 1: run the official image as a one-off container using the standard MCP entry points.
{
"mcpServers": {
"playwright": {
"command": "docker",
"args": ["run", "-i", "--rm", "--init", "--pull=always", "mcr.microsoft.com/playwright/mcp"]
}
}
}Option 2: run the container as a long-lived service and expose the port for external clients.
docker run -d -i --rm --init --pull=always \
--entrypoint node \
--name playwright \
-p 8931:8931 \
mcr.microsoft.com/playwright/mcp \
cli.js --headless --browser chromium --no-sandbox --port 8931 --host 0.0.0.0You can create a headless Playwright MCP server instance programmatically and connect a transport for communication.
import http from 'http';
import { createConnection } from '@playwright/mcp';
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
http.createServer(async (req, res) => {
// Creates a headless Playwright MCP server with SSE transport
const connection = await createConnection({ browser: { launchOptions: { headless: true } } });
const transport = new SSEServerTransport('/messages', res);
await connection.connect(transport);
});Perform click on a web page
Close the page
Returns all console messages
Perform drag and drop between two elements
Evaluate JavaScript expression on page or element
Upload one or multiple files
Fill multiple form fields
Handle a dialog
Hover over element on page
Navigate to a URL
Go back to the previous page in the history
List network requests
Press a key on the keyboard
Resize the browser window
Run Playwright code snippet
Select option in a dropdown
Page snapshot for accessibility auditing
Take a screenshot of the current page
Type text into an editable element
Wait for text to appear or disappear or a time to pass
Manage tabs: list, create, close, or select
Install the browser specified in the config
Click at a given position with the left mouse button
Press mouse button down
Drag mouse to a position
Move mouse to a position
Press mouse up
Scroll mouse wheel
Save page as PDF
Create locator for element in tests
Verify element is visible on the page
Verify list is visible on the page
Verify text is visible on the page
Verify element value