A Model Context Protocol server for Selenium web automation
Project description
Selenium MCP Server
A Model Context Protocol (MCP) server that provides web automation capabilities through Selenium WebDriver. This server allows AI assistants to interact with web pages by providing tools for navigation, element interaction, taking screenshots, and more.
- 1. Features
- 2. Available Tools
- 3. Installation
- 4. Usage
- 5. Examples
- 6. Logging
- 7. Troubleshooting
- 8. Architecture
- 9. Contributing
- 10. Support
- 11. Reference
1. Features
- Web Navigation: Navigate to URLs and control browser navigation
- Element Interaction: Click buttons, fill forms, and interact with page elements
- Screenshots: Capture screenshots of web pages
- Page Analysis: Get page content, titles, and element information
- Form Handling: Submit forms and interact with input fields
- Waiting Strategies: Wait for elements to load or become clickable
- Chrome Browser Control: Connect to existing Chrome instances or start new ones
2. Available Tools
The MCP server provides the following tools:
navigate(url, timeout)- Navigate to a specified URLtake_screenshot()- Capture a screenshot of the current pagecheck_page_ready(wait_seconds)- Check if the page is ready and optionally waitget_page_title()- Get the current page titleget_current_url()- Get the current page URLclick_element(selector, by_type, wait_time)- Click on page elementsfill_input(selector, text, by_type, wait_time, clear_first)- Fill input fieldssubmit_form(selector, by_type, wait_time)- Submit formsget_element_text(selector, by_type, wait_time)- Get text content of elementsget_page_content()- Get the full page HTML contentscroll_page(direction, amount)- Scroll the pagewait_for_element(selector, by_type, timeout, condition)- Wait for elementsget_element_attribute(selector, attribute, by_type, wait_time)- Get element attributescheck_element_exists(selector, by_type, wait_time)- Check if elements exist
3. Installation
3.1. Prerequisites
- Python 3.10 or higher
- Chrome browser installed
- uv package manager
3.2. Setup
- Clone this repository:
git clone <repository-url>
cd selenium-mcp-server
- Install dependencies using uv:
uv sync
3.3. Chrome Setup
The MCP server can work with Chrome in two ways:
- Connect to existing Chrome instance (recommended): Start Chrome with debugging enabled:
google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug
- Auto-start Chrome: The server can automatically start Chrome if no instance is found.
4. Usage
4.1. Using MPC Inspector for testing
4.1.1. Start Inspector server
Run the MCP server with default settings:
uv run mcp dev main.py
# or
make inspector
Or with custom options:
uv run mcp dev main.py --port 9222 --user_data_dir /tmp/chrome-debug --verbose
4.1.2. Access inspector to test
check log:
tailf /tmp/selenium-mcp.log
4.1.3. Command Line Options
--port: Chrome remote debugging port (default: 9222)--user_data_dir: Chrome user data directory (default: auto-generated in /tmp)-v, --verbose: Increase verbosity (use multiple times for more details)
4.2. Using with MCP Clients
The server communicates via stdio and follows the Model Context Protocol specification. You can integrate it with MCP-compatible AI assistants or clients.
4.2.1. Configuration Example
For Claude Desktop, add to your claude_desktop_config.json:
{
"mcpServers": {
"selenium": {
"command": "python",
"args": ["/path/to/selenium-mcp-server/main.py"],
"env": {}
}
}
}
For Vscode copilot: .vscode/mcp.json
{
"servers": {
"selenium": {
"command": "/home/xuananh/repo/selenium-mcp-server/.venv/bin/python",
"args": [
"/home/xuananh/repo/mcp-server/src/selenium/main.py",
"--user_data_dir=/home/xuananh/.config/google-chrome-selenium-mcp",
"--port=9225"
]
}
}
}
Debug
In Vscode copilot, if open .vscode/mcp.json file, you can see mcp server status
Or you can open command: Developer: Show logs.. > MCP: selenium to see its log
And also check log file:
tailf /tmp/selenium-mcp.log
5. Examples
5.1. Basic Web Automation
-
Navigate to a website:
- Tool:
navigate - URL:
https://example.com
- Tool:
-
Take a screenshot:
- Tool:
take_screenshot - Result: Screenshot saved to
~/selenium-mcp/screenshot/
- Tool:
-
Fill a form:
- Tool:
fill_input - Selector:
#email - Text:
user@example.com
- Tool:
-
Click a button:
- Tool:
click_element - Selector:
button[type="submit"]
- Tool:
5.2. Advanced Usage
- Wait for dynamic content: Use
wait_for_elementto wait for elements to load - Get page information: Use
get_page_title,get_current_url,get_page_content - Element inspection: Use
get_element_text,get_element_attribute,check_element_exists
6. Logging
The server logs all operations to /tmp/selenium-mcp.log with rotation. Use the -v flag to increase console verbosity:
-v: INFO level logging-vv: DEBUG level logging
7. Troubleshooting
7.1. Common Issues
- Chrome not starting: Ensure Chrome is installed and accessible from PATH
- Port conflicts: Use a different port with
--portoption - Permission errors: Ensure the user data directory is writable
- Element not found: Increase wait times or use more specific selectors
7.2. Debug Mode
Run with maximum verbosity to see detailed logs:
python main.py -vv
8. Architecture
- FastMCP: Uses the FastMCP framework for MCP protocol implementation
- Selenium WebDriver: Chrome WebDriver for browser automation
- Synchronous Design: All operations are synchronous for reliability
- Chrome DevTools Protocol: Connects to Chrome via remote debugging protocol
9. Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
10. Support
For issues and questions:
- Create an issue in the repository
- Check the logs at
/tmp/selenium-mcp.log - Use verbose logging for debugging
11. Reference
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_server_selenium-0.1.0.tar.gz.
File metadata
- Download URL: mcp_server_selenium-0.1.0.tar.gz
- Upload date:
- Size: 353.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9f4e41bff15c43179e973289201a8ab70dba8f0d98ea7541416bc7006af31fd
|
|
| MD5 |
6dacaa88ea72c6e3e6ec94b4e775cd89
|
|
| BLAKE2b-256 |
76e6eb6e540b687f519d4e55bc96ef2870ef4f6ce883bae47c372163cc5ccda7
|
File details
Details for the file mcp_server_selenium-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_server_selenium-0.1.0-py3-none-any.whl
- Upload date:
- Size: 359.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
625c53bbc1c1b2a9754934733e4234aec233e6e06c9a3e946cc6c3cecdb51c71
|
|
| MD5 |
54a07b90a06b3bfcd5fecd7e30f64495
|
|
| BLAKE2b-256 |
1d341f02c682a96a993045396c58bc22869efac4a573c6aaeb618201f6bda9e4
|