Playwright MCP Server
A minimal server that exposes Playwright browser automation capabilities through a simple API, enabling webpage interaction, DOM manipulation, and content extraction via the Model Context Protocol.
README
Playwright MCP Server
A minimal, robust Playwright MCP (Model Context Protocol) server that exposes core browser automation capabilities via a simple API.
Features
- Browser Context Management: Persistent browser context (headless or headed, configurable)
- Navigation: Open URLs, reload, go back/forward
- DOM Interaction: Click, type, fill, select, hover, scroll using Playwright selectors
- Element Discovery: Query elements using CSS, XPath, role, text, and other Playwright locators
- Snapshotting: Get HTML, accessibility snapshots, screenshots, and PDFs
- Script Evaluation: Run JavaScript in the page context
- Network Monitoring: Capture and analyze all network requests and responses
- Network Interception: Block, modify, or mock network requests
- Cookie Management: Get, set, and clear browser cookies
- Storage Access: Manage localStorage and sessionStorage data
- Headers & User Agent: Customize request headers and browser identity
- Raw Output: All outputs are raw Playwright results with no post-processing
Installation
Quick Install from GitHub
# Install directly from GitHub
pip install git+https://github.com/alexrwilliam/playwright-mcp-server.git
# Install Playwright browsers
playwright install
For Development
# Clone the repository
git clone https://github.com/alexrwilliam/playwright-mcp-server.git
cd playwright-mcp-server
# Install in development mode
pip install -e .
# Install browsers
playwright install
Usage
Running the Server
After installation, you can use it from anywhere:
# Run with stdio transport (for MCP clients)
playwright-mcp stdio
# Run with HTTP transport
playwright-mcp http --port 8000
# Run in headed mode (default is headless)
playwright-mcp stdio --headed
Command Line Usage
# Run the MCP server
playwright-mcp stdio
# Run with visible browser
playwright-mcp stdio --headed
# Run HTTP server
playwright-mcp http --port 8000
# Use different browsers
playwright-mcp stdio --browser firefox
playwright-mcp stdio --browser webkit
# Use real Chrome instead of bundled Chromium
playwright-mcp stdio --channel chrome
# Use real Chrome with your profile (cookies, extensions, history)
playwright-mcp stdio --channel chrome --user-data-dir "/Users/you/Library/Application Support/Google/Chrome"
# Other Chrome channels
playwright-mcp stdio --channel chrome-beta
playwright-mcp stdio --channel chrome-dev
Integration with Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"playwright": {
"command": "playwright-mcp",
"args": ["stdio"]
}
}
}
Testing with MCP Inspector
# Install and run MCP inspector
uv run mcp dev src/playwright_mcp/server.py
API Reference
Tools
Navigation & Page Control
navigate(url: str)- Navigate to a URLreload()- Reload the current pagego_back()- Go back in historygo_forward()- Go forward in historywait_for_url(url_pattern: str, timeout: int)- Wait for URL to match patternwait_for_load_state(state: str, timeout: int)- Wait for page load states (domcontentloaded, load, networkidle)set_viewport_size(width: int, height: int)- Set viewport dimensions
Element Interaction
click(selector: str)- Click an elementtype_text(selector: str, text: str)- Type text into an elementfill(selector: str, value: str)- Fill an input fieldclear_text(selector: str)- Clear input field textselect_option(selector: str, value: str)- Select an optionhover(selector: str)- Hover over an elementscroll(selector: str, x: int, y: int)- Scroll elementpress_key(key: str)- Press keyboard key
Form Handling
check_checkbox(selector: str)- Check a checkboxuncheck_checkbox(selector: str)- Uncheck a checkboxupload_file(selector: str, file_path: str)- Upload file to input
Element Discovery & Validation
query_selector(selector: str)- Query for single elementquery_selector_all(selector: str)- Query for all matching elementsis_visible(selector: str)- Check if element is visibleis_enabled(selector: str)- Check if element is enabledwait_for_element(selector: str, timeout: int)- Wait for element to appearget_element_bounding_box(selector: str)- Get element position and sizeget_element_attributes(selector: str)- Get all element attributesget_computed_style(selector: str, property: str)- Get CSS computed style
Content & Snapshots
get_html()- Get page HTMLget_accessibility_snapshot()- Get accessibility treescreenshot(selector: str, full_page: bool)- Take screenshot of page or elementpdf()- Generate PDF of page
JavaScript & Debugging
evaluate(script: str)- Execute JavaScript in page contextwait_for_network_idle(timeout: int)- Wait for network activity to settleget_page_errors()- Get JavaScript errors from pageget_console_logs()- Get console output from page
Network Monitoring & Interception
get_network_requests(url_pattern: str)- Retrieve captured network requests with filteringget_network_responses(url_pattern: str)- Retrieve captured network responses with filteringclear_network_logs()- Clear all captured network request/response logsintercept_route(url_pattern: str, action: str, ...)- Intercept and handle network requestsunroute_all()- Remove all route interceptorswait_for_response(url_pattern: str, timeout: int)- Wait for specific network responsesget_response_body(url_pattern: str)- Extract response body content from network calls
Cookie Management
get_cookies(urls: List[str])- Retrieve browser cookies with optional URL filteringadd_cookies(cookies: List[Dict])- Add cookies to browser contextclear_cookies(name: str, domain: str)- Clear cookies with optional filtering
Storage Management
get_local_storage(origin: str)- Access localStorage dataset_local_storage(key: str, value: str)- Set localStorage itemsget_session_storage()- Access sessionStorage dataset_session_storage(key: str, value: str)- Set sessionStorage itemsclear_storage(storage_type: str)- Clear localStorage and/or sessionStorage
Request Headers & Identity
set_extra_headers(headers: Dict)- Add custom HTTP headers to all requestsset_user_agent(user_agent: str)- Change browser User-Agent string
Configuration
The server accepts the following configuration options:
--headed/--headless- Run browser in headed or headless mode--browser- Browser type (chromium, firefox, webkit)--channel- Browser channel (chrome, chrome-beta, msedge, etc.) for real browsers--user-data-dir- Path to browser profile directory for persistent context--port- Port for HTTP transport--timeout- Default timeout for operations (ms)
Real Chrome vs Bundled Chromium
By default, Playwright uses bundled Chromium. For web scraping that requires real Chrome features:
Use --channel chrome to use your installed Google Chrome:
- Access to all Chrome features and codecs
- Better compatibility with some websites
- Chrome-specific behaviors
Use --user-data-dir to access your real profile:
- All your cookies and login sessions
- Browser extensions (AdBlock, etc.)
- Browsing history and autofill data
- Bookmarks and saved passwords
Example for macOS:
playwright-mcp stdio --channel chrome --user-data-dir "/Users/$(whoami)/Library/Application Support/Google/Chrome"
Example for Linux:
playwright-mcp stdio --channel chrome --user-data-dir "/home/$(whoami)/.config/google-chrome"
Development
# Clone the repository
git clone <repo-url>
cd playwright-mcp
# Install dependencies
uv sync --dev
# Run tests
uv run pytest
# Format code
uv run black src/
uv run ruff check src/
# Type check
uv run mypy src/
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。