Mcp Cdp

io.github.dockndevai由 GitHub 账号 dockndevai 发布v0.2.3更新于 Oct 26, 2026

Safe-by-default MCP that drives an Electron/Chrome app over CDP: DOM, console, network, input.

已验证STDIO仅桌面浏览器自动化开发者工具

概览

AI 生成的概览

默认安全的 MCP 服务器,通过 Chrome DevTools 协议驱动 Electron 或 Chrome/Chromium 应用,提供 DOM、控制台、网络与输入工具。

可以做什么
  • 列出可调试目标,如页面、webview 和 Electron 窗口,含 id、类型、标题和 URL。
  • 读取整页或 CSS 选择器子树的渲染 HTML,并查询匹配元素的外部 HTML。
  • 查看最近的浏览器控制台输出、未捕获异常和网络请求(方法、URL、状态、MIME、失败情况)。
  • 截取视口 PNG 截图,用于检查布局与渲染。
  • 在读写模式下点击元素、输入文本、按键,并将目标导航到指定 URL。
  • 在管理员模式并显式开启开关时,在页面中执行 JavaScript 表达式。
适用场景
适合需要检查或操作暴露了 DevTools 端口的桌面或网页应用的场景,例如排查失败的 UI 测试、读取精确 DOM 而非截图、查看控制台错误和失败请求。也适合多个并行代理各自连接独立调试端口的情况。
运行要求
通过 npx 从 npm 包本地运行,需要 Node.js。目标应用或浏览器须以远程调试端口启动(CDP_PORT,默认 9222),且主机为回环地址(CDP_HOST)。CDP_MODE 选择只读、读写或管理员模式;evaluate 工具还需 CDP_ALLOW_EVAL。未声明需要账号或 API 密钥。
安装前请注意
默认只读,但将 CDP_MODE 提升到读写后,助手即可在应用中点击、输入和导航;管理员模式加 CDP_ALLOW_EVAL 允许在渲染进程中执行任意 JavaScript。可用 CDP_TARGET_ALLOWLIST 和受保护目标限制范围,用 CDP_DRY_RUN 仅记录而不实际执行。请求头不会被采集、敏感 URL 查询值会被脱敏,但页面内容和网络元数据仍会发送给模型。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Mcp Cdp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

mcp-cdp

[npm] [CI] [licence]

A safe-by-default Model Context Protocol server that drives an Electron or Chrome/Chromium app over the Chrome DevTools Protocol (CDP) — instead of pixel-level GUI automation. Point it at the app's --remote-debugging-port and an agent gets the DOM, console, network requests, real input (click / type / navigate), and — gated — JavaScript evaluation.

Why this beats computer-use for a desktop/web app:

  • The DOM, not a screenshot. The agent reads exact rendered HTML and can query any element — far more information, and it sees things that aren't on screen.
  • Console + network. When a test fails, the uncaught exception or the failed request is right there — no guessing from an image.
  • No collisions. Each agent attaches to its own debugging port, so parallel agents (e.g. one per git worktree) never fight over one desktop.
  • Cross-OS. CDP works identically on macOS, Linux and Windows — the same flow runs on a headless VPS.

Part of the dockndevai MCP server suite — one governance model across all of them.

What it gives an agent

Starts read-only (see Safe by default); higher-capability tools are only registered when you raise the mode.

ToolForNeeds mode
list_targetslist pages / webviews / Electron windows (id, type, title, url)read-only
dom_snapshotrendered HTML of the page or a selector's subtreeread-only
query_domouter HTML of every element matching a CSS selectorread-only
console_logsrecent console output + uncaught exceptionsread-only
network_requestsrecent requests (method, url, status, mime; headers never captured)read-only
screenshota PNG of the viewportread-only
clickclick the first element matching a selectorread-write
type_texttype into the page (focus a selector first)read-write
press_keyEnter / Tab / Escape / Backspace / Delete / Arrowsread-write
navigatenavigate a target to a URL (confirmed)read-write
evaluaterun a JavaScript expression in the pageadmin + CDP_ALLOW_EVAL

Install

bash
npx -y @dockndevai/mcp-cdp

Expose a debugging port

Start your app (or a worktree's dev build) with an explicit port — one per agent:

  • Electron app: your-app --remote-debugging-port=9222, or in main-process code app.commandLine.appendSwitch('remote-debugging-port', '9222') before app.whenReady().
  • Plain Chrome/Chromium: chrome --headless=new --remote-debugging-port=9222 --user-data-dir=/tmp/p1 <url>.

Check it's up: curl http://127.0.0.1:9222/json/version.

Configure

json
{  "mcpServers": {    "cdp": {      "command": "npx",      "args": ["-y", "@dockndevai/mcp-cdp"],      "env": {        "CDP_PORT": "9222",        "CDP_MODE": "read-only"      }    }  }}

See docs/CLIENTS.md for Claude Code / Cursor / Codex / VS Code / Windsurf, and .env.example for every variable.

Safe by default

Enforced by src/security.ts. The browser process is the real boundary — this keeps an agent inside the targets and actions you intend:

  • CDP_MODE — read-only (default) → read-write → admin. Tools above the mode aren't registered, so in read-only the agent cannot click, type or navigate at all.
  • CDP_TARGET_ALLOWLIST — confine interactions to targets whose URL matches your patterns (empty = all). Reads (inspection) are always allowed.
  • CDP_PROTECTED_TARGETS — targets that can be inspected but never interacted with. Defaults protect sign-in pages (accounts.google.com, login.microsoftonline.com, …) and browser internals (chrome://, devtools://, extensions).
  • CDP_ALLOW_EVAL — evaluate is arbitrary code execution in the renderer: admin mode plus this flag, refused on protected targets, with a human confirmation.
  • CDP_DRY_RUN — interactions log their intent and return without dispatching.
  • Secrets — request/response headers are never captured (cookies/auth), and sensitive URL query values are redacted. evaluate and navigate also prompt a human via MCP elicitation.
  • Loopback only — the endpoint must be 127.0.0.1 unless CDP_ALLOW_REMOTE=true.

Optional AI risk guard. Set CDP_GUARD_MODE=monitor|enforce to have the evaluate tool consult a local laya-guard daemon (pipx install laya-guard && laya-guard) that classifies the JS expression allow/confirm/block before it runs. It runs after the eval gate and can only tighten, never grant; fails closed.

There is a bundled skill, cdp-safe-operations, that teaches an agent how to expose a port, read the DOM/console/network instead of screenshots, the safety rules, and the "why did this fail?" workflow. See also SECURITY.md.

Developing

bash
npm installnpm run build# list the tools:echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | CDP_PORT=9222 node dist/index.jsnpm test

Licence

MIT

来源:README.md,提交 a533f1b

工具

6

list_targets

List targets

List the debuggable targets on the DevTools endpoint — pages, webviews and Electron windows — with their id, type, title and URL. Start here to find the target id every other tool needs.

无需输入参数。

dom_snapshot

DOM snapshot

Return the rendered HTML of a target — the whole document, or just the subtree of the first element matching a CSS selector. This is the DOM the agent should read instead of a screenshot: it carries far more information and is exact.

输入参数selectortarget_id必填

query_dom

Query DOM

Return the outer HTML of every element matching a CSS selector (capped). Use to locate the exact elements to click or type into, and to confirm what is actually on the page.

输入参数limitselector必填target_id必填

console_logs

Console logs

Return recent console output and uncaught exceptions captured from the target since it was first inspected. The fastest way to see why something failed — errors that never appear on screen.

输入参数limittarget_id必填

network_requests

Network requests

Return recent network requests captured from the target — method, URL, status, MIME type, failures. Headers are never captured and sensitive URL query values are redacted.

输入参数limittarget_id必填url_filter

screenshot

Screenshot

Capture a PNG screenshot of the target's viewport. Prefer dom_snapshot for reading content; use this for visual layout, rendering and image checks.

输入参数target_id必填

版本历史

3
  1. v0.2.3最新Oct 26, 2026
  2. v0.2.0Sep 27, 2026
  3. v0.1.0Sep 22, 2026

评分

已满足适用检查项的 90%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分
  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分