网页浏览器
STDIO基于Playwright的网页浏览自动化服务器
基于Playwright的网页浏览自动化服务器
An advanced web browsing server for the Model Context Protocol (MCP) powered by Playwright, enabling headless browser interactions through a flexible, secure API.
# Install MCP and Playwright pip install mcp playwright # Install browser dependencies playwright install
Add to your claude_desktop_config.json
:
{ "mcpServers": { "web-browser": { "command": "python", "args": [ "/path/to/your/server.py" ] } } }
# Browse to a website page_content = browse_to("https://example.com") # Extract page text text_content = extract_text_content() # Extract text from a specific element title_text = extract_text_content("h1.title")
# Navigate to a page browse_to("https://example.com/login") # Input text into a form input_text("#username", "your_username") input_text("#password", "your_password") # Click a login button click_element("#login-button")
# Capture full page screenshot full_page_screenshot = get_page_screenshots(full_page=True) # Capture specific element screenshot element_screenshot = get_page_screenshots(selector="#main-content")
# Get all links on the page page_links = get_page_links() # Get links matching a pattern filtered_links = get_page_links(filter_pattern="contact")
# Create a new tab tab_id = create_new_tab("https://example.com") # Create another tab another_tab_id = create_new_tab("https://example.org") # List all open tabs tabs = list_tabs() # Switch between tabs switch_tab(tab_id) # Close a tab close_tab(another_tab_id)
# Scroll the page scroll_page(direction="down", amount="page") # Execute JavaScript on the page result = execute_javascript("return document.title") # Get detailed page information page_info = get_page_info() # Refresh the current page refresh_page() # Wait for navigation to complete wait_for_navigation(timeout_ms=5000)
browse_to()
methodAll significant events are logged with detailed information for easy debugging.
browse_to(url: str, context: Optional[Any] = None)
url
: Website to navigate tocontext
: Optional context object (currently unused)extract_text_content(selector: Optional[str] = None, context: Optional[Any] = None)
selector
: Optional CSS selector to extract specific contentcontext
: Optional context object (currently unused)click_element(selector: str, context: Optional[Any] = None)
selector
: CSS selector of the element to clickcontext
: Optional context object (currently unused)get_page_screenshots(full_page: bool = False, selector: Optional[str] = None, context: Optional[Any] = None)
full_page
: Capture entire page screenshotselector
: Optional element to screenshotcontext
: Optional context object (currently unused)get_page_links(filter_pattern: Optional[str] = None, context: Optional[Any] = None)
filter_pattern
: Optional text pattern to filter linkscontext
: Optional context object (currently unused)input_text(selector: str, text: str, context: Optional[Any] = None)
selector
: CSS selector of input elementtext
: Text to inputcontext
: Optional context object (currently unused)create_new_tab(url: Optional[str] = None, context: Optional[Any] = None)
url
: Optional URL to navigate to in the new tabcontext
: Optional context object (currently unused)switch_tab(tab_id: str, context: Optional[Any] = None)
tab_id
: ID of the tab to switch tocontext
: Optional context object (currently unused)list_tabs(context: Optional[Any] = None)
context
: Optional context object (currently unused)close_tab(tab_id: Optional[str] = None, context: Optional[Any] = None)
tab_id
: Optional ID of the tab to close (defaults to current tab)context
: Optional context object (currently unused)refresh_page(context: Optional[Any] = None)
context
: Optional context object (currently unused)get_page_info(context: Optional[Any] = None)
context
: Optional context object (currently unused)scroll_page(direction: str = "down", amount: str = "page", context: Optional[Any] = None)
direction
: Direction to scroll ('up', 'down', 'left', 'right')amount
: Amount to scroll ('page', 'half', or a number)context
: Optional context object (currently unused)wait_for_navigation(timeout_ms: int = 10000, context: Optional[Any] = None)
timeout_ms
: Maximum time to wait in millisecondscontext
: Optional context object (currently unused)execute_javascript(script: str, context: Optional[Any] = None)
script
: JavaScript code to executecontext
: Optional context object (currently unused)Contributions are welcome! Please feel free to submit a Pull Request.
# Clone the repository git clone https://github.com/random-robbie/mcp-web-browser.git # Create virtual environment python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` # Install dependencies pip install -e .[dev]
MIT License
For issues and questions, please open an issue on GitHub.