The MCP Web Browser Server provides headless web browsing capabilities through Model Context Protocol (MCP), using Playwright to enable browser interactions via a flexible API. It allows you to navigate websites, extract content, interact with web elements, and manage multiple browser tabs programmatically.
Install the required packages using pip:
# Install MCP and Playwright
pip install mcp playwright
# Install browser dependencies
playwright install
To use with Claude Desktop, add the following to your claude_desktop_config.json
:
{
"mcpServers": {
"web-browser": {
"command": "python",
"args": [
"/path/to/your/server.py"
]
}
}
}
Navigate to websites and extract content:
# Browse to a website
page_content = browse_to("https://example.com")
# Extract all text content from the page
text_content = extract_text_content()
# Extract text from a specific element
title_text = extract_text_content("h1.title")
Fill out forms and click buttons:
# Navigate to a login page
browse_to("https://example.com/login")
# Input text into form fields
input_text("#username", "your_username")
input_text("#password", "your_password")
# Click a login button
click_element("#login-button")
Capture screenshots of pages or specific elements:
# 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")
Retrieve and filter links from web pages:
# 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 and manage multiple browser tabs:
# 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)
Interact with page content and behavior:
# 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()
methodTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "web-browser" '{"command":"python","args":["/path/to/your/server.py"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"web-browser": {
"command": "python",
"args": [
"/path/to/your/server.py"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"web-browser": {
"command": "python",
"args": [
"/path/to/your/server.py"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect