playwright-mcp: Browser Automation via Accessibility Tree for LLMs
playwright-mcp: Browser Automation via Accessibility Tree for LLMs
The playwright-mcp MCP Server provides a direct pathway for LLMs to control web browsers, leveraging Playwright's accessibility tree. This approach offers a fast, lightweight, and deterministic method for browser automation, bypassing the typical need for vision models or pixel-based input.
Integrating with LLMs in VS Code
playwright-mcp is designed for straightforward integration, particularly within VS Code environments. Once installed, it becomes available for use with GitHub Copilot agents. The server can be configured to run in either headless or headed mode, with an option to specify a port for SSE transport.
Installation in VS Code is handled via CLI commands:
code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'For VS Code Insiders, use code-insiders instead:
code-insiders --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'To run the browser in headless mode, the mcpServers configuration should include the --headless flag. playwright-mcp launches Chrome with a new profile, which can be deleted to clear its offline state.
Tooling for Web Interaction
playwright-mcp exposes a set of tools that LLMs can call to interact with web pages. These tools operate under two primary modes: Snapshot Mode and Vision Mode. Snapshot Mode is the default and relies on accessibility snapshots, while Vision Mode uses screenshots.
Key capabilities and tools include:
- Fast and lightweight interaction: Achieved by using Playwright's accessibility tree, avoiding pixel-based input.
- LLM-friendly data: Operates purely on structured data, eliminating the need for vision models.
- Deterministic tool application: Reduces ambiguity often found in screenshot-based approaches.
Snapshot Mode Tools
These tools enable core browser actions:
browser_navigate: Directs the browser to a specified URL.browser_go_back: Navigates to the previous page in the browser history.browser_go_forward: Navigates to the next page in the browser history.- Additional tools for clicking, typing, and capturing snapshots are also available.
Vision Mode Tools
When configured for Vision Mode, the server offers tools for screenshot capture and other vision-based interactions, as detailed in the project's README.
Practical Use Cases
The structured data approach of playwright-mcp makes it well-suited for several agent-driven web tasks:
- Web navigation and form-filling: LLMs can navigate websites and complete forms programmatically.
- Data extraction: Enables extraction of specific data points from structured web content.
- Automated testing: Supports LLM-driven workflows for automated web application testing.
- General-purpose browser interaction: Provides a versatile interface for agents requiring web access.
By abstracting browser interaction into structured, deterministic tools, playwright-mcp offers a compelling alternative for developers building LLM agents that need to operate reliably within web environments.
References
- playwright-mcp on GitHub
- Model Context Protocol Documentation
- playwright-mcp on model-context-protocol.com