浏览器自动化服务

一个多租户的Playwright浏览器自动化MCP服务器,支持平台JWT认证,适用于需要自动化浏览器操作的场景。

  • by prmichaelsen
  • Shell
  • 本地部署
  • 更新于
在 GitHub 查看 prmichaelsen/playwright-mcp-server

使用说明

Playwright MCP Wrapper

Multi-tenant Playwright browser automation MCP server with Platform JWT authentication.

Features

  • 🔐 Platform JWT authentication (no OAuth required)
  • 🌐 Multi-tenant support (single server, multiple users)
  • 🎭 Playwright browser automation
  • 🔒 Isolated browser contexts per user
  • ☁️ Cloud Run deployment ready
  • 📊 Rate limiting and monitoring

Architecture

This is a static server - no per-user credentials needed:

  • No OAuth flow
  • No user account connection
  • Just JWT authentication
  • Available to all users immediately

Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • npm or yarn
  • Docker (for containerization)
  • GCP account (for deployment)

Installation

# Clone repository
git clone <repository-url>
cd playwright-mcp-server

# Install dependencies
npm install

# Copy environment template
cp .env.example .env

# Edit .env with your PLATFORM_SERVICE_TOKEN
nano .env

# Build
npm run build

# Run
npm start

Development

# Run in watch mode
npm run dev

Configuration

Environment Variables

Variable Required Default Description
PLATFORM_SERVICE_TOKEN Yes - JWT validation secret
PORT No 8080 Server port
NODE_ENV No development Environment
CORS_ORIGIN No https://agentbase.me CORS origin

API Usage

Authentication

All requests require a valid Platform JWT in the Authorization header:

curl -X POST http://localhost:8080/mcp/message \
  -H "Authorization: Bearer <jwt-token>" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","id":1}'

Available Tools

  • playwright_navigate - Navigate to URL
  • playwright_screenshot - Capture screenshot
  • playwright_click - Click element
  • playwright_fill - Fill form field
  • playwright_evaluate - Execute JavaScript
  • playwright_pdf - Generate PDF

Deployment

Docker

# Build image
docker build -t playwright-mcp-wrapper .

# Run container
docker run -p 8080:8080 \
  -e PLATFORM_SERVICE_TOKEN=your-token \
  playwright-mcp-wrapper

Google Cloud Run

# Deploy
gcloud builds submit --config cloudbuild.yaml \
  --substitutions=_CORS_ORIGIN=https://agentbase.me,COMMIT_SHA=$(git rev-parse HEAD)

See DEPLOYMENT.md for detailed instructions.

Development

Project Structure

playwright-mcp-server/
├── src/
│   ├── index.ts                    # Main entry point
│   └── auth/
│       └── platform-jwt-provider.ts # JWT validation
├── agent/                          # ACP documentation
├── scripts/                        # Utility scripts
├── package.json
├── tsconfig.json
├── Dockerfile
└── cloudbuild.yaml

Scripts

  • npm run build - Compile TypeScript
  • npm run dev - Run in watch mode
  • npm start - Run production build
  • npm run script - Run TypeScript scripts

Security

  • JWT validation on all requests
  • CORS configuration
  • Rate limiting (50 req/hour per user)
  • Isolated browser contexts
  • No persistent state

Monitoring

  • Health check: GET /mcp/health
  • Cloud Logging integration
  • Cloud Monitoring metrics

License

MIT

Support

For issues and questions, please open an issue on GitHub.