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. - 2. Features - 3. Available Tools - 3.1. Navigation and Page Management - 3.2. Element Interaction - 3.3. Element Styling - 3
Add this skill
npx mdskills install PhungXuanAnh/selenium-mcp-serverComprehensive web automation server with extensive tools, clear setup, and good documentation
1Selenium MCP Server2---34A 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.56## 1.1. Quick Start78### 1.1.1. Using Installed Package (Recommended)9```bash10# Install11pip install mcp-server-selenium1213# Run14python -m mcp_server_selenium --port 9222 --user_data_dir /tmp/chrome-debug15```1617### 1.1.2. Using Source Code (Development)18```bash19# Clone and setup20git clone https://github.com/PhungXuanAnh/selenium-mcp-server.git21cd selenium-mcp-server22uv sync2324# Run25PYTHONPATH=src python -m mcp_server_selenium --port 9222 --user_data_dir /tmp/chrome-debug26```2728---2930- [2. Features](#2-features)31- [3. Available Tools](#3-available-tools)32 - [3.1. Navigation and Page Management](#31-navigation-and-page-management)33 - [3.2. Element Interaction](#32-element-interaction)34 - [3.3. Element Styling](#33-element-styling)35 - [3.4. JavaScript Execution](#34-javascript-execution)36 - [3.5. Browser Logs](#35-browser-logs)37 - [3.6. Local Storage Management](#36-local-storage-management)38- [4. Installation](#4-installation)39 - [4.1. Prerequisites](#41-prerequisites)40 - [4.2. Installation Options](#42-installation-options)41 - [4.2.1. Option A: Install as Python Package (Recommended)](#421-option-a-install-as-python-package-recommended)42 - [4.2.2. Option B: Run from Source Code](#422-option-b-run-from-source-code)43 - [4.3. Chrome Setup](#43-chrome-setup)44- [5. Usage](#5-usage)45 - [5.1. Running the MCP Server](#51-running-the-mcp-server)46 - [5.1.1. Option A: From Installed Package](#511-option-a-from-installed-package)47 - [5.1.2. Option B: From Source Code](#512-option-b-from-source-code)48 - [5.2. Using MCP Inspector for Testing](#52-using-mcp-inspector-for-testing)49 - [5.2.1. Start Inspector Server](#521-start-inspector-server)50 - [5.2.2. Access Inspector Interface](#522-access-inspector-interface)51 - [5.2.3. Command Line Options](#523-command-line-options)52 - [5.3. Using with MCP Clients](#53-using-with-mcp-clients)53 - [5.3.1. Configuration Examples](#531-configuration-examples)54 - [5.3.2. Debug](#532-debug)55- [6. Examples](#6-examples)56 - [6.1. Basic Web Automation](#61-basic-web-automation)57 - [6.2. Advanced Usage](#62-advanced-usage)58 - [6.2.1. JavaScript Examples](#621-javascript-examples)59- [7. Logging](#7-logging)60- [8. Troubleshooting](#8-troubleshooting)61 - [8.1. Common Issues](#81-common-issues)62 - [8.1.1. Installation-Related Issues](#811-installation-related-issues)63 - [8.1.2. Runtime Issues](#812-runtime-issues)64 - [8.1.3. Configuration Issues](#813-configuration-issues)65- [9. Architecture](#9-architecture)66- [10. Contributing](#10-contributing)67- [11. Support](#11-support)68- [12. Documentation](#12-documentation)69- [13. Reference](#13-reference)707172# 2. Features7374- **Web Navigation**: Navigate to URLs with timeout control and page readiness checking75- **Element Discovery & Interaction**: Find elements by multiple criteria (text, class, ID, attributes, XPath) and interact with them through clicking and input value setting76- **Advanced Element Querying**: Get single elements, multiple elements with pagination, and direct child nodes with comprehensive filtering options77- **Screenshots**: Capture full-page screenshots of the current browser window78- **Element Styling**: Retrieve CSS styles and computed style information for any element79- **JavaScript Execution**: Execute custom JavaScript code in browser console with optional console output capture80- **Browser Logging**: Access console logs (with level filtering) and network request logs (with URL filtering and error filtering)81- **Local Storage Management**: Complete CRUD operations for browser local storage (add, read, update, delete)82- **iFrame Support**: Work with elements inside iframes using iframe ID or name targeting83- **XPath Support**: Use XPath expressions for precise element targeting84- **Chrome Browser Control**: Connect to existing Chrome instances or automatically start new ones8586# 3. Available Tools8788The MCP server provides the following tools:8990## 3.1. Navigation and Page Management91- `navigate(url, timeout)` - Navigate to a specified URL with Chrome browser92- `check_page_ready(wait_seconds)` - Check if the current page is fully loaded with optional wait93- `take_screenshot()` - Take a screenshot of the current browser window9495## 3.2. Element Interaction96- `get_an_element(text, class_name, id, attributes, element_type, in_iframe_id, in_iframe_name, return_html, xpath)` - Get an element identified by various criteria97- `get_elements(text, class_name, id, attributes, element_type, in_iframe_id, in_iframe_name, page, page_size, return_html, xpath)` - Get multiple elements with pagination support98- `get_direct_children(text, class_name, id, attributes, element_type, in_iframe_id, in_iframe_name, return_html, xpath, page, page_size)` - Get all direct child nodes of an element with pagination99- `click_to_element(text, class_name, id, attributes, element_type, in_iframe_id, in_iframe_name, element_index, xpath)` - Click on an element identified by various criteria100- `set_value_to_input_element(text, class_name, id, attributes, element_type, input_value, in_iframe_id, in_iframe_name, xpath)` - Set a value to an input element101102## 3.3. Element Styling103- `get_style_an_element(text, class_name, id, attributes, element_type, in_iframe_id, in_iframe_name, return_html, xpath, all_styles, computed_style)` - Get style information for an element104105## 3.4. JavaScript Execution106- `run_javascript_in_console(javascript_code)` - Execute JavaScript code in the browser console107- `run_javascript_and_get_console_output(javascript_code)` - Execute JavaScript code and capture both return value and console output108109## 3.5. Browser Logs110- `get_console_logs(log_level)` - Retrieve console logs from the browser with optional filtering by log level111- `get_network_logs(filter_url_by_text, only_errors_log)` - Retrieve network request logs from the browser with optional filtering112113## 3.6. Local Storage Management114- `local_storage_add(key, string_value, object_value, create_empty_string, create_empty_object)` - Add or update a key-value pair in browser's local storage115- `local_storage_read(key)` - Read a value from browser's local storage by key116- `local_storage_read_all()` - Read all key-value pairs from browser's local storage117- `local_storage_remove(key)` - Remove a key-value pair from browser's local storage118- `local_storage_remove_all()` - Remove all key-value pairs from browser's local storage119120# 4. Installation121122## 4.1. Prerequisites123124- Python 3.10 or higher125- Chrome browser installed126127## 4.2. Installation Options128129You can use this MCP server in two ways:130131### 4.2.1. Option A: Install as Python Package (Recommended)132133Install directly from PyPI:134```bash135pip install mcp-server-selenium136```137138Or using uv:139```bash140uv add mcp-server-selenium141```142143### 4.2.2. Option B: Run from Source Code1441451. Clone this repository:146```bash147git clone https://github.com/PhungXuanAnh/selenium-mcp-server.git148cd selenium-mcp-server149```1501512. Install dependencies using uv:152```bash153uv sync154```155156Or using pip with virtual environment:157```bash158python -m venv .venv159source .venv/bin/activate # On Windows: .venv\Scripts\activate160pip install -e .161```162163## 4.3. Chrome Setup164165The MCP server can work with Chrome in two ways:1661671. **Connect to existing Chrome instance** (recommended): Start Chrome with debugging enabled:168```bash169google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug170```1711722. **Auto-start Chrome**: The server can automatically start Chrome if no instance is found.173174# 5. Usage175176## 5.1. Running the MCP Server177178### 5.1.1. Option A: From Installed Package179180After installing via pip/uv, you can run the server directly:181182```bash183# Basic usage with default settings184python -m mcp_server_selenium185186# With custom Chrome debugging port and user data directory187python -m mcp_server_selenium --port 9222 --user_data_dir /tmp/chrome-debug188189# With verbose logging190python -m mcp_server_selenium --port 9222 --user_data_dir /tmp/chrome-debug -v191192# Using the installed command (if available)193selenium-mcp-server --port 9222 --user_data_dir /tmp/chrome-debug -v194```195196### 5.1.2. Option B: From Source Code197198When running from source, ensure the Python path includes the src directory:199200```bash201# Navigate to the project directory202cd /path/to/selenium-mcp-server203204# Activate virtual environment (if using one)205source .venv/bin/activate206207# Run with proper Python path208PYTHONPATH=src python -m mcp_server_selenium --port 9222 --user_data_dir /tmp/chrome-debug -v209210# Or using uv (recommended for development)211uv run python -m mcp_server_selenium --port 9222 --user_data_dir /tmp/chrome-debug -v212```213214## 5.2. Using MCP Inspector for Testing215216### 5.2.1. Start Inspector Server217218For development and testing, you can use the MCP inspector:219220**From Source Code:**221```bash222# Using uv (recommended)223uv run mcp dev src/mcp_server_selenium/__main__.py224225# Or with make command226make inspector227228# With custom options229uv run mcp dev src/mcp_server_selenium/__main__.py --port 9222 --user_data_dir /tmp/chrome-debug --verbose230```231232**From Installed Package:**233```bash234# Create a wrapper script or use directly235mcp dev python -m mcp_server_selenium236```237238### 5.2.2. Access Inspector Interface239240Open your browser and navigate to: http://127.0.0.1:6274/#tools241242243Check logs:244```shell245tailf /tmp/selenium-mcp.log246```247248### 5.2.3. Command Line Options249250- `--port`: Chrome remote debugging port (default: 9222)251- `--user_data_dir`: Chrome user data directory (default: auto-generated in /tmp)252- `-v, --verbose`: Increase verbosity (use multiple times for more details)253254## 5.3. Using with MCP Clients255256The server communicates via stdio and follows the Model Context Protocol specification. You can integrate it with MCP-compatible AI assistants or clients.257258### 5.3.1. Configuration Examples259260**For Claude Desktop** (`claude_desktop_config.json`):261262Using installed package:263```json264{265 "mcpServers": {266 "selenium": {267 "command": "python",268 "args": [269 "-m", "mcp_server_selenium",270 "--port", "9222",271 "--user_data_dir", "/tmp/chrome-debug-claude"272 ],273 "env": {}274 }275 }276}277```278279**For VS Code Copilot** (`.vscode/mcp.json`):280281Using installed package:282```json283{284 "servers": {285 "selenium-installed": {286 "command": "python",287 "args": [288 "-m", "mcp_server_selenium",289 "--user_data_dir=/home/user/.config/google-chrome-selenium-mcp",290 "--port=9225"291 ]292 }293 }294}295```296297Using source code directly:298```json299{300 "servers": {301 "selenium-source": {302 "command": "/path/to/selenium-mcp-server/.venv/bin/python",303 "args": [304 "-m", "mcp_server_selenium",305 "--user_data_dir=/home/user/.config/google-chrome-selenium-mcp-source",306 "--port=9226"307 ],308 "env": {309 "PYTHONPATH": "/path/to/selenium-mcp-server/src"310 }311 }312 }313}314```315316Alternative source code configuration using full path:317```json318{319 "servers": {320 "selenium-source-alt": {321 "command": "/path/to/selenium-mcp-server/.venv/bin/python",322 "args": [323 "/path/to/selenium-mcp-server/src/mcp_server_selenium/__main__.py",324 "--user_data_dir=/home/user/.config/google-chrome-selenium-mcp-alt",325 "--port=9227"326 ]327 }328 }329}330```331332### 5.3.2. Debug333334**VS Code Copilot MCP Status:**335If you open the `.vscode/mcp.json` file, you can see the MCP server status at the bottom of VS Code.336337338339**View MCP Logs:**340- In VS Code: Open Command Palette → "Developer: Show Logs..." → "MCP: selenium"341- Check log file: `tail -f /tmp/selenium-mcp.log`342343# 6. Examples344345## 6.1. Basic Web Automation3463471. **Navigate to a website**:348 - Tool: `navigate`349 - URL: `https://example.com`3503512. **Take a screenshot**:352 - Tool: `take_screenshot`353 - Result: Screenshot saved to `~/selenium-mcp/screenshot/`3543553. **Fill a form**:356 - Tool: `fill_input`357 - Selector: `#email`358 - Text: `user@example.com`3593604. **Click a button**:361 - Tool: `click_element`362 - Selector: `button[type="submit"]`3633645. **Execute JavaScript**:365 - Tool: `run_javascript_in_console`366 - Code: `return document.title;`367 - Result: Returns the page title3683696. **JavaScript with console output**:370 - Tool: `run_javascript_and_get_console_output`371 - Code: `console.log('Hello from browser'); return window.location.href;`372 - Result: Shows both console output and return value373374## 6.2. Advanced Usage375376- **Wait for dynamic content**: Use `wait_for_element` to wait for elements to load377- **Get page information**: Use `get_page_title`, `get_current_url`, `get_page_content`378- **Element inspection**: Use `get_element_text`, `get_element_attribute`, `check_element_exists`379- **JavaScript automation**: Use `run_javascript_in_console` for complex DOM manipulation and data extraction380- **JavaScript debugging**: Use `run_javascript_and_get_console_output` to capture console logs for debugging381382### 6.2.1. JavaScript Examples383384**Extract page data**:385```javascript386// Tool: run_javascript_in_console387var links = Array.from(document.querySelectorAll('a')).slice(0, 5).map(a => ({388 text: a.textContent.trim(),389 href: a.href390}));391return links;392```393394**Page performance monitoring**:395```javascript396// Tool: run_javascript_and_get_console_output397console.time('Page Analysis');398var stats = {399 title: document.title,400 links: document.querySelectorAll('a').length,401 images: document.querySelectorAll('img').length,402 scripts: document.querySelectorAll('script').length403};404console.timeEnd('Page Analysis');405console.log('Page stats:', stats);406return stats;407```408409**Form automation**:410```javascript411// Tool: run_javascript_in_console412document.querySelector('#username').value = 'testuser';413document.querySelector('#password').value = 'password123';414document.querySelector('#login-form').submit();415return 'Form submitted successfully';416```417418# 7. Logging419420The server logs all operations to `/tmp/selenium-mcp.log` with rotation. Use the `-v` flag to increase console verbosity:421422- `-v`: INFO level logging423- `-vv`: DEBUG level logging424425# 8. Troubleshooting426427## 8.1. Common Issues428429### 8.1.1. Installation-Related Issues430431**Package not found (installed package):**432```bash433# Verify installation434pip list | grep mcp-server-selenium435# or436python -c "import mcp_server_selenium; print('OK')"437```438439**Module not found (source code):**440```bash441# Ensure PYTHONPATH is set correctly442export PYTHONPATH=/path/to/selenium-mcp-server/src443# or run from project root with:444PYTHONPATH=src python -m mcp_server_selenium445```446447### 8.1.2. Runtime Issues4484491. **Chrome not starting**: Ensure Chrome is installed and accessible from PATH4502. **Port conflicts**: Use a different port with `--port` option4513. **Permission errors**: Ensure the user data directory is writable4524. **Element not found**: Increase wait times or use more specific selectors4535. **JavaScript execution errors**: Check browser console for syntax errors or security restrictions4546. **Console output not captured**: Ensure the JavaScript code runs successfully before checking console logs455456### 8.1.3. Configuration Issues457458**MCP Client Connection Problems:**459- Verify the command path is correct (use `which python` to find Python executable)460- For source code: Ensure PYTHONPATH environment variable is set461- For installed package: Ensure the package is installed in the same Python environment as the MCP client462- Check MCP client logs for detailed error messages463464# 9. Architecture465466- **FastMCP**: Uses the FastMCP framework for MCP protocol implementation467- **Selenium WebDriver**: Chrome WebDriver for browser automation468- **Synchronous Design**: All operations are synchronous for reliability469- **Chrome DevTools Protocol**: Connects to Chrome via remote debugging protocol470471# 10. Contributing4724731. Fork the repository4742. Create a feature branch4753. Make your changes4764. Add tests if applicable4775. Submit a pull request478479# 11. Support480481For issues and questions:482- Create an issue in the repository483- Check the logs at `/tmp/selenium-mcp.log`484- Use verbose logging for debugging485486# 12. Documentation487488For detailed documentation on specific features:489- [JavaScript Console Tools](docs/javascript_console_tools.md) - Comprehensive guide for JavaScript execution tools490- [Examples](examples/javascript_console_examples.py) - JavaScript execution examples and use cases491492# 13. Reference493494- https://github.com/modelcontextprotocol/python-sdk495- https://github.com/modelcontextprotocol/servers496
Full transparency — inspect the skill content before installing.