chrome_mcp_server
An MCP server for controlling and automating Google Chrome browser operations using Puppeteer. It provides tools for navigation, element interaction, screenshots, and browser management.
README
Chrome MCP Server
A Model Context Protocol (MCP) server for controlling and automating Google Chrome browser operations using Puppeteer. This server provides tools for web automation, element interaction, and browser management.
Features
The Chrome MCP server provides the following tools:
- open_url: Navigate to a specific URL
- get_page_title: Get the current page title
- get_page_url: Get the current page URL
- click_element: Click on elements using CSS selectors or XPath
- type_text: Type text into input fields
- screenshot: Take screenshots of the current page
- scroll_page: Scroll the page in any direction
- wait_for_element: Wait for elements to appear on the page
- close_browser: Close the Chrome browser
Prerequisites
- Python 3.8+ installed on your system
- Google Chrome browser installed (recommended) or let Puppeteer download Chromium automatically
Installation
-
Clone or download this repository
-
Navigate to the project directory:
cd mcp_chrome -
Create a virtual environment (recommended):
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt
Configuration
Environment Variables
You can configure the Chrome MCP server using environment variables:
CHROME_HEADLESS: Set totrueto run Chrome in headless mode (default:false)CHROME_EXECUTABLE_PATH: Specify a custom path to your Chrome executable (optional)CHROME_SCREENSHOT_DIR: Specify a custom directory for saving screenshots (optional)
Examples:
# Run in headless mode
export CHROME_HEADLESS=true
# Use custom Chrome path
export CHROME_EXECUTABLE_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
# Use custom screenshot directory
export CHROME_SCREENSHOT_DIR="/Users/username/Pictures/screenshots"
Usage
Running the Server
- Activate your virtual environment (if using one)
- Run the server:
python chrome_mcp_server.py
The server will start and listen for MCP client connections via stdio.
Integration with MCP Clients
This server can be integrated with any MCP-compatible client. Configure your client to use the Chrome MCP server by specifying the path to chrome_mcp_server.py.
Example MCP Client Configuration
{
"mcpServers": {
"chrome": {
"command": "python",
"args": ["/path/to/chrome_mcp_server.py"],
"env": {
"CHROME_HEADLESS": "false"
}
}
}
}
Cursor Integration
To enable the Chrome MCP server in Cursor, add the following configuration to ~/.cursor/mcp.json:
Tool Examples
Basic Navigation
# Open a website
await client.call_tool("open_url", {"url": "https://example.com"})
# Get page information
title = await client.call_tool("get_page_title", {})
current_url = await client.call_tool("get_page_url", {})
Element Interaction
# Click on a button
await client.call_tool("click_element", {
"selector": "#submit-button",
"selector_type": "css"
})
# Type text into a search box
await client.call_tool("type_text", {
"selector": "input[name='q']",
"text": "search query",
"clear_first": True
})
Page Manipulation
# Take a screenshot
await client.call_tool("screenshot", {"filename": "page.png"})
# Scroll down the page
await client.call_tool("scroll_page", {
"direction": "down",
"pixels": 1000
})
# Wait for an element to appear
await client.call_tool("wait_for_element", {
"selector": ".loading-spinner",
"timeout": 30
})
Browser Management
Using Local Chrome vs Downloaded Chromium
The server automatically detects and uses your locally installed Google Chrome browser. If Chrome is not found, it falls back to downloading and using Chromium.
To use your local Chrome:
- The server automatically searches for Chrome in common installation paths
- No additional configuration needed
To specify a custom Chrome path:
export CHROME_EXECUTABLE_PATH="/path/to/your/chrome"
To force using downloaded Chromium:
- Simply don't install Chrome, or remove the Chrome executable from the detected paths
Headless Mode
For server environments or automated testing, you can run Chrome in headless mode:
export CHROME_HEADLESS=true
python chrome_mcp_server.py
Closing the Browser
Always close the browser when you're done:
await client.call_tool("close_browser", {})
Error Handling
The server includes comprehensive error handling:
- WebDriver initialization errors
- Element not found errors
- Timeout errors
- General WebDriver exceptions
All errors are returned as text content with descriptive error messages.
Security Considerations
- The server runs Chromium with reduced security options for automation purposes
- Be cautious when automating websites that contain sensitive information
- Consider using headless mode in production environments
- The server automatically closes the browser on exit to prevent resource leaks
- Puppeteer automatically downloads and manages the appropriate Chromium version
Troubleshooting
Common Issues
- Chromium download failed: Ensure you have internet access for the initial Chromium download
- Permission denied: Make sure you have write permissions in the current directory for screenshots
- Element not found: Verify your CSS selectors or XPath expressions are correct
- Browser crashes: Check if Chrome/Chromium is already running and close other instances
- First run delay: The first run may take longer as Puppeteer downloads Chromium
Screenshot Issues
"Read-only file system" error: This happens when the current directory doesn't have write permissions. Solutions:
-
Use custom screenshot directory:
export CHROME_SCREENSHOT_DIR="/Users/username/Pictures/screenshots" -
The server automatically falls back to
/tmpdirectory if the current directory is read-only -
Check directory permissions:
ls -la /current/directory -
Use absolute paths in your screenshot calls:
await client.call_tool("screenshot", {"filename": "/Users/username/screenshot.png"})
"Browser closed unexpectedly" Error
This error commonly occurs on macOS due to security restrictions. Here are solutions:
Immediate fixes:
- Close all Chrome windows and try again
- Use headless mode:
export CHROME_HEADLESS=true - Check for running Chrome instances: The server will warn you if Chrome is already running
macOS-specific solutions:
- System Preferences > Security & Privacy: Check if Chrome is blocked
- Quit Chrome completely from Activity Monitor
- Restart Chrome and try again
Advanced troubleshooting:
- Custom Chrome path:
export CHROME_EXECUTABLE_PATH="/path/to/chrome" - Force headless mode in your MCP configuration
- Check Chrome's debugging output (the server now shows this by default)
Debug Mode
For debugging, you can run the server with verbose output:
python -u chrome_mcp_server.py
Contributing
Feel free to submit issues, feature requests, or pull requests to improve the Chrome MCP server.
License
This project is open source and available under the MIT License.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。