HaolongChen/playwright-mcp-server
If you are the rightful owner of playwright-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The Playwright MCP Server is a Docker-based server that provides browser automation capabilities using the Model Context Protocol (MCP). It supports multiple browsers and can be deployed on various cloud platforms.
Playwright MCP Server
A Docker-based Model Context Protocol (MCP) server that provides Playwright browser automation capabilities. This server runs in a containerized environment with support for multiple browsers (Chromium, Firefox, WebKit) and can be deployed on various cloud platforms.
Features
- 🎭 Multi-browser Support: Chromium, Firefox, and WebKit
- 🐳 Docker-based: Fully containerized with proper browser dependencies
- 🚀 Cloud-ready: Deploy to Fly.io, Railway, DigitalOcean, Render, and more
- 📊 Health Monitoring: Built-in health checks and logging
- 🔧 MCP Protocol: Standard Model Context Protocol implementation
- 🛡️ Security: Non-root container execution with security hardening
Quick Start
Local Development
- Clone the repository
git clone https://github.com/HaolongChen/playwright-mcp-server.git
cd playwright-mcp-server
- Install dependencies
npm install
- Run locally (requires Playwright browsers)
npm start
Docker Deployment
- Using Docker Compose (Recommended)
docker-compose up -d
- Using Docker directly
# Build the image
docker build -t playwright-mcp-server .
# Run the container
docker run -d -p 3000:3000 --name playwright-mcp playwright-mcp-server
- With nginx proxy
docker-compose --profile proxy up -d
API Endpoints
Health Check
GET /health
Available Tools
GET /tools
MCP Protocol
POST /mcp
Content-Type: application/json
{
"method": "navigate",
"params": {
"url": "https://example.com",
"browser": "chromium"
}
}
Available MCP Tools
| Tool | Description | Parameters |
|---|---|---|
navigate | Navigate to a URL | url, browser?, waitUntil? |
screenshot | Take a screenshot | url, browser?, fullPage?, selector? |
extractText | Extract text content | url, selector?, browser? |
clickElement | Click an element | url, selector, browser?, waitForSelector? |
fillForm | Fill a form field | url, selector, value, browser? |
waitForElement | Wait for element to appear | url, selector, timeout?, browser? |
Example Tool Usage
// Navigate to a page
{
"method": "navigate",
"params": {
"url": "https://example.com",
"browser": "chromium",
"waitUntil": "networkidle"
}
}
// Take a screenshot
{
"method": "screenshot",
"params": {
"url": "https://example.com",
"browser": "firefox",
"fullPage": true
}
}
// Extract text from a specific element
{
"method": "extractText",
"params": {
"url": "https://example.com",
"selector": ".main-content",
"browser": "webkit"
}
}
Cloud Deployment
Fly.io
- Install Fly CLI
curl -L https://fly.io/install.sh | sh
- Create fly.toml
app = "your-playwright-mcp-server"
primary_region = "ord"
[build]
dockerfile = "Dockerfile"
[env]
PORT = "8080"
NODE_ENV = "production"
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 10
soft_limit = 5
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "10s"
interval = "15s"
restart_limit = 0
timeout = "2s"
[vm]
memory = "2gb"
cpu_kind = "shared"
cpus = 1
- Deploy
fly launch
fly deploy
Railway
-
Connect Railway to your repository
- Go to Railway.app
- Import your GitHub repository
-
Set environment variables
PORT=3000
NODE_ENV=production
- Deploy automatically - Railway will use your Dockerfile
Render
Render provides a seamless deployment experience with automatic SSL, custom domains, and managed infrastructure. This guide covers deploying the Playwright MCP Server to Render using their Docker support.
Prerequisites
- A Render account (free tier available)
- Your GitHub repository connected to Render
- This project's Dockerfile in your repository
Step-by-Step Deployment
1. Create a New Web Service
- Log in to your Render Dashboard
- Click "New +" button in the top right
- Select "Web Service"
2. Connect Your Repository
- Choose "Build and deploy from a Git repository"
- Click "Connect" next to your GitHub account (authorize if needed)
- Select the
playwright-mcp-serverrepository - Click "Connect"
3. Configure Your Web Service
Fill in the following settings:
| Setting | Value | Description |
|---|---|---|
| Name | playwright-mcp-server | Your service name (will be part of URL) |
| Region | Choose closest to your users | e.g., Oregon (US West), Frankfurt (EU) |
| Branch | main | Git branch to deploy from |
| Runtime | Docker | Render will detect your Dockerfile |
| Instance Type | Standard or higher | Minimum recommended for Playwright |
4. Environment Variables
Under the "Environment" section, add the following variables:
| Key | Value | Required | Description |
|---|---|---|---|
PORT | 3000 | Yes | Application port (Render maps to public port automatically) |
NODE_ENV | production | Yes | Node environment setting |
Click "Add Environment Variable" for each entry.
5. Advanced Settings (Recommended)
Expand "Advanced" section and configure:
Docker Command Override (optional):
npm start
Health Check Path:
/health
Auto-Deploy: ✅ Enabled (automatically deploy on git push)
6. Resource Configuration
Since Playwright requires significant resources, choose appropriate instance type:
| Instance Type | RAM | CPU | Use Case |
|---|---|---|---|
| Standard | 2 GB | 1.0 | Light usage, single browser |
| Standard Plus | 4 GB | 2.0 | Multiple browsers, moderate load |
| Pro | 8 GB | 4.0 | High traffic, concurrent operations |
💡 Recommendation: Start with Standard ($7/month) and scale up if needed.
7. Deploy Your Service
- Review all settings
- Click "Create Web Service"
- Render will:
- Clone your repository
- Build the Docker image
- Deploy the container
- Assign a public URL
Your service will be available at: https://playwright-mcp-server-XXXX.onrender.com
Post-Deployment Configuration
Custom Domain (Optional)
- Go to your service's "Settings" tab
- Scroll to "Custom Domain" section
- Click "Add Custom Domain"
- Enter your domain (e.g.,
playwright.yourdomain.com) - Update your DNS records as instructed by Render
Environment Groups (Optional)
For managing multiple services with shared environment variables:
- Go to "Environment" tab in your dashboard
- Create an Environment Group
- Add common variables (e.g., API keys)
- Link the group to your services
Monitoring and Logs
- Logs: Click "Logs" tab to view real-time application logs
- Metrics: Click "Metrics" tab to monitor:
- CPU usage
- Memory consumption
- HTTP requests
- Response times
- Events: View deployment history and events
Testing Your Deployment
Once deployed, test your service:
1. Health Check
curl https://your-service-name.onrender.com/health
Expected response:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"browsers": {
"chromium": true,
"firefox": true,
"webkit": true
}
}
2. List Available Tools
curl https://your-service-name.onrender.com/tools
3. Test Navigation Tool
curl -X POST https://your-service-name.onrender.com/mcp \
-H "Content-Type: application/json" \
-d '{
"method": "navigate",
"params": {
"url": "https://example.com",
"browser": "chromium"
}
}'
Render-Specific Features
Automatic HTTPS
- All Render services get free SSL certificates
- HTTPS is enabled by default
- Certificates auto-renew
Zero-Downtime Deploys
- Render performs rolling deploys
- New version starts before old one stops
- No service interruption
Persistent Disks (if needed)
- Render services are ephemeral by default
- Add a persistent disk for permanent storage
- Not required for this Playwright server
Pull Request Previews
- Enable preview environments for PRs
- Test changes before merging
- Automatically created for each PR
Troubleshooting Render Deployment
Build Failures
If your build fails:
- Check the build logs in the "Logs" tab
- Ensure your Dockerfile is in the repository root
- Verify all npm dependencies are listed in
package.json
Memory Issues
If you see OOM (Out of Memory) errors:
- Upgrade to a higher instance type
- Consider using only Chromium browser (comment out others)
- Monitor memory usage in the "Metrics" tab
Service Won't Start
If the service builds but won't start:
- Verify the
PORTenvironment variable is set to3000 - Check that the application listens on
0.0.0.0, notlocalhost - Review startup logs for error messages
Health Check Failures
If health checks fail:
- Verify
/healthendpoint is responding - Check the health check path in settings
- Ensure browsers initialize successfully (check logs)
Slow Cold Starts
Render may suspend free/starter services after inactivity:
- Upgrade to paid plan to keep service always-on
- First request after suspension may take 30-60 seconds
- Subsequent requests will be fast
Cost Optimization
Free Tier Limitations
- Free services spin down after 15 minutes of inactivity
- 750 hours/month of usage
- Shared resources
- ⚠️ Not recommended for production Playwright workloads
Recommended Setup
- Development: Standard instance ($7/month)
- Production: Standard Plus ($20/month) or higher
- Enable auto-scaling if needed
Cost-Saving Tips
- Use single browser (Chromium) to reduce memory
- Implement request queueing to handle concurrent load
- Set up proper caching strategies
- Monitor usage to right-size your instance
Updating Your Deployment
Automatic Updates
- Push to your connected branch
- Render automatically builds and deploys
- Watch deployment progress in dashboard
Manual Deploy
- Go to your service dashboard
- Click "Manual Deploy" button
- Select "Clear build cache & deploy" if needed
Rollback
- Click on "Events" tab
- Find previous successful deployment
- Click "Rollback to this version"
Additional Resources
- Render Documentation
- Render Docker Deployment Guide
- Render Environment Variables
- Render Health Checks
DigitalOcean App Platform
- Create app.yaml
name: playwright-mcp-server
services:
- name: web
source_dir: /
github:
repo: HaolongChen/playwright-mcp-server
branch: main
run_command: npm start
environment_slug: node-js
instance_count: 1
instance_size_slug: basic-xxs
http_port: 3000
env:
- key: NODE_ENV
value: production
- Deploy
doctl apps create app.yaml
Google Cloud Run
- Build and push to Container Registry
gcloud builds submit --tag gcr.io/PROJECT-ID/playwright-mcp-server
- Deploy to Cloud Run
gcloud run deploy --image gcr.io/PROJECT-ID/playwright-mcp-server --memory 2Gi --cpu 1
AWS ECS/Fargate
- Push to ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ACCOUNT.dkr.ecr.us-east-1.amazonaws.com
docker build -t playwright-mcp-server .
docker tag playwright-mcp-server:latest ACCOUNT.dkr.ecr.us-east-1.amazonaws.com/playwright-mcp-server:latest
docker push ACCOUNT.dkr.ecr.us-east-1.amazonaws.com/playwright-mcp-server:latest
- Create ECS Service with task definition using your ECR image
Local Docker Development
Prerequisites
- Docker Engine 20.10+
- Docker Compose 2.0+
- 2GB+ available RAM
Development Setup
- Clone and build
git clone https://github.com/HaolongChen/playwright-mcp-server.git
cd playwright-mcp-server
docker-compose build
- Start services
docker-compose up -d
- View logs
docker-compose logs -f playwright-mcp
- Stop services
docker-compose down
Development with Hot Reload
# For development with nodemon
docker-compose -f docker-compose.dev.yml up
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
PORT | Server port | 3000 |
NODE_ENV | Environment | development |
Browser Configuration
The server initializes all three browsers on startup:
- Chromium: Fast, modern web standards
- Firefox: Good for cross-browser testing
- WebKit: Safari engine, iOS compatibility
Monitoring & Logging
Health Endpoint
curl http://localhost:3000/health
Response:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.000Z",
"browsers": {
"chromium": true,
"firefox": true,
"webkit": true
}
}
Logs
- Console logs: Real-time server status
- Error logs: Saved to
error.log - Structured logging: JSON format with timestamps
Security Considerations
- Non-root execution: Container runs as
playwrightuser - Resource limits: Memory and CPU constraints in docker-compose
- Network security: Only port 3000 exposed
- Input validation: All MCP parameters validated
- Browser isolation: Each request uses isolated browser contexts
Troubleshooting
Common Issues
-
Browser initialization fails
- Check available memory (minimum 2GB recommended)
- Ensure Docker has sufficient resources
-
Timeout errors
- Increase timeout values in MCP tool parameters
- Check network connectivity
-
Memory issues
- Monitor Docker memory usage
- Consider scaling horizontally
Debug Mode
# Enable debug logging
docker-compose up --build
Container Shell Access
docker exec -it playwright-mcp-server_playwright-mcp_1 /bin/bash
Performance Tuning
Resource Requirements
| Deployment Size | CPU | Memory | Browsers |
|---|---|---|---|
| Small | 1 vCPU | 2GB RAM | Chromium only |
| Medium | 2 vCPU | 4GB RAM | All browsers |
| Large | 4 vCPU | 8GB RAM | All + concurrent |
Optimization Tips
- Browser selection: Use Chromium for best performance
- Context cleanup: Automatic cleanup after each operation
- Resource monitoring: Use health endpoints for monitoring
- Horizontal scaling: Deploy multiple instances behind load balancer
Contributing
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push branch:
git push origin feature/amazing-feature - Create Pull Request
License
MIT License - see file for details.
Support
- 📧 Issues: GitHub Issues
- 📖 Documentation: This README
- 🐳 Docker: Official Playwright Docker images
- 🎭 Playwright: Playwright Documentation
Built with ❤️ using Playwright and Docker