- Playwright MCP Server
Playwright MCP Server
Content
Playwright MCP Server
This server provides a comprehensive set of tools to control a web browser instance using Playwright, exposed via the Model Context Protocol (MCP). It allows AI models or other MCP clients to perform complex web browsing tasks across multiple pages/tabs.
Features
- Multi-Page Management: Open, close, switch between, and list multiple browser pages/tabs. Tools target the active page by default or a specific page via
page_id. - Robust Lifecycle: Uses FastMCP's lifespan manager for reliable setup and teardown of Playwright resources (browser, pages).
- Comprehensive Tools:
- Page Management: Open, close, switch, and list pages
- Navigation: Go to URLs, back/forward navigation, reload
- Content Retrieval: Get HTML, text content, titles, URLs
- Interaction: Click, fill, type, press keys, check/uncheck, select options, hover, drag-and-drop
- Waiting: Wait for elements, URLs, load states, timing
- State/Information: Element state, attributes, bounding boxes
- Visuals: Page and element screenshots
- JavaScript Evaluation: Execute arbitrary JS (use with caution)
Installation
-
Install Dependencies:
pip install "fastmcp>=2.0.0" playwright -
Install Playwright Browsers:
playwright install chromium
Usage
Running the Server
use fastmcp CLI:
fastmcp run main.py --transport sse --port 8001
Run the client script:
python client_example.py
Tool Reference
Page Management
| Tool | Description |
|---|---|
playwright_open_page | Opens a new browser page/tab |
playwright_close_page | Closes a specific page or the current one |
playwright_switch_page | Makes a specific page active |
playwright_list_pages | Lists all open pages |
Navigation
| Tool | Description |
|---|---|
playwright_goto | Navigates to a URL |
playwright_go_back | Navigates back in history |
playwright_go_forward | Navigates forward in history |
playwright_reload | Reloads the current page |
Content Retrieval
| Tool | Description |
|---|---|
playwright_get_content | Gets the full HTML content |
playwright_get_text_content | Gets text content of page or element |
playwright_get_title | Gets the page title |
playwright_get_url | Gets the current URL |
Interaction
| Tool | Description |
|---|---|
playwright_click | Clicks an element |
playwright_fill | Fills a form field |
playwright_type | Types text with keyboard simulation |
playwright_press | Presses keyboard keys |
playwright_check | Checks a checkbox or radio button |
playwright_uncheck | Unchecks a checkbox |
playwright_select_option | Selects dropdown options |
playwright_hover | Hovers over an element |
playwright_scroll_into_view | Scrolls an element into view |
playwright_set_input_files | Uploads files to a file input |
playwright_drag_and_drop | Drags one element to another |
Waiting
| Tool | Description |
|---|---|
playwright_wait_for_selector | Waits for an element to reach a state |
playwright_wait_for_url | Waits for URL to match pattern |
playwright_wait_for_load_state | Waits for a specific load state |
playwright_sleep | Pauses execution |
State and Information
| Tool | Description |
|---|---|
playwright_get_element_state | Gets element visibility, enabled state, etc. |
playwright_get_attribute | Gets an attribute value |
playwright_get_bounding_box | Gets element position and dimensions |
playwright_get_computed_style | Gets computed CSS property |
Visuals
| Tool | Description |
|---|---|
playwright_take_screenshot | Takes a screenshot of the page |
playwright_take_element_screenshot | Takes a screenshot of an element |
JavaScript
| Tool | Description |
|---|---|
playwright_evaluate | Evaluates JavaScript and returns result |
playwright_execute_javascript | Executes JavaScript without return value |
Security Notes
The playwright_evaluate and playwright_execute_javascript tools are powerful but potentially dangerous if the server is exposed publicly. Use these with caution or disable them if security is a concern.
Client Example
import asyncio
from fastmcp import Client
async def main():
async with Client("stdio://python main.py") as client:
# Open a new page and navigate to a website
page_info = await client.call_tool("playwright_open_page", {"url": "https://example.com"})
# Get the page title
title = await client.call_tool("playwright_get_title", {})
print(f"Page title: {title}")
# Click a button
await client.call_tool("playwright_click", {"selector": "button.submit"})
# Take a screenshot
screenshot = await client.call_tool("playwright_take_screenshot", {"full_page": True})
if __name__ == "__main__":
asyncio.run(main())
License
This project is licensed under the MIT License - see the LICENSE file for details.
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Amap Maps高德地图官方 MCP Server
DeepChatYour AI Partner on Desktop
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Playwright McpPlaywright MCP server
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
WindsurfThe new purpose-built IDE to harness magic
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
CursorThe AI Code Editor
Serper MCP ServerA Serper MCP Server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
ChatWiseThe second fastest AI chatbot™