Playwright MCP HTTP Server
Provides browser automation capabilities via HTTP endpoints by wrapping the official Playwright MCP package, enabling serverless deployments and cloud environments where STDIO-based communication is not possible.
README
Playwright MCP HTTP Server
A standalone HTTP service that wraps the official @playwright/mcp package to provide browser automation capabilities via HTTP endpoints. This service enables the use of Playwright MCP in serverless environments where STDIO-based communication is not possible.
Features
- š HTTP-based MCP Protocol - Access Playwright MCP via standard HTTP requests
- š Serverless Compatible - Works in serverless/cloud environments (Railway, Render, Fly.io, GCP Cloud Run, etc.)
- š MCP v0.1 Compatible - Fully implements the Model Context Protocol specification
- š Full Playwright Support - All Playwright browser automation tools available
- š³ Docker Ready - Includes Dockerfile for easy containerization
- ā” Production Ready - Health checks, graceful shutdown, error handling
- āļø Live Deployment - Pre-deployed to Google Cloud Run (see below)
Quick Start
Prerequisites
- Node.js 18+ (LTS recommended)
- npm or yarn
Installation
# Clone the repository
git clone https://github.com/mcpmessenger/playwright-mcp.git
cd playwright-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Start the server
npm start
The server will start on port 8931 by default. You can access:
- Service Info: http://localhost:8931/
- Health Check: http://localhost:8931/health
- MCP Endpoint: http://localhost:8931/mcp (POST only)
š Live Production Instance
The service is deployed to Google Cloud Run and ready to use:
- Service URL: https://playwright-mcp-http-server-554655392699.us-central1.run.app
- Health Check: https://playwright-mcp-http-server-554655392699.us-central1.run.app/health
- MCP Endpoint: https://playwright-mcp-http-server-554655392699.us-central1.run.app/mcp (POST only)
You can use the live instance immediately without deploying your own. See Usage Examples below.
Development
# Run in development mode with auto-reload
npm run dev
Configuration
Configuration is done via environment variables. Create a .env file or set environment variables:
| Variable | Default | Description |
|---|---|---|
PORT |
8931 |
HTTP server port |
PLAYWRIGHT_BROWSER |
chromium |
Browser type (chromium, firefox, webkit) |
PLAYWRIGHT_HEADLESS |
true |
Run browser in headless mode |
LOG_LEVEL |
info |
Logging level (error, warn, info, debug) |
MAX_SESSIONS |
(unlimited) | Maximum concurrent browser sessions |
SESSION_TIMEOUT |
(none) | Session timeout in seconds |
CORS_ORIGIN |
* |
CORS allowed origins |
See .env.example for a template.
API Documentation
POST /mcp
Main MCP protocol endpoint. Accepts JSON-RPC 2.0 messages.
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "browser_navigate",
"arguments": {
"url": "https://example.com"
}
}
}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [
{
"type": "text",
"text": "Navigation completed"
}
],
"isError": false
}
}
GET /health
Health check endpoint. Returns service status.
Response:
{
"status": "healthy",
"version": "1.0.0",
"uptime": 3600,
"timestamp": "2024-12-01T12:00:00.000Z"
}
GET /
Service information endpoint.
Response:
{
"name": "Playwright MCP HTTP Server",
"version": "1.0.0",
"protocol": "MCP v0.1",
"endpoints": {
"mcp": "/mcp",
"health": "/health"
}
}
Supported MCP Methods
The server supports all standard MCP methods:
initialize- Initialize MCP connectioninitialized- Confirm initializationtools/list- List available Playwright toolstools/call- Invoke a Playwright tool
Available Playwright Tools
All tools from @playwright/mcp are supported:
browser_navigate- Navigate to a URLbrowser_snapshot- Get accessibility snapshotbrowser_take_screenshot- Capture screenshotbrowser_click- Click an elementbrowser_type- Type textbrowser_fill_form- Fill form fieldsbrowser_evaluate- Execute JavaScriptbrowser_wait_for- Wait for conditionsbrowser_close- Close browser/page
For detailed tool parameters, see the Playwright MCP documentation.
Using the Server
- Start locally with
npm install, build (npm run build), then runnpm start(or usenpm run devfor auto-reload during development). - Call
/,/health, or/mcpvia curl/Postman/Playwright MCP clients; the/mcpendpoint accepts JSON-RPC POST requests (see the example below). - Adjust behavior by editing
.envor setting env vars such asPORT,PLAYWRIGHT_BROWSER, andPLAYWRIGHT_HEADLESS. - Alternatively, containerize the service with
docker build -t playwright-mcp-http-server .anddocker run -p 8931:8931 ...for consistent deployments.
Updating the GitHub Repository
- Pull the latest changes before making edits:
git pull --rebase origin main. - Use
git statusto see touched files, then stage withgit add <files>and commit with a descriptive message. - Push your branch with
git push origin HEADand open a pull request if the change needs review.
Example Usage
Using curl
# List available tools
curl -X POST http://localhost:8931/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}'
# Navigate to a page
curl -X POST http://localhost:8931/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "browser_navigate",
"arguments": {
"url": "https://example.com"
}
}
}'
# Take a screenshot
curl -X POST http://localhost:8931/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "browser_take_screenshot",
"arguments": {
"fullPage": true
}
}
}'
Using JavaScript/TypeScript
// Use the live production instance or replace with your own deployment URL
const MCP_SERVER_URL = 'https://playwright-mcp-http-server-554655392699.us-central1.run.app/mcp';
async function callPlaywrightMCP(method: string, params?: any) {
const response = await fetch(MCP_SERVER_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: Date.now(),
method,
params,
}),
});
return response.json();
}
// List tools
const tools = await callPlaywrightMCP('tools/list');
// Navigate
await callPlaywrightMCP('tools/call', {
name: 'browser_navigate',
arguments: { url: 'https://example.com' },
});
// Take screenshot
const screenshot = await callPlaywrightMCP('tools/call', {
name: 'browser_take_screenshot',
arguments: { fullPage: true },
});
Note: The /mcp endpoint requires POST requests with JSON-RPC 2.0 formatted messages. GET requests will return a 404 error.
Deployment
Railway
- Create a new Railway project
- Connect your Git repository
- Railway will auto-detect Node.js and use
npm start - Set environment variables if needed
- Deploy!
The service will use Railway's $PORT environment variable automatically.
Render
- Create a new Web Service on Render
- Connect your Git repository
- Build command:
npm install && npm run build - Start command:
npm start - Set environment variables if needed
- Deploy!
Google Cloud Platform (Cloud Run)
See DEPLOY_GCP.md for detailed instructions.
Quick deploy:
# Set your project ID
export GCP_PROJECT_ID="your-project-id"
# Deploy (Linux/Mac)
chmod +x deploy-gcp.sh && ./deploy-gcp.sh
# Deploy (Windows PowerShell)
.\deploy-gcp.ps1 -ProjectId "your-project-id"
Or manually:
PROJECT_ID="your-project-id"
IMAGE="gcr.io/${PROJECT_ID}/playwright-mcp-http-server"
docker build -t $IMAGE .
docker push $IMAGE
gcloud run deploy playwright-mcp-http-server \
--image $IMAGE \
--region us-central1 \
--platform managed \
--allow-unauthenticated \
--port 8931 \
--memory 2Gi \
--cpu 2
Fly.io
- Install Fly CLI:
curl -L https://fly.io/install.sh | sh - Login:
fly auth login - Launch app:
fly launch - Deploy:
fly deploy
Docker
# Build the image
docker build -t playwright-mcp-http-server .
# Run the container
docker run -p 8931:8931 playwright-mcp-http-server
# With environment variables
docker run -p 8931:8931 \
-e PORT=8931 \
-e PLAYWRIGHT_HEADLESS=true \
playwright-mcp-http-server
Docker Compose
version: '3.8'
services:
playwright-mcp:
build: .
ports:
- "8931:8931"
environment:
- PORT=8931
- PLAYWRIGHT_HEADLESS=true
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:8931/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
Architecture
The service works by:
- HTTP Server (Express) receives JSON-RPC requests
- MCP Handler processes the requests and routes them to Playwright
- Playwright Process Manager spawns
@playwright/mcpas a child process - STDIO Communication handles JSON-RPC messages via stdin/stdout
- Response is formatted and returned via HTTP
This architecture allows the Playwright process to run independently while being accessible via HTTP.
Troubleshooting
Service won't start
- Check that Node.js 18+ is installed:
node --version - Verify dependencies are installed:
npm install - Check logs for error messages
Playwright browser not found
- The browser will be downloaded automatically on first run
- For Docker, ensure system dependencies are installed (included in Dockerfile)
- Check network connectivity for browser downloads
High memory usage
- Consider setting
MAX_SESSIONSto limit concurrent sessions - Ensure
browser_closeis called when done with a session - Monitor for memory leaks in long-running processes
Timeout errors
- Increase request timeout if operations take longer than 30 seconds
- Check network connectivity to target URLs
- Verify Playwright process is not crashed
Development
Project Structure
playwright-mcp-http-server/
āāā src/
ā āāā server.ts # HTTP server setup
ā āāā mcp-handler.ts # MCP protocol handler
ā āāā playwright-process.ts # Playwright process management
ā āāā config.ts # Configuration
ā āāā types/
ā āāā mcp.ts # TypeScript types
āāā dist/ # Compiled JavaScript (generated)
āāā package.json
āāā tsconfig.json
āāā Dockerfile
āāā README.md
Building
npm run build
Running Tests
Note: Tests are not yet implemented but planned for future releases
License
MIT
References
Support
For issues and questions, please open an issue on the repository.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.