Selenium MCP Server
Servidor Selenium MCP
insignia de herrería
Un servidor MCP que usa Selenium para interactuar con una instancia de WebDriver. Creado con la plantilla MCP-Server-Starter .
Descripción general
Este servidor permite que los agentes de IA controlen una sesión de navegador web a través de Selenium WebDriver, lo que habilita tareas como raspado web, pruebas automatizadas y llenado de formularios a través del Protocolo de contexto de modelo.
Related MCP server: mcp-selenium-python
Componentes principales
Servidor MCP : expone las acciones de Selenium WebDriver como herramientas MCP.
Selenium WebDriver : interactúa con el navegador.
Clientes MCP : hosts de IA (como Cursor, Claude Desktop) que pueden utilizar las herramientas expuestas.
Prerrequisitos
Node.js (v18 o posterior)
npm (v7 o posterior)
Un ejecutable WebDriver (por ejemplo, ChromeDriver, GeckoDriver) instalado y disponible en la RUTA de su sistema.
Un navegador web compatible (por ejemplo, Chrome, Firefox).
Empezando
Clonar el repositorio:
git clone <your-repo-url> selenium-mcp-server cd selenium-mcp-serverInstalar dependencias:
npm installConfigurar WebDriver:
Asegúrese de que su WebDriver (por ejemplo,
chromedriver) esté instalado y en su RUTA.Modifique
src/seleniumService.ts(creará este archivo) si es necesario para especificar las opciones del navegador o las rutas de WebDriver.
Construir el servidor:
npm run buildEjecutar el servidor:
npm startAlternativamente, intégrelo con un host MCP como Cursor o Claude Desktop (consulte las secciones de Integración a continuación).
Herramientas
Este servidor proporcionará herramientas como:
selenium_navigate: navega el navegador a una URL específica.selenium_findElement: encuentra un elemento en la página usando un selector CSS.selenium_click: hace clic en un elemento.selenium_sendKeys: envía pulsaciones de teclas a un elemento.selenium_getPageSource: recupera el código HTML de la página actual.(Agregue más herramientas según sea necesario)
Implementación de TypeScript
El servidor utiliza las bibliotecas @modelcontextprotocol/sdk y selenium-webdriver .
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();Desarrollo
Construir:
npm run buildEjecutar:
npm start(ejecutanode build/index.js)Pelusa:
npm run lintFormato:
npm run format
Depuración
Utilice el Inspector MCP o las técnicas de depuración estándar de Node.js.
Integración con hosts MCP
(Conserve las secciones relevantes del README original para Cursor, Claude Desktop, Smithery, etc., actualizando rutas y comandos según sea necesario)
Integración del cursor
Construye tu servidor :
npm run buildEn el cursor:
Settings>Features>MCP: agregar un nuevo servidor MCP.Registra tu servidor :
Seleccione
stdiocomo tipo de transporte.Nombre:
Selenium Server(o similar).Comando:
node /path/to/selenium-mcp-server/build/index.js.
Ahorrar .
Integración de escritorio de Claude
Construye tu servidor :
npm run buildModificar
claude_desktop_config.json:{ "mcpServers": { "selenium-mcp-server": { "command": "node", "args": [ "/path/to/selenium-mcp-server/build/index.js" ] } } }Reinicie Claude Desktop .
Mejores prácticas
Utilice TypeScript y Zod para la seguridad y validación de tipos.
Mantenga las herramientas modulares (por ejemplo, un archivo por herramienta en
src/tools/).Maneje los errores de WebDriver con elegancia (por ejemplo, elemento no encontrado, problemas de navegación).
Asegúrese de que WebDriver se apague correctamente (por ejemplo,
driver.quit()al salir del servidor).Siga las mejores prácticas de MCP para esquemas, manejo de errores y tipos de contenido.
Más información
Créditos
Basado en la plantilla creada por Seth Rose :
Sitio web : https://www.sethrose.dev
𝕏 (Twitter) : https://x.com/TheSethRose
🦋 (Cielo azul) : https://bsky.app/profile/sethrose.dev
Available Tools
6 toolsbrowser_clickC
Perform click on a web page
Inputs: element (required), ref (required).
browser_snapshotB
Capture accessibility snapshot of the current page
Inputs: no named parameters.
browser_take_screenshotC
Take a screenshot of the current page
Inputs: filename, raw.
browser_typeC
Type text into editable element
Inputs: element (required), ref (required), text (required), submit.
browser_wait_forC
Wait for text to appear or disappear or a specified time to pass
Inputs: text, textGone, time.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose with no overlap: clicking, navigating, capturing snapshots, taking screenshots, typing text, and waiting for conditions. The descriptions make it easy to differentiate between them, eliminating any ambiguity in tool selection.
All tools follow a consistent 'browser_' prefix with descriptive action names (e.g., click, navigate, snapshot). This uniform snake_case pattern makes the tool set predictable and easy to understand, enhancing usability for agents.
With 6 tools, the server is well-scoped for web automation tasks. Each tool serves a specific, essential function in the Selenium domain, avoiding bloat while covering core interactions like navigation, input, and monitoring.
The tool set covers key web automation actions (navigation, interaction, monitoring), but lacks some common operations like form submission, element selection, or handling alerts. However, agents can work around these gaps using existing tools, making it mostly complete for basic workflows.
Maintenance
Related MCP Connectors
Control a real browser from AI agents: navigate, click, type, screenshot, read the page.
Give AI agents a real cloud Chrome: open sessions, navigate, read pages, click, type and screenshot.
Let your AI agent operate any website through a real, logged-in browser session.
Browser sessions for agents: navigate, interact, read and screenshot. Pay in stablecoins.
Related MCP Servers
- AlicenseCqualityBmaintenanceEnables AI assistants to automate web browser interactions through Selenium WebDriver. Supports multi-browser automation, element interaction, navigation, and web testing capabilities.56218 npm6MIT
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to automate browser tasks (navigation, clicks, text input) via Selenium through the Model Context Protocol.1GPL 3.0
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to automate web tasks such as browsing, clicking, typing, and taking screenshots via the Model Context Protocol.1MIT
- AlicenseAqualityCmaintenanceEnables browser automation through the Model Context Protocol, allowing AI agents to control Chrome, Firefox, or Edge for tasks like navigation, clicking, typing, and screenshots.4177 npmMIT