electron-driver 标志

electron-driver

社区
mesomya

MCP server that lets AI agents drive Electron apps — click, type, drag, screenshot, eval JS in the renderer or main process, capture console logs. 38 tools, Playwright-powered, works with any Electron app.

发布者mesomya
代码仓库electron-driver
语言JavaScript
复刻数
1
星标数
3
可用工具
20
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    electron-driver 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 20 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 3 个 Star 和 1 个 Fork。

electron-driver

npm version license node version

Drive Electron apps from AI agents. Click, type, drag, screenshot, evaluate JavaScript in the renderer or main process, read console logs, handle multi-window apps, capture accessibility snapshots — all through an MCP (Model Context Protocol) server that plugs into Claude Code, Claude Desktop, Cursor, and any other MCP-compatible agent host.

https://github.com/user-attachments/assets/a95500d2-28d2-4ee1-9965-8f7e1ef54caa

Built on Playwright's experimental _electron API. Works with any Electron app — React, Vue, Svelte, vanilla — as long as you can point it at a compiled main-process entry.

Status: v0.3.0. First public release. 38 tools covering real workflows.

Why this exists

AI agents can reason about what a desktop app should do, but they can't see or interact with one on their own. Web browsers have plenty of agent-automation options; Electron has almost none. This package closes that gap: give an agent the path to your compiled Electron app and it can drive it the same way a human would.

Common use cases:

  • An agent verifies a feature it just implemented by actually running the app and checking the visible result
  • Visual regression testing during a refactor
  • Accessibility audits via ARIA tree snapshots
  • Reproducing bugs from a natural-language description
  • Teaching a subagent to iterate on UI until a spec passes

Install

Requires Node 18+ and an Electron app you've already built.

bash
npm install electron-driver

You don't need to install Playwright browsers separately — _electron drives your Electron binary directly.

Register with your agent host

Claude Code (project scope)

Create .mcp.json at the repo root:

json
{
  "mcpServers": {
    "electron-driver": {
      "command": "npx",
      "args": ["electron-driver"]
    }
  }
}

Claude Code (user scope — available in every project)

bash
claude mcp add electron-driver --scope user -- npx electron-driver

Claude Desktop / Cursor / other

Add to the host's MCP configuration, pointing at npx electron-driver or the absolute path to node_modules/electron-driver/index.mjs.

Core idea

The server owns exactly one Electron session at a time. start_app launches it, everything else drives it, stop_app closes it. Screenshots go to a session directory that is wiped on every start_app — no pileup, no stale artefacts. All tool calls are logged to <project>/.electron-driver/driver.log during a session.

Errors carry a stable code field so callers can branch programmatically without regex-matching prose:

CodeMeaning
NOT_RUNNINGA tool needs a running session, but there isn't one
ALREADY_RUNNINGstart_app called while a session exists
TIMEOUTAn action hit its timeout
NOT_FOUNDSelector or file didn't match
FILE_NOT_FOUNDPath-based input points at a missing file
BAD_ARGUMENTArguments failed validation
UNKNOWN_TOOLTool name not recognized
ERROREverything else

Tools

All 38 tools grouped by purpose. Every selector-based tool uses Playwright's full selector engine: CSS, text=, role=, [aria-label=], :has-text(), scoping (main >> button), etc.

Lifecycle

start_app — launch the app. Takes main (absolute path to the compiled main entry), optional cwd, args, env, screenshotsDir, timeoutMs. Returns { title, url, viewport, screenshotsDir, logFile }. Detects the single-instance-lock failure mode and gives a helpful hint instead of a raw disconnection error.

stop_app — close cleanly. Safe on an already-stopped session.

info — { title, url, viewport: {width, height, devicePixelRatio}, uptimeMs }. Viewport is populated from window.innerWidth/innerHeight.

Capturing

screenshot — full-page PNG. Pass name (without extension) to control the filename. Returns { path }.

cleanup_screenshots — wipe the current session's screenshot directory.

console_logs — recent renderer console messages (log/info/warn/error/ debug/pageerror) and main-process stdout/stderr. Rolling 1000-entry buffer. Filter by source (renderer/main/all), type, and limit. Pass clear: true to drain after reading.

Interaction

click — click an element. Options: timeoutMs, button (left/right/middle), clickCount, force (skip actionability checks), position (click at an offset inside the element).

type — fill a text input, replacing existing content. Fast but only works on real inputs. For editors/CodeMirror/contenteditables, use keyboard_type.

keyboard_type — type as real per-character keydown events. Pass focusSelector to click an element first. Warns in the result if nothing has focus and no focus selector was passed.

press — press a key or chord: "Escape", "Enter", "Control+S", "Shift+Tab", "Control+Shift+P".

press_sequence — alias for keyboard_type with no focus selector.

hover — hover over an element. Options: timeoutMs, force.

drag — drag from one point to another using real Chromium input events (via Playwright's CDP mouse pipeline). Because these are trusted browser events, Chromium's pointer pipeline generates matching PointerEvents as a side effect, so React onPointerDown, native pointerdown listeners, setPointerCapture, CSS :hover/:active, and every other pointer consumer see the drag exactly as if a real user had performed it. Coordinates are CSS pixels. Pass detectSelector and the driver will measure the element before and after the drag and include detect.moved in the result — the only reliable way to catch drags that silently hit a min/max clamp.

json
{
  "from": { "x": 275, "y": 400 },
  "to":   { "x": 420, "y": 400 },
  "detectSelector": ".sidebar-resize-handle"
}

If the primary strategy does not move the detect target, the driver automatically falls back to invoking the React handler directly via fiber-prop access and dispatching move/up events on both document and window — covering all known React splitter patterns. Disable the fallback with fiberFallback: false. The result includes strategy ("pointer-capture" or "react-fiber").

clear_input — empty an input or textarea.

select_option — select from a <select> by value, label, or index.

check — check a checkbox or radio. Options: timeoutMs, force.

uncheck — uncheck a checkbox.

scroll — scroll a container (pass selector) or the window. Supports absolute (x, y) or delta (dx, dy).

scroll_into_view — ensure an element is visible. Safe if already is.

drop_file — simulate dropping a file onto a target via synthetic DragEvents and a reconstructed File with DataTransfer. Works for apps that read the File via web APIs (FileReader, File.text(), etc). Does not populate file.path — apps relying on webUtils.getPathForFile() must use eval_main to invoke their own IPC handler directly.

set_input_files — the correct way to test file upload UI. Sets files on an <input type="file"> without a native dialog. Much more reliable than drop_file when the app uses real file inputs.

Waiting

wait — fixed pause in milliseconds. Prefer the others.

wait_for_selector — wait until a selector reaches a state (attached/detached/visible/hidden). Honours timeoutMs. Returns count, box, and elapsedMs on success; the error carries elapsed vs requested on timeout.

wait_for — poll a JavaScript predicate (function body, use return) until it returns truthy. Options: timeoutMs, pollMs.

Checking & reading state

exists — { exists, count } fast check, no waiting. Accepts the full selector engine.

get_text — text content of the first match. Accepts the full selector engine. Returns { exists, text }.

get_attribute — read an HTML attribute by name. Returns { exists, value }.

get_value — read an input/textarea/select's current value.

get_bbox — bounding box as { x, y, width, height } in CSS pixels. Use before dragging or clicking at an offset.

get_computed_style — read one or more computed CSS properties. Pass a properties array.

elements_list — enumerate elements matching a selector with their tag, id, classes, text snippet, box, and key attributes. Great for "what buttons exist on this screen". Capped at 50 by default; tune via limit.

focused_element — what currently has focus, with tag/id/classes/text and bounding box. Returns { focused: false } if nothing meaningful has focus.

accessibility_snapshot — capture the ARIA tree as JSON. Useful for a11y audits and finding elements by role. Pass interestingOnly: false to include every node. Pass root to snapshot a subtree.

Multi-window

windows_list — every BrowserWindow the app has open, with id, title, URL, focus/visibility/state flags.

switch_window — route subsequent tool calls to a different window. Pass index or titleMatch.

Dialogs

dialog_handler — install an auto-responder for JavaScript dialogs (alert/confirm/prompt/beforeunload). Pass action: "accept" | "dismiss", optional text for prompt(), and once: true (default) to auto-uninstall after the first dialog.

Evaluation escape hatches

Both eval_renderer and eval_main use the same contract: pass a function body, use return to yield a value, supports async/await, and an optional arg payload is available as the local arg variable.

eval_renderer — evaluate in the renderer (page) context.

json
{
  "js": "return document.querySelectorAll(arg.selector).length",
  "arg": { "selector": ".item" }
}

eval_main — evaluate in the Electron main process. The body receives electron (the full Electron module) and arg.

json
{
  "js": "return electron.app.getName()"
}
json
{
  "js": "const w = electron.BrowserWindow.getAllWindows()[0]; w.webContents.send('open-file', arg.path); return true",
  "arg": { "path": "C:/docs/README.md" }
}

Use eval_main as the escape hatch for everything the DOM side can't reach: invoking IPC handlers, reading user paths, driving secondary windows, bypassing native dialogs for apps that use them.

Selectors cheat sheet

text
text=Open File              // exact text match
text=/^Save$/               // regex
[aria-label="Settings"]     // ARIA attribute
role=button[name="Close"]   // ARIA role
button:has-text("Save")     // CSS with text predicate
button.primary              // plain CSS
main >> text=Save           // scoped

Selector-engine consistency

Every selector-based tool (click, hover, wait_for_selector, get_text, get_attribute, get_value, get_bbox, exists, elements_list, scroll_into_view, select_option, check, uncheck, set_input_files) goes through Playwright's full locator engine. Anything Playwright accepts, these tools accept — including text=, role=, and :has-text().

Tools that read low-level DOM via eval_renderer under the hood (get_computed_style, scroll, focused_element, drop_file) use native document.querySelector and only support CSS. This is documented on each tool's description where relevant.

Troubleshooting

"Electron process exited immediately after launch." Another copy of your app is already running and grabbed the single-instance lock — the second process quits via app.requestSingleInstanceLock(). Close the running instance (check your taskbar and background processes) and retry.

drag returned ok:true but detect.moved is false. The most common cause is a min/max clamp on the target (e.g. a resizable sidebar at its MAX_WIDTH). Try dragging in the opposite direction to confirm the drag pipeline is working. If it's really not the clamp, the React fiber fallback should catch it automatically — check the strategy field in the result. If even that returns moved:false, use eval_renderer or eval_main to invoke the app's own drag API directly.

type throws "Element is not an <input>..." You're hitting a button, a div, or a contenteditable. Use keyboard_type with a focusSelector instead.

click times out on an element that's clearly there. Something is covering it — a modal backdrop, a tooltip, a toast. Use exists first to confirm the count, then try force: true, or use eval_renderer to check getComputedStyle(el).pointerEvents.

Native dialogs are invisible. Playwright cannot see OS-level file pickers, save dialogs, or system alerts. Use eval_main to invoke the same IPC handler your UI button uses. For JavaScript dialogs (alert/confirm/prompt), use dialog_handler to auto-respond.

Development build vs compiled app. This drives the built app, not dev-server output. Run your build command before start_app, and rebuild

  • restart the session after source changes.

One session at a time. Calling start_app while a session is running returns ALREADY_RUNNING. Call stop_app first.

Logs. Every tool call is logged to <project>/.electron-driver/driver.log while a session is active. Useful when debugging why an agent got stuck.

Screenshots location. Defaults to <project>/.electron-driver/screenshots, where <project> is the nearest directory containing .git or package.json. Override via screenshotsDir on start_app.

Security

This server gives the connected agent full control over an Electron app, including arbitrary code execution in the main process (via eval_main). The Electron main process has unrestricted Node.js access — filesystem, network, child processes, everything. This is by design: it's what makes the driver powerful enough to drive real apps.

What this means for you:

  • Only use over stdio (the default). Never expose this server over HTTP, WebSocket, or any network transport. Stdio ties it to the process that spawned it — your local Claude Code or Claude Desktop session.
  • Trust the agent. The agent calling these tools can do anything on your machine via eval_main. Only connect agents you trust.
  • Don't use in multi-tenant environments. This is a single-user, local-machine tool. It's not designed for shared servers, CI pipelines with untrusted input, or any context where the caller might be adversarial.
  • drop_file and set_input_files read local files and pass their contents to the renderer. The file paths should come from trusted sources.

If you're running this with Claude Code, the risk profile is the same as giving Claude Code terminal access (which you already have). The driver doesn't add new capabilities beyond what eval in a terminal could do — it just makes them convenient for the agent to use.

Known limitations

  • Playwright's _electron namespace is officially experimental upstream. Occasional launch timeouts on slow machines; usually retrying fixes it.
  • Developed primarily on Windows. Mac and Linux should work — Playwright handles them — but are less battle-tested. Bug reports welcome.
  • switch_window routes subsequent calls to the selected window, but the console-log buffer is populated from the initial window. Multi-window console capture is a planned v0.4 item.
  • drop_file does not populate file.path. Apps using webUtils.getPathForFile() must use eval_main with their own IPC.
  • No built-in network-request capture yet — planned for v0.4.

Implementation notes

For anyone curious or contributing:

  • Single Electron session, owned by the MCP server process.
  • Screenshots wiped on every start_app — intentional.
  • Console logs captured into a rolling 1000-entry buffer.
  • Every tool call is logged; errors carry a stable code field.
  • Error messages are rewritten to be attributed to the driver tool, not the underlying Playwright method.
  • Single-instance-lock detection keys on "process disconnected within 5s of launch", which is the actual shape of the failure.
  • Evals are async-IIFE wrapped, so return works and await works.
  • arg payloads are coerced server-side (JSON-parse on strings) to protect against MCP clients that stringify arg fields.
  • stderr is used for status messages; stdout is reserved for MCP protocol frames.

Contributing

Issues and PRs welcome. Run locally with:

bash
cd electron-driver
npm install
node index.mjs  # stdio MCP server

The server logs a ready banner to stderr and waits for MCP frames on stdin. Test it against a real Electron app via any MCP client.

License

MIT

安装

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "electron-driver": {
      "command": "npx",
      "args": [
        "-y",
        "electron-driver"
      ]
    }
  }
}

可用工具

  • start_app

    Launch an Electron application

  • stop_app

    Close the running Electron app

  • screenshot

    Take a full-page PNG screenshot

  • click

    Click on an element

  • type

    Fill text input by replacing existing content

  • keyboard_type

    Type text as real keydown events

  • press

    Press keys or key combinations

  • hover

    Hover over an element

  • drag

    Drag from one point to another

  • wait_for_selector

    Wait until selector reaches specified state

  • exists

    Check if element exists without waiting

  • get_text

    Get text content of first matching element

  • get_attribute

    Read HTML attribute value

  • console_logs

    Get recent console messages from renderer and main process

  • eval_renderer

    Execute JavaScript in renderer process

  • eval_main

    Execute JavaScript in main process

  • accessibility_snapshot

    Capture ARIA tree for accessibility audits

  • windows_list

    List all open browser windows

  • switch_window

    Switch focus to different window

  • drop_file

    Simulate file drop onto target element

将 electron-driver MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 electron-driver 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 electron-driver 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 electron-driver MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "electron-driver": {
      "command": "npx",
      "args": [
        "-y",
        "electron-driver"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 electron-driver MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 electron-driver MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 electron-driver 帮我完成这项任务吗?
electron-driver
当然。我已阅读。
以下是我使用 electron-driver 得到的结果。

常见问题

electron-driver MCP 服务器有什么用途?

electron-driver 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 electron-driver MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 electron-driver,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 electron-driver MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 electron-driver 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 electron-driver MCP 连接到 TypingMind?

electron-driver 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

electron-driver MCP 在 TypingMind 中提供哪些工具?

electron-driver 提供 20 个 MCP 工具,您可以在 TypingMind 的插件页面启用这些工具,然后在聊天中使用,或将其分配给 AI 智能体。

使用 electron-driver MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 electron-driver 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇