Sponsored by Deepsite.site

Playwright MCP Server

Created By
san08087 months ago
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.
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

  1. Install Dependencies:

    pip install "fastmcp>=2.0.0" playwright
    
  2. 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

ToolDescription
playwright_open_pageOpens a new browser page/tab
playwright_close_pageCloses a specific page or the current one
playwright_switch_pageMakes a specific page active
playwright_list_pagesLists all open pages
ToolDescription
playwright_gotoNavigates to a URL
playwright_go_backNavigates back in history
playwright_go_forwardNavigates forward in history
playwright_reloadReloads the current page

Content Retrieval

ToolDescription
playwright_get_contentGets the full HTML content
playwright_get_text_contentGets text content of page or element
playwright_get_titleGets the page title
playwright_get_urlGets the current URL

Interaction

ToolDescription
playwright_clickClicks an element
playwright_fillFills a form field
playwright_typeTypes text with keyboard simulation
playwright_pressPresses keyboard keys
playwright_checkChecks a checkbox or radio button
playwright_uncheckUnchecks a checkbox
playwright_select_optionSelects dropdown options
playwright_hoverHovers over an element
playwright_scroll_into_viewScrolls an element into view
playwright_set_input_filesUploads files to a file input
playwright_drag_and_dropDrags one element to another

Waiting

ToolDescription
playwright_wait_for_selectorWaits for an element to reach a state
playwright_wait_for_urlWaits for URL to match pattern
playwright_wait_for_load_stateWaits for a specific load state
playwright_sleepPauses execution

State and Information

ToolDescription
playwright_get_element_stateGets element visibility, enabled state, etc.
playwright_get_attributeGets an attribute value
playwright_get_bounding_boxGets element position and dimensions
playwright_get_computed_styleGets computed CSS property

Visuals

ToolDescription
playwright_take_screenshotTakes a screenshot of the page
playwright_take_element_screenshotTakes a screenshot of an element

JavaScript

ToolDescription
playwright_evaluateEvaluates JavaScript and returns result
playwright_execute_javascriptExecutes 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™