Allows AI agents to control web browser sessions via Selenium WebDriver, enabling web automation tasks like scraping, testing, and form filling through the Model Context Protocol.
smithery badge
An MCP server that uses Selenium to interact with a WebDriver instance. Built using the MCP-Server-Starter template.
This server allows AI agents to control a web browser session via Selenium WebDriver, enabling tasks like web scraping, automated testing, and form filling through the Model Context Protocol.
git clone selenium-mcp-server cd selenium-mcp-server
npm install
chromedriver
) is installed and in your PATH.src/seleniumService.ts
(you'll create this file) if needed to specify browser options or WebDriver paths.npm run build
Alternatively, integrate it with an MCP host like Cursor or Claude Desktop (see Integration sections below).npm start
This server will provide tools such as:
selenium_navigate
: Navigates the browser to a specific URL.selenium_findElement
: Finds an element on the page using a CSS selector.selenium_click
: Clicks an element.selenium_sendKeys
: Sends keystrokes to an element.selenium_getPageSource
: Retrieves the current page source HTML.The server uses the @modelcontextprotocol/sdk
and selenium-webdriver
libraries.
import { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { Builder, By, Key, until, WebDriver } from 'selenium-webdriver'; // Basic server setup (details in src/index.ts) const server = new Server({ name: "selenium-mcp-server", version: "0.1.0", capabilities: { tools: {}, // Enable tools capability } }); // Selenium WebDriver setup (details in src/seleniumService.ts) let driver: WebDriver; async function initializeWebDriver() { driver = await new Builder().forBrowser('chrome').build(); // Or 'firefox', etc. } // Example tool implementation (details in src/tools/) server.registerTool('selenium_navigate', { description: 'Navigates the browser to a specific URL.', inputSchema: { /* ... zod schema ... */ }, outputSchema: { /* ... zod schema ... */ }, handler: async (params) => { await driver.get(params.url); return { success: true }; } }); // Connect transport async function startServer() { await initializeWebDriver(); const transport = new StdioServerTransport(); await server.connect(transport); console.log("Selenium MCP Server connected via stdio."); // Graceful shutdown process.on('SIGINT', async () => { console.log("Shutting down WebDriver..."); if (driver) { await driver.quit(); } process.exit(0); }); } startServer();
npm run build
npm start
(executes node build/index.js
)npm run lint
npm run format
Use the MCP Inspector or standard Node.js debugging techniques.
(Keep relevant sections from the original README for Cursor, Claude Desktop, Smithery, etc., updating paths and commands as necessary)
npm run build
Settings
> Features
> MCP
: Add a new MCP server.stdio
as the transport type.Selenium Server
(or similar).node /path/to/selenium-mcp-server/build/index.js
.npm run build
claude_desktop_config.json
:
{ "mcpServers": { "selenium-mcp-server": { "command": "node", "args": [ "/path/to/selenium-mcp-server/build/index.js" ] } } }
src/tools/
).driver.quit()
on server exit).Based on the template created by Seth Rose:
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!