mcp-selenium -ai
Selenium MCP server with JAVA MAVEN TESTNG, it executes browser automation tasks by converting natural language test steps into Selenium WebDriver commands using a LLM.
claude mcp add --transport stdio jyotiprakashb83-mcp-selenium-server-ai mvn exec:java -Dexec.mainClass="McpServer"
How to use
This MCP server implements a Java-based Selenium Master Control Program (MCP) with AI. It accepts natural language test steps, forwards them to a Language Model (LLM) either locally via Ollama or to a remote LLM endpoint, and returns a structured sequence of Selenium commands. The server then executes those commands against a browser via WebDriver (ChromeDriver or GeckoDriver) to perform automated web tasks. A TestNG-based client is included to send prompts and log results. To use it, configure an LLM source (local Ollama or remote API), place the desired steps in your client prompt, and expect a JSON array of operations that map to actions like starting a browser, navigating, clicking elements, entering text, taking screenshots, and closing the session. The server supports a configurable set of Selenium operations defined in selenium_operations.properties and will execute each command in order while reporting errors per-command when they occur.
How to install
Prerequisites:
- Java 17 or later
- Maven 3.6.0 or later
- WebDriver (ChromeDriver or GeckoDriver) matching your browser version and added to PATH
- Maven dependencies for TestNG and Selenium (provided by pom.xml)
- Optional: Ollama (for local LLM) running at http://localhost:11434 or a remote LLM endpoint with API key
Step-by-step:
-
Clone the repository git clone <repository-url> cd selenium-mcp
-
Install dependencies and build mvn install
-
Configure the server
- Edit config.properties in the project root to set: server.port=8080 browser=chrome llm.endpoint=http://localhost:11434 llm.model=llama3 llm.apiKey=
-
Run the MCP server mvn exec:java -Dexec.mainClass="McpServer" The server will start on http://localhost:8080 by default
-
Run the Selenium Test Client mvn test Or run SeleniumTestClient.java in an IDE with TestNG support to send test prompts and observe results
Additional notes
Tips and notes:
- The LLM must respond with a structured JSON array of commands that align with selenium_operations.properties. If the model outputs unexpected formats, adjust the prompt or parsing logic in McpServer.java.
- Ensure ChromeDriver/GeckoDriver is compatible with the installed browser version and accessible on PATH.
- The take_screenshot command returns base64 data to avoid server-side file dependencies.
- If using a remote LLM, securely provide API keys via llm.apiKey in config.properties.
- You can extend operations by updating selenium_operations.properties and the executeCommand implementation in McpServer.java.
- The sample workflow assumes a TestNG-based client is available to trigger the server and log results in test-output/.
- For local Ollama usage, start Ollama with ollama serve and pull the model (e.g., llama3) before running the server.