Chrome MCP Server

by lxe

Chrome MCP 服务器

模型上下文协议 (MCP) 服务器通过 Chrome DevTools 协议 (CDP) 提供对 Chrome 浏览器实例的细粒度控制。

先决条件

  • Bun (推荐)或 Node.js(v14 或更高版本)
  • 启用远程调试的 Chrome 浏览器

设置

安装 Bun

  1. 安装 Bun(如果尚未安装):
# macOS, Linux, or WSL curl -fsSL https://bun.sh/install | bash # Windows (using PowerShell) powershell -c "irm bun.sh/install.ps1 | iex" # Alternatively, using npm npm install -g bun
  1. 启动 Chrome 并启用远程调试:您可以使用附带的脚本自动检测您的操作系统并使用正确的命令启动 Chrome:
    # Make the script executable chmod +x start-chrome.sh # Run the script ./start-chrome.sh
    或者手动启动 Chrome 进行远程调试:
    # macOS /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 # Windows start chrome --remote-debugging-port=9222 # Linux google-chrome --remote-debugging-port=9222
  2. 安装依赖项:
bun install
  1. 启动服务器:
bun start

对于使用热重载进行开发:

bun dev

服务器默认在 3000 端口启动。您可以通过设置PORT环境变量来更改此设置。

配置 Roo Code 以使用此 MCP 服务器

要将此 Chrome MCP 服务器与 Roo 代码一起使用:

  1. 打开 Roo 代码设置
  2. 导航至 MCP 设置配置文件:
    • macOS: ~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json
    • Windows: %APPDATA%\Code\User\globalStorage\rooveterinaryinc.roo-cline\settings\cline_mcp_settings.json
    • Linux: ~/.config/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json
  3. mcpServers对象添加以下配置:
{ "mcpServers": { "chrome-control": { "url": "http://localhost:3000/sse-cursor", "disabled": false, "alwaysAllow": [] } } }
  1. 保存文件并重新启动 Roo Code 以应用更改。
  2. 您现在可以使用 Roo Code 中的 Chrome MCP 工具来控制浏览器。

可用工具

服务器提供以下浏览器控制工具:

导航

导航到特定的 URL。

参数:

  • url (字符串):要导航到的 URL

点击

单击特定坐标。

参数:

  • x (数字):X 坐标
  • y (数字):Y坐标

类型

在当前焦点处输入文本。

参数:

  • text (字符串):要输入的文本

clickElement

单击页面信息中索引对应的元素。

参数:

  • selector (字符串):元素索引(例如,“0”表示第一个元素)

获取文本

使用 CSS 选择器获取元素的文本内容。

参数:

  • selector (字符串):用于查找元素的 CSS 选择器

获取页面信息

获取有关页面的语义信息,包括交互元素和文本节点。

获取页面状态

获取当前页面状态,包括 URL、标题、滚动位置和视口大小。

用法

服务器通过 SSE 传输实现模型上下文协议。请通过以下方式连接到服务器:

  • SSE 端点: http://localhost:3000/sse-cursor
  • 消息端点: http://localhost:3000/message?sessionId=...

与 Roo Code 一起使用时,MCP 设置文件中的配置将自动处理连接。

发展

要使用热重载以开发模式运行服务器:

bun dev

这使用 Bun 的内置监视模式在文件发生变化时自动重启服务器。

执照

麻省理工学院

-
security - not tested
-
license - not tested
-
quality - not tested

模型上下文协议服务器,使 AI 助手能够通过 Chrome DevTools 协议控制 Chrome 浏览器,从而实现导航、点击、输入和提取页面信息。

  1. Prerequisites
    1. Setup
      1. Installing Bun
    2. Configuring Roo Code to use this MCP server
      1. Available Tools
        1. navigate
        2. click
        3. type
        4. clickElement
        5. getText
        6. getPageInfo
        7. getPageState
      2. Usage
        1. Development
          1. License
            ID: qwqhondcp6