Configuration Guide
Configuration Guide
Section titled “Configuration Guide”Version: 1.0.13
Reading Time: 8 minutes
Overview
Section titled “Overview”Configure Puppeteer MCP to match your needs. This guide covers environment variables, configuration files, security settings, and performance tuning.
Configuration Methods
Section titled “Configuration Methods”Puppeteer MCP can be configured through:
- Environment Variables (recommended)
- Configuration Files (
.env
or JSON) - Command Line Arguments
- Runtime API (for dynamic changes)
Quick Configuration
Section titled “Quick Configuration”Basic Setup (.env file)
Section titled “Basic Setup (.env file)”Create a .env
file in your project root:
# Server ConfigurationPORT=3000NODE_ENV=production
# AuthenticationPUPPETEER_MCP_AUTH_TOKEN=your-secure-token-here
# Browser SettingsPUPPETEER_HEADLESS=trueMAX_SESSIONS=10SESSION_TIMEOUT=1800000
Generate Secure Token
Section titled “Generate Secure Token”# Using Node.jsnode -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
# Using OpenSSLopenssl rand -hex 32
Environment Variables Reference
Section titled “Environment Variables Reference”Server Configuration
Section titled “Server Configuration”Core Server Settings
Variable | Default | Description |
---|---|---|
PORT | 3000 | REST API and WebSocket port |
GRPC_PORT | 50051 | gRPC service port |
NODE_ENV | development | Environment mode (development , production , test ) |
LOG_LEVEL | info | Logging level (debug , info , warn , error ) |
HOST | 0.0.0.0 | Server bind address |
Example:
PORT=3001 GRPC_PORT=50052 NODE_ENV=production puppeteer-mcp
Authentication & Security
Section titled “Authentication & Security”Security Settings
Variable | Default | Description |
---|---|---|
PUPPETEER_MCP_AUTH_TOKEN | none | Bearer token for API authentication |
JWT_SECRET | auto-generated | Secret for JWT signing |
JWT_EXPIRES_IN | 1h | JWT token expiration |
JWT_REFRESH_EXPIRES_IN | 7d | Refresh token expiration |
API_KEY_HEADER | X-API-Key | Header name for API key auth |
ENABLE_CORS | true | Enable CORS support |
CORS_ORIGIN | * | Allowed CORS origins |
Example:
PUPPETEER_MCP_AUTH_TOKEN=abc123 JWT_SECRET=mysecret puppeteer-mcp
Browser Configuration
Section titled “Browser Configuration”Puppeteer Settings
Variable | Default | Description |
---|---|---|
PUPPETEER_HEADLESS | true | Run browsers in headless mode |
PUPPETEER_EXECUTABLE_PATH | auto-detect | Path to Chrome/Chromium |
PUPPETEER_ARGS | none | Additional browser launch args |
PUPPETEER_IGNORE_HTTPS_ERRORS | false | Ignore HTTPS certificate errors |
PUPPETEER_SLOW_MO | 0 | Slow down operations by ms |
PUPPETEER_DEVTOOLS | false | Auto-open DevTools |
DEFAULT_VIEWPORT_WIDTH | 1920 | Default viewport width |
DEFAULT_VIEWPORT_HEIGHT | 1080 | Default viewport height |
Example:
PUPPETEER_HEADLESS=false PUPPETEER_SLOW_MO=250 puppeteer-mcp
Session Management
Section titled “Session Management”Session & Resource Limits
Variable | Default | Description |
---|---|---|
MAX_SESSIONS | 10 | Maximum concurrent browser sessions |
SESSION_TIMEOUT | 1800000 | Session idle timeout (ms) |
MAX_PAGES_PER_SESSION | 10 | Max pages per browser session |
CLEANUP_INTERVAL | 60000 | Resource cleanup interval (ms) |
MEMORY_LIMIT | 1024 | Memory limit per browser (MB) |
CPU_LIMIT | 0.5 | CPU limit per browser (0.5 = 50%) |
Example:
MAX_SESSIONS=5 SESSION_TIMEOUT=600000 puppeteer-mcp
Performance & Optimization
Section titled “Performance & Optimization”Performance Tuning
Variable | Default | Description |
---|---|---|
BROWSER_POOL_MIN | 1 | Minimum browsers in pool |
BROWSER_POOL_MAX | 5 | Maximum browsers in pool |
BROWSER_POOL_ACQUIRE_TIMEOUT | 30000 | Pool acquire timeout (ms) |
BROWSER_POOL_IDLE_TIMEOUT | 300000 | Pool idle timeout (ms) |
ENABLE_BROWSER_CACHE | true | Enable browser disk cache |
CACHE_SIZE_MB | 100 | Browser cache size (MB) |
RATE_LIMIT_ENABLED | true | Enable API rate limiting |
RATE_LIMIT_MAX | 100 | Max requests per window |
RATE_LIMIT_WINDOW | 15m | Rate limit time window |
Example:
BROWSER_POOL_MAX=3 RATE_LIMIT_MAX=50 puppeteer-mcp
Configuration Files
Section titled “Configuration Files”JSON Configuration
Section titled “JSON Configuration”Create puppeteer-mcp.config.json
:
{ "server": { "port": 3000, "grpcPort": 50051, "host": "localhost" }, "auth": { "token": "your-secure-token", "jwtSecret": "your-jwt-secret", "jwtExpiresIn": "1h" }, "browser": { "headless": true, "args": ["--no-sandbox", "--disable-setuid-sandbox"], "defaultViewport": { "width": 1920, "height": 1080 } }, "session": { "maxSessions": 10, "timeout": 1800000, "maxPagesPerSession": 10 }, "pool": { "min": 1, "max": 5, "acquireTimeout": 30000, "idleTimeout": 300000 }}
YAML Configuration
Section titled “YAML Configuration”Create puppeteer-mcp.config.yaml
:
server: port: 3000 grpcPort: 50051 host: localhost
auth: token: your-secure-token jwtSecret: your-jwt-secret jwtExpiresIn: 1h
browser: headless: true args: - --no-sandbox - --disable-setuid-sandbox defaultViewport: width: 1920 height: 1080
session: maxSessions: 10 timeout: 1800000 maxPagesPerSession: 10
Security Configuration
Section titled “Security Configuration”Production Security Checklist
Section titled “Production Security Checklist”Essential Security Settings
# 1. Generate strong secretsexport PUPPETEER_MCP_AUTH_TOKEN=$(openssl rand -hex 32)export JWT_SECRET=$(openssl rand -hex 64)
# 2. Set production modeexport NODE_ENV=production
# 3. Configure CORSexport ENABLE_CORS=trueexport CORS_ORIGIN=https://your-domain.com
# 4. Enable rate limitingexport RATE_LIMIT_ENABLED=trueexport RATE_LIMIT_MAX=50export RATE_LIMIT_WINDOW=15m
# 5. Set secure browser optionsexport PUPPETEER_HEADLESS=trueexport PUPPETEER_ARGS="--no-sandbox --disable-dev-shm-usage"
# 6. Configure timeoutsexport SESSION_TIMEOUT=900000 # 15 minutesexport MAX_SESSIONS=5
Authentication Strategies
Section titled “Authentication Strategies”Bearer Token Authentication
# Set tokenexport PUPPETEER_MCP_AUTH_TOKEN=your-secure-token
# Client usagecurl -H "Authorization: Bearer your-secure-token" \ http://localhost:8443/api/sessions
API Key Authentication
# Set API key headerexport API_KEY_HEADER=X-API-Key
# Client usagecurl -H "X-API-Key: your-api-key" \ http://localhost:8443/api/sessions
JWT Authentication
# Configure JWTexport JWT_SECRET=your-jwt-secretexport JWT_EXPIRES_IN=1hexport JWT_REFRESH_EXPIRES_IN=7d
# Login to get tokencurl -X POST http://localhost:8443/api/auth/login \ -H "Content-Type: application/json" \ -d '{"email": "user@example.com", "password": "pass"}'
Performance Optimization
Section titled “Performance Optimization”Memory Management
Section titled “Memory Management”Optimize Memory Usage
# Limit browser memoryexport MEMORY_LIMIT=512 # MB per browserexport MAX_SESSIONS=3
# Use shared memory efficientlyexport PUPPETEER_ARGS="--disable-dev-shm-usage --shm-size=1gb"
# Enable aggressive cleanupexport CLEANUP_INTERVAL=30000 # 30 secondsexport SESSION_TIMEOUT=300000 # 5 minutes
CPU Optimization
Section titled “CPU Optimization”Control CPU Usage
# Limit CPU per browserexport CPU_LIMIT=0.25 # 25% per browser
# Disable unnecessary featuresexport PUPPETEER_ARGS="--disable-gpu --disable-webgl --disable-3d-apis"
# Reduce render loadexport PUPPETEER_ARGS="$PUPPETEER_ARGS --disable-images --disable-javascript"
Network Optimization
Section titled “Network Optimization”Optimize Network Performance
# Enable compressionexport ENABLE_COMPRESSION=true
# Configure proxyexport HTTP_PROXY=http://proxy.example.com:8080export HTTPS_PROXY=http://proxy.example.com:8080
# Optimize DNSexport PUPPETEER_ARGS="--host-resolver-rules='MAP * 8.8.8.8'"
Docker Configuration
Section titled “Docker Configuration”Docker Environment File
Section titled “Docker Environment File”Create .env.docker
:
# ServerPORT=3000NODE_ENV=production
# SecurityPUPPETEER_MCP_AUTH_TOKEN=${PUPPETEER_MCP_AUTH_TOKEN}JWT_SECRET=${JWT_SECRET}
# Browser (Docker-specific)PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browserPUPPETEER_ARGS=--no-sandbox --disable-setuid-sandbox
# ResourcesMAX_SESSIONS=5MEMORY_LIMIT=512
Docker Compose Configuration
Section titled “Docker Compose Configuration”version: '3.8'
services: puppeteer-mcp: image: puppeteer-mcp:latest ports: - '3000:3000' - '50051:50051' env_file: .env.docker environment: - NODE_ENV=production volumes: - ./config:/app/config deploy: resources: limits: cpus: '2' memory: 2G reservations: cpus: '1' memory: 1G
Monitoring & Logging
Section titled “Monitoring & Logging”Logging Configuration
Section titled “Logging Configuration”Configure Logging
# Log levels: debug, info, warn, errorexport LOG_LEVEL=info
# Log formatexport LOG_FORMAT=json # or 'pretty'
# Log destinationsexport LOG_FILE=/var/log/puppeteer-mcp.logexport LOG_CONSOLE=true
# Debug specific modulesexport DEBUG=puppeteer:* # All Puppeteer logsexport DEBUG=mcp:* # All MCP logsexport DEBUG=* # Everything
Metrics & Health Checks
Section titled “Metrics & Health Checks”Enable Monitoring
# Enable metrics endpointexport ENABLE_METRICS=trueexport METRICS_PORT=9090
# Health check settingsexport HEALTH_CHECK_INTERVAL=30000export HEALTH_CHECK_TIMEOUT=5000
# Prometheus metricsexport PROMETHEUS_ENABLED=trueexport PROMETHEUS_PREFIX=puppeteer_mcp_
Configuration Priority
Section titled “Configuration Priority”Configuration is loaded in this order (later overrides earlier):
- Default values (built-in)
- Configuration file (
puppeteer-mcp.config.{json,yaml,js}
) .env
file- Environment variables
- Command line arguments
Example:
# .env filePORT=3000
# Override with environment variablePORT=3001 puppeteer-mcp
# Override with command linepuppeteer-mcp --port 3002
Advanced Configuration
Section titled “Advanced Configuration”Custom Browser Profiles
Section titled “Custom Browser Profiles”module.exports = { browser: { userDataDir: './profiles/user1', args: ['--user-agent=CustomBot/1.0', '--window-size=1920,1080', '--lang=en-US'], ignoreDefaultArgs: ['--disable-extensions'], },};
Plugin Configuration
Section titled “Plugin Configuration”{ "plugins": { "authentication": { "provider": "oauth2", "config": { "clientId": "your-client-id", "clientSecret": "your-client-secret" } }, "storage": { "provider": "s3", "config": { "bucket": "puppeteer-screenshots", "region": "us-east-1" } } }}
Troubleshooting Configuration
Section titled “Troubleshooting Configuration”Verify Configuration
Section titled “Verify Configuration”# Show current configurationpuppeteer-mcp --show-config
# Validate configuration filepuppeteer-mcp --validate-config
# Test configurationpuppeteer-mcp --test
Common Configuration Issues
Section titled “Common Configuration Issues”Configuration Not Loading
- Check file location and name
- Verify JSON/YAML syntax
- Check file permissions
- Look for error messages on startup
Environment Variables Not Working
- Verify variable names (case-sensitive)
- Check for typos
- Ensure no spaces around
=
- Try
export
before the variable
Next Steps
Section titled “Next Steps”Configuration complete! Continue with:
- First automation examples - Put configuration to use
- Security best practices - Harden your deployment
- Performance tuning - Optimize for scale
Pro Tip: Start with minimal configuration and add settings as needed. Over-configuration can make troubleshooting harder! 🎯