Skip to content

Configuration Guide

Version: 1.0.13
Reading Time: 8 minutes

Configure Puppeteer MCP to match your needs. This guide covers environment variables, configuration files, security settings, and performance tuning.

Puppeteer MCP can be configured through:

  1. Environment Variables (recommended)
  2. Configuration Files (.env or JSON)
  3. Command Line Arguments
  4. Runtime API (for dynamic changes)

Create a .env file in your project root:

Terminal window
# Server Configuration
PORT=3000
NODE_ENV=production
# Authentication
PUPPETEER_MCP_AUTH_TOKEN=your-secure-token-here
# Browser Settings
PUPPETEER_HEADLESS=true
MAX_SESSIONS=10
SESSION_TIMEOUT=1800000
Terminal window
# Using Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
# Using OpenSSL
openssl rand -hex 32
Core Server Settings
VariableDefaultDescription
PORT3000REST API and WebSocket port
GRPC_PORT50051gRPC service port
NODE_ENVdevelopmentEnvironment mode (development, production, test)
LOG_LEVELinfoLogging level (debug, info, warn, error)
HOST0.0.0.0Server bind address

Example:

Terminal window
PORT=3001 GRPC_PORT=50052 NODE_ENV=production puppeteer-mcp
Security Settings
VariableDefaultDescription
PUPPETEER_MCP_AUTH_TOKENnoneBearer token for API authentication
JWT_SECRETauto-generatedSecret for JWT signing
JWT_EXPIRES_IN1hJWT token expiration
JWT_REFRESH_EXPIRES_IN7dRefresh token expiration
API_KEY_HEADERX-API-KeyHeader name for API key auth
ENABLE_CORStrueEnable CORS support
CORS_ORIGIN*Allowed CORS origins

Example:

Terminal window
PUPPETEER_MCP_AUTH_TOKEN=abc123 JWT_SECRET=mysecret puppeteer-mcp
Puppeteer Settings
VariableDefaultDescription
PUPPETEER_HEADLESStrueRun browsers in headless mode
PUPPETEER_EXECUTABLE_PATHauto-detectPath to Chrome/Chromium
PUPPETEER_ARGSnoneAdditional browser launch args
PUPPETEER_IGNORE_HTTPS_ERRORSfalseIgnore HTTPS certificate errors
PUPPETEER_SLOW_MO0Slow down operations by ms
PUPPETEER_DEVTOOLSfalseAuto-open DevTools
DEFAULT_VIEWPORT_WIDTH1920Default viewport width
DEFAULT_VIEWPORT_HEIGHT1080Default viewport height

Example:

Terminal window
PUPPETEER_HEADLESS=false PUPPETEER_SLOW_MO=250 puppeteer-mcp
Session & Resource Limits
VariableDefaultDescription
MAX_SESSIONS10Maximum concurrent browser sessions
SESSION_TIMEOUT1800000Session idle timeout (ms)
MAX_PAGES_PER_SESSION10Max pages per browser session
CLEANUP_INTERVAL60000Resource cleanup interval (ms)
MEMORY_LIMIT1024Memory limit per browser (MB)
CPU_LIMIT0.5CPU limit per browser (0.5 = 50%)

Example:

Terminal window
MAX_SESSIONS=5 SESSION_TIMEOUT=600000 puppeteer-mcp
Performance Tuning
VariableDefaultDescription
BROWSER_POOL_MIN1Minimum browsers in pool
BROWSER_POOL_MAX5Maximum browsers in pool
BROWSER_POOL_ACQUIRE_TIMEOUT30000Pool acquire timeout (ms)
BROWSER_POOL_IDLE_TIMEOUT300000Pool idle timeout (ms)
ENABLE_BROWSER_CACHEtrueEnable browser disk cache
CACHE_SIZE_MB100Browser cache size (MB)
RATE_LIMIT_ENABLEDtrueEnable API rate limiting
RATE_LIMIT_MAX100Max requests per window
RATE_LIMIT_WINDOW15mRate limit time window

Example:

Terminal window
BROWSER_POOL_MAX=3 RATE_LIMIT_MAX=50 puppeteer-mcp

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
}
}

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
Essential Security Settings
Terminal window
# 1. Generate strong secrets
export PUPPETEER_MCP_AUTH_TOKEN=$(openssl rand -hex 32)
export JWT_SECRET=$(openssl rand -hex 64)
# 2. Set production mode
export NODE_ENV=production
# 3. Configure CORS
export ENABLE_CORS=true
export CORS_ORIGIN=https://your-domain.com
# 4. Enable rate limiting
export RATE_LIMIT_ENABLED=true
export RATE_LIMIT_MAX=50
export RATE_LIMIT_WINDOW=15m
# 5. Set secure browser options
export PUPPETEER_HEADLESS=true
export PUPPETEER_ARGS="--no-sandbox --disable-dev-shm-usage"
# 6. Configure timeouts
export SESSION_TIMEOUT=900000 # 15 minutes
export MAX_SESSIONS=5
Bearer Token Authentication
Terminal window
# Set token
export PUPPETEER_MCP_AUTH_TOKEN=your-secure-token
# Client usage
curl -H "Authorization: Bearer your-secure-token" \
http://localhost:8443/api/sessions
API Key Authentication
Terminal window
# Set API key header
export API_KEY_HEADER=X-API-Key
# Client usage
curl -H "X-API-Key: your-api-key" \
http://localhost:8443/api/sessions
JWT Authentication
Terminal window
# Configure JWT
export JWT_SECRET=your-jwt-secret
export JWT_EXPIRES_IN=1h
export JWT_REFRESH_EXPIRES_IN=7d
# Login to get token
curl -X POST http://localhost:8443/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "pass"}'
Optimize Memory Usage
Terminal window
# Limit browser memory
export MEMORY_LIMIT=512 # MB per browser
export MAX_SESSIONS=3
# Use shared memory efficiently
export PUPPETEER_ARGS="--disable-dev-shm-usage --shm-size=1gb"
# Enable aggressive cleanup
export CLEANUP_INTERVAL=30000 # 30 seconds
export SESSION_TIMEOUT=300000 # 5 minutes
Control CPU Usage
Terminal window
# Limit CPU per browser
export CPU_LIMIT=0.25 # 25% per browser
# Disable unnecessary features
export PUPPETEER_ARGS="--disable-gpu --disable-webgl --disable-3d-apis"
# Reduce render load
export PUPPETEER_ARGS="$PUPPETEER_ARGS --disable-images --disable-javascript"
Optimize Network Performance
Terminal window
# Enable compression
export ENABLE_COMPRESSION=true
# Configure proxy
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
# Optimize DNS
export PUPPETEER_ARGS="--host-resolver-rules='MAP * 8.8.8.8'"

Create .env.docker:

Terminal window
# Server
PORT=3000
NODE_ENV=production
# Security
PUPPETEER_MCP_AUTH_TOKEN=${PUPPETEER_MCP_AUTH_TOKEN}
JWT_SECRET=${JWT_SECRET}
# Browser (Docker-specific)
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
PUPPETEER_ARGS=--no-sandbox --disable-setuid-sandbox
# Resources
MAX_SESSIONS=5
MEMORY_LIMIT=512
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
Configure Logging
Terminal window
# Log levels: debug, info, warn, error
export LOG_LEVEL=info
# Log format
export LOG_FORMAT=json # or 'pretty'
# Log destinations
export LOG_FILE=/var/log/puppeteer-mcp.log
export LOG_CONSOLE=true
# Debug specific modules
export DEBUG=puppeteer:* # All Puppeteer logs
export DEBUG=mcp:* # All MCP logs
export DEBUG=* # Everything
Enable Monitoring
Terminal window
# Enable metrics endpoint
export ENABLE_METRICS=true
export METRICS_PORT=9090
# Health check settings
export HEALTH_CHECK_INTERVAL=30000
export HEALTH_CHECK_TIMEOUT=5000
# Prometheus metrics
export PROMETHEUS_ENABLED=true
export PROMETHEUS_PREFIX=puppeteer_mcp_

Configuration is loaded in this order (later overrides earlier):

  1. Default values (built-in)
  2. Configuration file (puppeteer-mcp.config.{json,yaml,js})
  3. .env file
  4. Environment variables
  5. Command line arguments

Example:

Terminal window
# .env file
PORT=3000
# Override with environment variable
PORT=3001 puppeteer-mcp
# Override with command line
puppeteer-mcp --port 3002
custom-config.js
module.exports = {
browser: {
userDataDir: './profiles/user1',
args: ['--user-agent=CustomBot/1.0', '--window-size=1920,1080', '--lang=en-US'],
ignoreDefaultArgs: ['--disable-extensions'],
},
};
{
"plugins": {
"authentication": {
"provider": "oauth2",
"config": {
"clientId": "your-client-id",
"clientSecret": "your-client-secret"
}
},
"storage": {
"provider": "s3",
"config": {
"bucket": "puppeteer-screenshots",
"region": "us-east-1"
}
}
}
}
Terminal window
# Show current configuration
puppeteer-mcp --show-config
# Validate configuration file
puppeteer-mcp --validate-config
# Test configuration
puppeteer-mcp --test
Configuration Not Loading
  1. Check file location and name
  2. Verify JSON/YAML syntax
  3. Check file permissions
  4. Look for error messages on startup
Environment Variables Not Working
  1. Verify variable names (case-sensitive)
  2. Check for typos
  3. Ensure no spaces around =
  4. Try export before the variable

Configuration complete! Continue with:

  1. First automation examples - Put configuration to use
  2. Security best practices - Harden your deployment
  3. Performance tuning - Optimize for scale

Pro Tip: Start with minimal configuration and add settings as needed. Over-configuration can make troubleshooting harder! 🎯