Playwright Docker
HTTP-SSEDocker Compose environment for Playwright MCP server with headless and headed browser automation modes
Docker Compose environment for Playwright MCP server with headless and headed browser automation modes
日本語版はこちら (Japanese version here)
This project provides a Docker Compose environment to run the @playwright/mcp server. It allows you to easily set up and manage the Playwright MCP server for use with clients like Cline or Cursor.
git clone <repository-url> cd playwright-mcp-docker
.env file:
Copy the sample environment file:
cp .env.sample .env
.env:
Edit the .env file to adjust settings according to your environment and preferences:
MCP_HOST_PORT: The port on the host machine that the MCP server will be accessible through (default: 8931).HEADLESS: Set to true for headless mode (no browser GUI) or false for headed mode (requires GUI setup). Default is true.DISPLAY, WAYLAND_DISPLAY, XDG_RUNTIME_DIR: Environment variables needed for GUI applications in Linux environments (especially WSLg). Defaults are provided.X11_HOST_PATH, WSLG_HOST_PATH: Host paths for X11 and WSLg sockets/directories. Defaults are provided. Adjust if your system configuration differs. For Windows Docker accessing WSL paths, use the \\wsl.localhost\DistroName\... format (see .env.sample).Build and start the container:
docker-compose up --build -d
The --build flag is only needed the first time or when Dockerfile changes. The -d flag runs the container in detached mode (in the background).
Configure MCP Client (e.g., VSCode/Cline):
playwright_sse (or any name you prefer).http://localhost:<MCP_HOST_PORT>/sse (replace <MCP_HOST_PORT> with the value from your .env file, e.g., http://localhost:8931/sse).{ "mcpServers": { "playwright_sse": { // Server name is arbitrary "url": "http://localhost:8931/sse" // Match the port number in .env } } }
.env file: Manages environment-specific settings like ports, headless mode, and paths for headed mode.docker-compose.yml: Defines the Docker service, reads variables from .env, sets up port mapping and volumes.Dockerfile: Defines the Docker image, installs @playwright/mcp and its dependencies (including Chrome).entrypoint.sh: Script that runs when the container starts, passing the correct arguments (--headless or --port) to the npx @playwright/mcp command based on the HEADLESS environment variable.HEADLESS=true in .env. Restart the container: docker-compose up -d.HEADLESS=false in .env. Ensure your host environment (e.g., WSLg or X Server) is correctly set up. Restart the container: docker-compose up -d.docker-compose.yml and the WSL2-specific paths in .env.sample should generally work. Ensure the paths in your .env match your WSL distribution name if it's not Ubuntu.DISPLAY variable and potentially the volume mounts (X11_HOST_PATH) in your .env file according to your X Server setup.docker-compose down