bg-control-mcp
Enables launching or connecting to Electron desktop applications with a remote debugging port and controlling them in the background via CDP, including UI actions and form filling.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
bg-control-mcp
轻量级 Windows 本地 MCP 服务:把 后台静默 UI Automation(不抢焦点)、后台静默 Chrome/Edge/Electron CDP 自动化(穿透多层 iframe / OOPIF / Shadow DOM) 和 极速单窗前台定点输入 打包在一起,零 VPS、零复杂鉴权、超省 Token。
给 AI Agent / 人类维护者的说明:本仓库只包含 4 个精简 Python 文件,照下方安装步骤即可直接跑起来。
核心特点
不抢你正在用的电脑:
桌面窗口通过 Win32 UI Automation(
AutoSetFocus = False+ 原生 Pattern)与PrintWindow在后台读写、点击和截窗。网页与 Electron 应用通过独立隔离配置目录(
profiles/)+SW_SHOWMINNOACTIVE后台最小化启动,走 Chrome DevTools Protocol(CDP)直接操控,不碰你日常浏览器,也不弹窗打断前台操作。
超省 Token 的紧凑快照:
cdp_snapshot默认只抓视口内可交互元素 + 精简单行格式,并支持filter_text过滤,输出体积相比整页 DOM/截屏减少约 90%。cdp_action(action="fill", submit=True)一条调用即可完成输入并提交,兼容 React/Vue 原生表单以及contenteditable富文本编辑器(自动切Input.insertText)。
穿透复杂嵌套页面:
支持同源子 iframe、沙箱化跨进程 OOPIF(
blob:/srcdoc,通过Target.setAutoAttach(flatten=True)递归附着)以及开放 Shadow DOM,统一分配e1/f<idx>_e<n>引用。
单窗极速前台兜底(
fg_window_input):针对不暴露 UIA
ValuePattern也没有开 CDP 端口的富文本桌面软件(如常规启动的聊天客户端),可在约 0.3 秒内完成「聚焦目标窗 → 定点点击 → 剪贴板粘贴(自动保护并恢复原剪贴板)→ 回车 → 自动归还光标与原前台窗口」,无需扫描全桌面 UI 树。
本地代理免疫:
所有
127.0.0.1的 CDP HTTP 与 WebSocket 通信均强制绕过系统/环境变量代理,避免本机开梯子导致 CDP 假死或 502。
Related MCP server: GhostHand-MCP
暴露的 12 个 MCP 工具
类别 | 工具名 | 用途 |
Windows 后台 UIA |
| 枚举可见窗口(hwnd、进程名、标题、坐标、最小化/前台状态) |
Windows 后台 UIA |
| 后台读取单个窗口控件树与支持的 Pattern,支持 |
Windows 后台 UIA |
| 后台执行 |
Windows 后台 UIA |
| 后台 |
Windows 极速前台输入 |
| 单窗瞬时激活、可选点击、Unicode 粘贴、组合键/回车,并自动归还光标、剪贴板与前窗 |
后台 CDP |
| 复用现有 CDP 端口,或后台最小化拉起隔离 Chrome/Edge 或指定 Electron 程序( |
后台 CDP |
| 列出指定端口的所有页面标签 |
后台 CDP |
| 打开新标签页(支持 |
后台 CDP |
| 关闭指定标签页 |
后台 CDP |
| 获取紧凑视口元素列表(含 iframe/OOPIF/Shadow DOM 穿透)与页面文本 |
后台 CDP |
| 执行 |
后台 CDP |
| 后台对指定标签页截图(不激活窗口、不抢焦点) |
环境要求
Windows 10 / 11
Python 3.12(推荐使用
uv创建独立虚拟环境;部分 Python 3.14 环境缺少pywin32等预编译 wheel)已安装 Chrome 或 Edge(如需使用 CDP 工具)
快速安装
git clone https://github.com/magua521/bg-control-mcp.git
cd bg-control-mcp
# 推荐用 uv 创建 Python 3.12 虚拟环境
uv venv --python 3.12 .venv
uv pip install --python .venv\Scripts\python.exe -r requirements.txt
# 跑一遍自动化冒烟测试(验证后台 UIA + 无头 Chrome CDP + MCP 12 工具握手)
.venv\Scripts\python.exe smoke_test.py接入 MCP 客户端
把 <INSTALL_DIR> 替换成你实际 clone 的目录路径(建议用正斜杠 /)。
Antigravity / Claude Desktop / 通用 JSON (mcp_config.json)
{
"mcpServers": {
"bg-control": {
"command": "<INSTALL_DIR>/.venv/Scripts/python.exe",
"args": [
"<INSTALL_DIR>/server.py"
],
"env": {
"PYTHONUTF8": "1",
"NO_PROXY": "127.0.0.1,localhost"
}
}
}
}Hermes Agent (config.yaml)
mcp_servers:
bg-control:
command: <INSTALL_DIR>/.venv/Scripts/python.exe
args:
- <INSTALL_DIR>/server.py
env:
PYTHONUTF8: "1"
NO_PROXY: "127.0.0.1,localhost"
timeout: 120
connect_timeout: 30
enabled: true注:Hermes 会为工具名加上
mcp__bg_control__前缀(例如mcp__bg_control__cdp_snapshot)。
环境变量说明
变量名 | 是否必需 | 默认值 | 说明 |
| 推荐 |
| 防止 Windows 控制台/管道 GBK 编码乱码 |
| 推荐 |
| 确保本地回环通信不走外部代理 |
| 可选 |
| 隔离浏览器登录态目录(含 Cookie,已在 |
| 可选 |
| 截图默认输出目录 |
| 可选 | 自动探测本机 | 当 |
实测避坑指南(改动时别踩回去)
为什么不用日常 Chrome 默认 Profile 开 CDP? 新版 Chrome 禁止对默认
User Data目录开启--remote-debugging-port;用profiles/<browser>-<name>独立目录登录一次即可持久化保存登录态,且完全不打扰日常浏览。Next.js / SPA 页面在后台打开一片空白? 某些前端框架在非激活标签页会延迟挂载组件;因为隔离 Chrome 窗口本身已最小化在后台,调用
cdp_open_tab(..., background=False)只会在最小化窗口内部切为当前页,既能完整渲染,也不会弹窗抢焦点。Electron 桌面软件接入:可通过
cdp_launch_or_connect(exe_path="...", port=9223)启动支持--remote-debugging-port的 Electron 应用并在后台走 CDP 操控;对于内部使用contenteditable的富文本输入框,cdp_action(action="fill")会自动走Input.insertText。安全边界:本工具仅操作本机桌面与本地回环端口,不对外暴露公网服务;请勿将
profiles/提交到仓库,也不建议对有强风控封号机制的即时通讯软件做无人值守群发。
目录结构
bg-control-mcp/
├── server.py # MCP 2.x 服务端入口(暴露 12 个工具)
├── bg_cdp.py # 后台静默 CDP 引擎(含 OOPIF / Shadow DOM 穿透)
├── bg_uia.py # Windows 后台 UIA + PrintWindow + fg_window_input 引擎
├── smoke_test.py # 端到端冒烟测试
├── requirements.txt # Python 依赖清单
├── .gitignore # 严格排除 .venv / profiles / screenshots / __pycache__
└── LICENSE # MIT 协议License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Remote desktop control, files, and terminal tools for AI assistants on paired Windows PCs.
Let your AI see your screen, click, type and run commands on your own Windows, Mac or Linux PC.
Let AI see and use your own Windows PC with your permission: screen, apps, mouse and keyboard.
Connect ChatGPT, Claude, Cursor or VS Code to your Windows PC: files, terminal, browser, apps.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to observe and drive Windows desktop applications in the background through UI Automation and Win32 messages, without taking over the user's mouse, keyboard, or foreground window. Every action is read back and verified, and outward actions are held for explicit confirmation.6MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI clients to automate Windows desktop applications through protocol-first, background-safe window inspection, screenshots, clicks, typing, scrolling, browser CDP control, batch pipelines, and built-in safety guardrails without hijacking the physical mouse or focus.MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to automate Windows applications and Chrome/Edge browsers through UI Automation, browser CDP, OCR, vision, and fast screen capture, including clicking, typing, JavaScript execution, page extraction, and waiting for on-screen changes.1MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to inspect and control Windows desktop applications through compact UI Automation trees, dHash-gated screenshots, OCR, and guarded physical, virtual, or parallel input actions with emergency stop.MIT