-
Notifications
You must be signed in to change notification settings - Fork 0
MCP Server
yhAutomationQA edited this page May 9, 2026
·
1 revision
The framework includes a Model Context Protocol (MCP) server that exposes Playwright automation capabilities to AI assistants like Claude and GPT.
MCP is an open standard that lets AI assistants interact with tools and data through a standardized interface. The Playwright MCP server exposes browser automation as tools the AI can call.
# Start MCP server (stdio mode — for AI assistant integration)
npm run mcp
# HTTP mode (for remote access)
npm run mcp:local
# Debug mode (headed browser)
npm run mcp:debug| Variable | Default | Description |
|---|---|---|
MCP_MODE |
stdio |
Transport: stdio or http
|
MCP_PORT |
3100 |
HTTP server port |
MCP_HOST |
localhost |
HTTP server host |
MCP_HEADLESS |
true |
Run browser headless |
MCP_BROWSER |
chromium |
Browser: chromium, firefox, webkit
|
MCP_OUTPUT_DIR |
./mcp-output |
Output directory for traces/screenshots |
MCP_SAVE_SESSION |
false |
Persist browser session to disk |
MCP_CAPABILITIES |
core,network,storage,vision |
Enabled tool categories |
| Capability | Purpose |
|---|---|
core |
Navigate, click, fill, select, hover, scroll |
network |
Inspect requests, responses, network logs |
storage |
Cookies, localStorage, sessionStorage |
vision |
Coordinate-based interactions, screenshots |
pdf |
PDF generation from pages |
devtools |
Chrome DevTools Protocol (chromium only) |
npm run mcp:example:loginAutomates login to SauceDemo, captures a screenshot, extracts the page snapshot, and saves auth state for reuse.
npm run mcp:example:locatorInspects multiple locators on the login page and reports their existence, visibility, count, tag name, text content, attributes, and bounding box.
npm run mcp:example:traceRecords a Playwright trace of the login flow, then saves it for viewing with npx playwright show-trace.
- Start the MCP server:
npm run mcp - Configure your AI assistant to connect via stdio or HTTP
- The AI can control the browser, inspect pages, capture traces, and more
mcp/
├── config.ts # Environment-based configuration
├── mcp-server.ts # Main MCP server entry point
├── session-manager.ts # Browser session lifecycle
├── trace-collector.ts # Trace capture utilities
├── screenshot-capture.ts # Screenshot utilities
├── page-snapshot.ts # Page structure extraction
├── locator-debugger.ts # Locator inspection
├── auth-reuse.ts # Auth state persistence
├── index.ts # Public exports
└── examples/
├── login-automation.ts
├── locator-inspection.ts
└── trace-debugging.ts
| Issue | Solution |
|---|---|
| Server won't start | Run npm install, check Node.js >= 22 |
| Browser not found | Run npx playwright install chromium
|
| Port in use | Set MCP_PORT to a different port |
| AI not connecting | Verify transport mode matches (stdio vs HTTP) |
| Need headed debugging | Set MCP_HEADLESS=false
|