Skip to main content
Glama

Firefox DevTools MCP

npm version CI codecov License: MIT

用于通过 WebDriver BiDi(经由 Selenium WebDriver)自动化 Firefox 的模型上下文协议 (MCP) 服务器。适用于 Claude Code、Claude Desktop、Cursor、Cline 及其他 MCP 客户端。

仓库地址:https://github.com/mozilla/firefox-devtools-mcp

注意:此 MCP 服务器需要本地安装 Firefox 浏览器,无法在 glama.ai 等云托管服务上运行。请使用 npx firefox-devtools-mcp@latest 在本地运行,或使用提供的 Dockerfile 通过 Docker 运行。

要求

  • Node.js ≥ 20.19.0

  • 已安装 Firefox 100+(自动检测,或通过 --firefox-path 指定)

Related MCP server: gecko-mcp

安装并与 Claude Code (npx) 一起使用

推荐:使用 npx,以便始终运行 npm 上发布的最新版本。

选项 A — Claude Code CLI

claude mcp add firefox-devtools npx firefox-devtools-mcp@latest

通过参数或环境变量传递选项。示例:

# Headless + viewport via args
claude mcp add firefox-devtools npx firefox-devtools-mcp@latest -- --headless --viewport 1280x720

# Or via environment variables
claude mcp add firefox-devtools npx firefox-devtools-mcp@latest \
  --env START_URL=https://example.com \
  --env FIREFOX_HEADLESS=true

选项 B — 编辑 Claude Code 设置 JSON

添加到您的 Claude Code 配置文件中:

  • macOS: ~/Library/Application Support/Claude/Code/mcp_settings.json

  • Linux: ~/.config/claude/code/mcp_settings.json

  • Windows: %APPDATA%\Claude\Code\mcp_settings.json

{
  "mcpServers": {
    "firefox-devtools": {
      "command": "npx",
      "args": ["-y", "firefox-devtools-mcp@latest", "--headless", "--viewport", "1280x720"],
      "env": {
        "START_URL": "about:home"
      }
    }
  }
}

选项 C — 辅助脚本(本地开发构建)

npm run setup
# Choose Claude Code; the script saves JSON to the right path

使用 MCP Inspector 进行尝试

npx @modelcontextprotocol/inspector npx firefox-devtools-mcp@latest --start-url https://example.com --headless

然后调用如下工具:

  • list_pages, select_page, navigate_page

  • take_snapshot 然后 click_by_uid / fill_by_uid

  • list_network_requests(常驻捕获), get_network_request

  • screenshot_page, list_console_messages

CLI 选项

您可以传递标志或环境变量(右侧为名称):

  • --firefox-path — Firefox 二进制文件的绝对路径

  • --headless — 在无界面模式下运行 (FIREFOX_HEADLESS=true)

  • --viewport 1280x720 — 初始窗口大小

  • --profile-path — 使用特定的 Firefox 配置文件

  • --firefox-arg — 额外的 Firefox 参数(可重复)

  • --start-url — 启动时打开此 URL (START_URL)

  • --accept-insecure-certs — 忽略 TLS 错误 (ACCEPT_INSECURE_CERTS=true)

  • --connect-existing — 连接到已运行的 Firefox 而不是启动新实例 (CONNECT_EXISTING=true)

  • --marionette-port — 用于连接现有模式的 Marionette 端口,默认为 2828 (MARIONETTE_PORT)

  • --pref name=value — 通过 moz:firefoxOptions 在启动时设置 Firefox 首选项(可重复)

  • --enable-script — 启用 evaluate_script 工具,在页面上下文中执行任意 JavaScript (ENABLE_SCRIPT=true)

  • --enable-privileged-context — 启用特权上下文工具:列出/选择特权上下文、评估特权脚本、获取/设置 Firefox 首选项以及列出扩展。需要 MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 (ENABLE_PRIVILEGED_CONTEXT=true)

关于 --pref 的说明:当 Firefox 在自动化模式下运行时,它会应用 RecommendedPreferences,这些首选项会修改浏览器行为以进行测试。--pref 选项允许在需要时覆盖这些默认值。

连接到现有的 Firefox

使用 --connect-existing 来自动化您真实的浏览会话——保持 Cookie、登录状态和打开的标签页不变:

# Start Firefox with Marionette enabled
firefox --marionette

# Run the MCP server
npx firefox-devtools-mcp --connect-existing --marionette-port 2828

或者在 about:config(或 user.js)中将 marionette.enabled 设置为 true,以便在每次启动时启用 Marionette。

依赖 BiDi 的功能(控制台事件、网络事件)在连接现有模式下不可用;所有其他功能均正常工作。

警告:请勿在正常浏览时保持 Marionette 启用。它会将 navigator.webdriver = true 并更改其他浏览器指纹信号,这可能会触发受 Cloudflare、Akamai 等保护的网站的机器人检测。仅在需要 MCP 自动化时启用 Marionette,之后请正常重启 Firefox。

工具概览

  • 页面:列出/新建/导航/选择/关闭

  • 快照/UID:获取/解析/清除

  • 输入:点击/悬停/填充/拖拽/上传/表单填充

  • 网络:列出/获取(ID 优先,过滤器,常驻捕获)

  • 控制台:列出/清除

  • 屏幕截图:页面/按 UID(对于 CLI 环境,可选 saveTo)

  • 脚本:evaluate_script

  • 特权上下文:列出/选择特权(“chrome”)上下文,evaluate_privileged_script(需要 MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1)

  • WebExtension:install_extension, uninstall_extension, list_extensions(列出需要 MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1)

  • Firefox 管理:get_firefox_info, get_firefox_output, restart_firefox, set_firefox_prefs, get_firefox_prefs

  • 实用工具:接受/关闭对话框,历史记录后退/前进,设置视口

针对 Claude Code 的屏幕截图优化

在 Claude Code CLI 中使用屏幕截图时,base64 图像数据可能会占用大量上下文。请使用 saveTo 参数将屏幕截图保存到磁盘:

screenshot_page({ saveTo: "/tmp/page.png" })
screenshot_by_uid({ uid: "abc123", saveTo: "/tmp/element.png" })

然后可以使用 Claude Code 的 Read 工具查看该文件,而不会影响上下文大小。

本地开发

npm install
npm run build

# Run with Inspector against local build
npx @modelcontextprotocol/inspector node dist/index.js --headless --viewport 1280x720

# Or run in dev with hot reload
npm run inspector:dev

测试

npm run test:run          # all tests once (unit + integration)
npm test                  # watch mode

有关运行特定测试套件、端到端场景覆盖范围和已知问题的完整详细信息,请参阅 docs/testing.md。

故障排除

  • 未找到 Firefox:请传递 --firefox-path "/Applications/Firefox.app/Contents/MacOS/firefox"(macOS)或您操作系统上的正确路径。

  • 首次运行缓慢:Selenium 会设置 BiDi 会话;后续运行会更快。

  • 导航后 UID 过期:在使用 UID 工具之前,请获取新的快照 (take_snapshot)。

  • Windows 10:MCP 服务器 'firefox-devtools' 发现期间出错:MCP error -32000: Connection closed

    • 解决方案 1 使用 cmd /c 包装 (详细信息):

      "mcpServers": {
        "firefox-devtools": {
          "command": "cmd",
          "args": ["/c", "npx", "-y", "firefox-devtools-mcp@latest"]
        }
      }
    • 解决方案 2 使用 npx 的绝对路径(调整扩展名 — .cmd, .bat, .exe 或 .ps1 — 以匹配您的设置):

      "mcpServers": {
        "firefox-devtools": {
          "command": "C:\\nvm4w\\nodejs\\npx.ps1",
          "args": ["-y", "firefox-devtools-mcp@latest"]
        }
      }

版本控制

  • 1.0 之前的 API:版本从 0.x 开始。请在 npx 中使用 @latest 以获取最新版本。

CI 和发布

  • 包含用于 CI、发布和 npm 发布 GitHub Actions。有关详细信息和所需密钥,请参阅 docs/ci-and-release.md。

问题与贡献

问题在 Bugzilla 上进行跟踪,产品为 Developer Infrastructure,组件为 AI for Development。

如有疑问和讨论,请加入 #firefox-devtools-mcp Matrix 房间。

作者

由 Mozilla 维护。

Available Tools

36 tools
accept_dialogA

Accept browser dialog. Provide promptText for prompts.

Inputs: promptText.

clear_downloadsA

Clear the tracked downloads buffer.

Inputs: no named parameters.

clear_snapshotC

Clear snapshot UIDs. Usually not needed.

Inputs: no named parameters.

click_by_uidA

Click element by UID. Set dblClick for double-click.

Inputs: uid (required), dblClick.

close_firefox_sessionA

Ends the browser session. If the server connected to your existing Firefox, this releases the connection and leaves Firefox running. If the server started Firefox itself, this closes it. Call this when the browser task is complete and no further browser interaction is expected.

Inputs: no named parameters.

close_pageA

Close tab by index.

Inputs: pageIdx (required).

dismiss_dialogA

Dismiss browser dialog.

Inputs: no named parameters.

drag_by_uid_to_uidB

Drag element to another (HTML5 drag events).

Inputs: toUid (required), fromUid (required).

evaluate_scriptA

Run a JS function in the page and return its result. Prefer this for targeted reads (a value, text, computed style, whether an element exists) instead of a full take_snapshot. Use the UID interaction tools for clicking, typing, and filling.

Inputs: function (required), args, saveTo, preview, +2 more.

fill_by_uidA

Fill text input/textarea or pick a select option by UID.

Inputs: uid (required), value (required).

fill_form_by_uidA

Fill multiple form fields at once.

Inputs: elements (required).

get_firefox_infoA
Read-only

Get information about the current Firefox instance configuration, including binary path, environment variables, and output file location.

Inputs: no named parameters.

get_firefox_outputA
Read-only

Retrieve Firefox output (stdout/stderr including MOZ_LOG, warnings, crashes, stack traces). Returns recent output from the capture file. Use filters to focus on specific content.

Inputs: grep, lines, since.

get_page_textA
Read-only

Get the visible text of the page (document.body.innerText). Caps at maxLength (default 20000 chars); saveTo saves the full text to a file.

Inputs: saveTo, preview, maxLength.

hover_by_uidB

Hover over element by UID.

Inputs: uid (required).

install_extensionA

Install a Firefox extension using WebDriver BiDi webExtension.install command. Supports installing from archive (.xpi/.zip), base64-encoded data, or unpacked directory.

Inputs: type (required), path, value, permanent.

list_downloadsA
Read-only

List downloads tracked since startup, including status and saved file path.

Inputs: limit, format, status, urlContains.

list_extensionsB
Read-only

List installed Firefox extensions using the WebDriver BiDi webExtension.moz:listExtensions command.

Inputs: ids, name, isActive.

list_pagesA
Read-only

List open tabs (index, title, URL). Selected tab is marked.

Inputs: no named parameters.

new_pageB

Open new tab at URL. Returns tab index.

Inputs: url (required), wait.

press_keyA

Press a single key, optionally with modifiers, to submit, dismiss, navigate or trigger a shortcut. Not for entering text: use fill_by_uid instead.

Inputs: key (required), uid.

resolve_uid_to_selectorA
Read-only

Resolve UID to CSS selector. Fails if the element is gone.

Inputs: uid (required).

screencast_startA

Start recording a screencast (video) of the current page viewport, saving the output to a file in the downloads directory. Returns a screencast id to pass to screencast_stop. Multiple recordings can run at once.

Inputs: width, height, context, mimeType, +1 more.

screencast_stopA

Stop an in-progress screencast recording started with screencast_start and finalize the video file. Returns the path to the saved file.

Inputs: screencast.

screenshot_by_uidB
Read-only

Capture element screenshot by UID as base64 PNG.

Inputs: uid (required), saveTo.

screenshot_pageB
Read-only

Capture viewport screenshot as base64 PNG. Set fullPage for the whole scrollable document.

Inputs: saveTo, fullPage.

select_pageA

Select active tab by index, URL, or title. Index takes precedence.

Inputs: url, title, pageIdx.

set_download_behaviorA

Control how downloads are handled: allow (save to a destination folder), deny (cancel), or reset to default. Avoids the native save-file dialog. Requires a recent Firefox.

Inputs: behavior (required), downloadFolder.

set_viewport_sizeA

Set viewport dimensions in pixels. Applies to the selected tab only.

Inputs: width (required), height (required).

take_snapshotA
Read-only

Capture DOM snapshot with stable UIDs. A UID stays valid across snapshots until its element is removed or the page navigates. Output caps at maxLines (default 100); scope with selector or dump the full tree with saveTo.

Inputs: saveTo, preview, maxDepth, maxLines, +4 more.

type_textA

Type text key by key into the focused element, optionally followed by a key such as Enter. Use fill_by_uid to set the value of a known input; use this for elements that only react to real typing, such as autocomplete fields and rich text editors.

Inputs: text (required), uid, submitKey.

uninstall_extensionA

Uninstall a Firefox extension using WebDriver BiDi webExtension.uninstall command. Requires the extension ID returned by install_extension or obtained from list_extensions.

Inputs: id (required).

upload_file_by_uidB

Upload file to file input by UID.

Inputs: uid (required), filePath (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 36 tools

    Disambiguation4/5

    Most tools target a distinct resource+action, and the descriptions actively steer between near-neighbors (fill_by_uid vs type_text vs press_key, screenshot_page vs screenshot_by_uid, take_snapshot vs get_page_text vs evaluate_script). The only real overlaps are the fill family (fill_by_uid, fill_form_by_uid, type_text) and the three 'read the page' tools, but each carries explicit guidance on when to use it.

    Naming Consistency3/5

    The majority follow verb_noun (click_by_uid, list_pages, take_snapshot, install_extension), but there are deviations: noun-first forms like screencast_start/screencast_stop (vs the otherwise dominant verb_noun, cf. navigate_history), set_download_behavior/set_viewport_size, and noun-as-verb names like screenshot_by_uid, screenshot_page, drag_by_uid_to_uid. Still readable and predictable in spirit, but not a single consistent convention.

    Tool Count2/5

    36 tools is heavy for a browser automation surface; most earn their place, but there is clear consolidation headroom (clear_snapshot, resolve_uid_to_selector, clear_downloads, get_firefox_info are marginal, and the fill/type/screenshot variants could be merged). The count pushes well past the 15-tool comfort zone into territory where selection cost is real.

    Completeness3/5

    Core lifecycle is well covered: tabs, navigation, history, viewport, UID-based interaction, forms, uploads, dialogs, downloads, extensions, screenshots, PDF printing, screencast, and session teardown. Notable devtools gaps remain: no console message retrieval distinct from raw Firefox stdout/stderr, no network request inspection/interception, no explicit wait-for-element/condition, and no frame/iframe or cookie/storage management.

    Maintenance

    ActivityActive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Drive Firefox-based browsers (Floorp, LibreWolf, Zen, Waterfox, Mullvad, Firefox) from any MCP client — read pages, screenshot, click, fill forms and manage tabs in your real session, over Marionette/WebDriver. OS input & JS eval locked by default.
      41
      63 npm
      2
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables AI agents to drive a user-launched Firefox instance via its native Marionette protocol, providing precise DOM actuation like clicking, typing, uploading files, taking screenshots, and evaluating JavaScript.
      18
      11 npm
      1
      GPL 2.0