Selenium MCP 服务器
铁匠徽章
一个使用 Selenium 与 WebDriver 实例交互的 MCP 服务器。使用MCP-Server-Starter模板构建。
概述
该服务器允许 AI 代理通过 Selenium WebDriver 控制 Web 浏览器会话,从而通过模型上下文协议实现 Web 抓取、自动化测试和表单填写等任务。
核心组件
MCP 服务器:将 Selenium WebDriver 操作作为 MCP 工具公开。
Selenium WebDriver :与浏览器交互。
MCP 客户端:可以利用公开工具的 AI 主机(如 Cursor、Claude Desktop)。
先决条件
Node.js(v18 或更高版本)
npm(v7 或更高版本)
已安装WebDriver 可执行文件(例如 ChromeDriver、GeckoDriver)并可在系统 PATH 中使用。
兼容的网络浏览器(例如 Chrome、Firefox)。
入门
克隆存储库:
git clone <your-repo-url> selenium-mcp-server cd selenium-mcp-server安装依赖项:
npm install配置WebDriver:
确保您的 WebDriver (例如
chromedriver
) 已安装并位于您的 PATH 中。如果需要指定浏览器选项或 WebDriver 路径,请修改
src/seleniumService.ts
(您将创建此文件)。
构建服务器:
npm run build运行服务器:
npm start或者,将其与 Cursor 或 Claude Desktop 等 MCP 主机集成(请参阅下面的集成部分)。
工具
该服务器将提供以下工具:
selenium_navigate
:将浏览器导航到特定的 URL。selenium_findElement
:使用 CSS 选择器在页面上查找元素。selenium_click
:点击一个元素。selenium_sendKeys
:向元素发送击键。selenium_getPageSource
:检索当前页面源 HTML。(根据需要添加更多工具)
TypeScript 实现
服务器使用@modelcontextprotocol/sdk
和selenium-webdriver
库。
发展
构建:
npm run build
运行:
npm start
(执行node build/index.js
)Lint:
npm run lint
格式:
npm run format
调试
使用 MCP Inspector 或标准 Node.js 调试技术。
与 MCP 主机集成
(保留原始 README 中有关 Cursor、Claude Desktop、Smithery 等的相关部分,并根据需要更新路径和命令)
光标集成
构建你的服务器:
npm run build
在光标中:
Settings
>Features
>MCP
:添加新的 MCP 服务器。注册您的服务器:
选择
stdio
作为传输类型。名称:
Selenium Server
(或类似名称)。命令:
node /path/to/selenium-mcp-server/build/index.js
。
节省。
Claude 桌面集成
构建你的服务器:
npm run build
修改
claude_desktop_config.json
:{ "mcpServers": { "selenium-mcp-server": { "command": "node", "args": [ "/path/to/selenium-mcp-server/build/index.js" ] } } }重新启动 Claude Desktop 。
最佳实践
使用 TypeScript 和 Zod 进行类型安全和验证。
保持工具模块化(例如,
src/tools/
中每个工具一个文件)。优雅地处理 WebDriver 错误(例如,未找到元素、导航问题)。
确保 WebDriver 正确关闭(例如,服务器退出时使用
driver.quit()
)。遵循 MCP 有关架构、错误处理和内容类型的最佳实践。
了解更多
致谢
根据 Seth Rose 创建的模板:
local-only server
The server can only run on the client's local machine because it depends on local resources.
Tools
允许 AI 代理通过 Selenium WebDriver 控制 Web 浏览器会话,从而通过模型上下文协议实现抓取、测试和表单填写等 Web 自动化任务。
Related MCP Servers
- -securityFlicense-qualityEnables AI agents to control web browsers via a standardized interface for operations like launching, interacting with, and closing browsers.
- AsecurityAlicenseAqualityAI-driven browser automation server that implements the Model Context Protocol to enable natural language control of web browsers for tasks like navigation, form filling, and visual interaction.Last updated -12MIT License
- -securityAlicense-qualityEmpowers AI agents to perform web browsing, automation, and scraping tasks with minimal supervision using natural language instructions and Selenium.Last updated -4Apache 2.0
- -securityFlicense-qualityEnables AI assistants to control a browser through a set of tools, allowing them to perform web automation tasks like navigation, typing, clicking, and taking screenshots.Last updated -