multi-vm-mcp
Controls Oracle VirtualBox 7.x VMs through VBoxManage and the Windows COM SDK: captures console screenshots, injects absolute mouse movement and clicks, sends keystrokes and Unicode text, executes guest commands via guestcontrol, reports Guest Additions status and guest IP, and manages power state and snapshots.
Controls VMware Workstation/Player VMs through vmrun and VNC: captures the console screen (with observation_id), injects mouse/keyboard input, runs guest programs, pastes Unicode text into the focused field, checks Tools status and guest IP, and manages power state and snapshots.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@multi-vm-mcp capture the current screen of win11-lab and click the Start button"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
一个本地 MCP Server,统一操作 VMware Workstation/Player 与 Oracle VirtualBox。
让 Agent 看虚拟机画面、动鼠标键盘、执行 Guest 命令、管理电源与快照。
ESXi / vCenter Provider 接口已预留,v1 暂未实现。
为什么是 multi-vm-mcp
设计 | 解决的问题 |
一个协议,多个后端 | Provider 注册表按 |
观察编号(observation_id) | GUI 动作必须基于最新画面,防止 Agent 盲点、重放和坐标错位 |
异步命令任务(job_id) | 长命令不阻塞 MCP;服务重启后仍可继续读取输出 |
异步 VM 操作(operation_id) | 电源/快照操作可追踪;结果不明时先查状态,不盲目重试 |
本地凭据库 | Guest 密码与 VNC 密码存系统 keyring,不写进配置文件 |
安全默认值 | 破坏性操作要求 |
stdio 本地运行 | 不监听公网端口,适合 Codex、Claude Code、Cursor、Trae 等客户端 |
Related MCP server: qemu-mcp-server
能做什么
能力 | 说明 |
控制台画面 | 返回虚拟机当前 PNG/JPEG 画面、分辨率与 |
GUI 操作 | 鼠标移动、单击、双击、右键、拖拽、滚轮、按键、快捷键、文本输入 |
连续动作 | 一次最多 50 个短动作,返回最终画面 |
Unicode 粘贴 | 向已聚焦输入框粘贴中文或长文本;依赖 Guest Tools / 剪贴板工具 |
登录框输入 | 使用已保存用户名或密码输入,不向 Agent 返回凭据文本 |
Guest 命令 | Windows CMD/PowerShell、Linux Bash/Sh,异步任务与输出回读 |
电源管理 | 启动、正常关机、强制断电、重启、暂停、恢复、挂起、保存状态 |
快照管理 | 列出、创建、恢复、删除;恢复后旧观察编号自动失效 |
状态查询 | 运行状态、VMware Tools / Guest Additions、Guest IP |
多虚拟机 | 按名称选择目标,每台机器独立配置与凭据 |
客户端接入 | 生成 Codex / Claude Code / Claude Desktop / Cursor 的 stdio 配置 |
架构
flowchart LR
A["MCP Client<br/>Codex / Claude / Cursor / Trae"] -->|stdio| B["multi-vm-mcp<br/>FastMCP"]
B --> C["LabService<br/>观察 / 任务 / 操作编排"]
C --> D["Provider Registry"]
D --> E["VMware Provider<br/>vmrun + VNC"]
D --> F["VirtualBox Provider<br/>VBoxManage + COM SDK"]
D -.->|预留| G["ESXi / vCenter<br/>future"]
E --> H["VMware 虚拟机"]
F --> I["VirtualBox 虚拟机"]MCP 层:12 个工具,输入校验、结构化错误、图像内容返回。
服务层:观察编号、每 VM 串行锁、后台任务、操作状态机。
Provider 层:统一接口,能力声明(截图、鼠标、Unicode 粘贴、Guest 命令等)。
存储层:SQLite 保存命令任务与操作记录;系统 keyring 保存凭据。
快速开始
环境要求
宿主机:Windows 10/11 x64
Python 3.11+
VMware Workstation/Player(提供
vmrun.exe),或 Oracle VirtualBox 7.x(提供VBoxManage.exe)Guest 内已安装 VMware Tools / open-vm-tools / Guest Additions(命令执行与 IP 查询需要)
macOS/Linux 宿主机代码保持可移植,但 v1 未做完整验证
安装
git clone https://github.com/ZiYyyun/multi-vm-mcp.git
cd multi-vm-mcp
# 推荐:uv
uv venv --python 3.12 .venv
uv pip install -e ".[dev]" --python .venv\Scripts\python.exe
# 或者:venv + pip
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e ".[dev]"配置与注册
# 1. 生成配置
.\.venv\Scripts\vm-mcp.exe init
# 2. 发现本机虚拟机并写入配置
.\.venv\Scripts\vm-mcp.exe discover --register
# 3. 编辑配置,填写 guest_user
# %APPDATA%\vmboxs-mcp\config.toml
# 4. 保存 Guest 登录密码(交互输入,不写配置文件)
.\.venv\Scripts\vm-mcp.exe credential set <虚拟机名>
# 5. VMware 虚拟机首次使用控制台前:先关机,再准备 VNC
.\.venv\Scripts\vm-mcp.exe console prepare <虚拟机名>
# 6. 检查 Provider、配置、凭据和虚拟机状态
.\.venv\Scripts\vm-mcp.exe doctor接入 MCP 客户端
# 写入 Codex 配置(~/.codex/config.toml)
.\.venv\Scripts\vm-mcp.exe install codex
# 或 Claude Code / Claude Desktop / Cursor
.\.venv\Scripts\vm-mcp.exe install claude-code
.\.venv\Scripts\vm-mcp.exe install claude-desktop
.\.venv\Scripts\vm-mcp.exe install cursor
# 只输出配置,不写文件
.\.venv\Scripts\vm-mcp.exe install cursor --print重启客户端后,应该能看到 multi-vm-mcp 提供的 12 个工具。
配置示例
[server]
state_dir = "C:/Users/you/AppData/Local/vmboxs-mcp"
default_command_timeout = 120
command_output_limit = 200000
vnc_host = "127.0.0.1"
log_level = "INFO"
[[vms]]
name = "win11-lab"
provider = "vmware"
path = "D:/VMs/win11-lab/win11-lab.vmx"
os = "windows"
guest_user = "Administrator"
credential = "win11-lab"
console = { vnc_port = 5901, vnc_address = "127.0.0.1", display = 0 }
[[vms]]
name = "ubuntu-lab"
provider = "virtualbox"
uuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
os = "linux"
guest_user = "lab"
credential = "ubuntu-lab"密码不写在配置文件里。vm-mcp credential set 会把密码写入 Windows Credential Manager / macOS Keychain / Linux Secret Service。
工具清单
# | 工具 | 用途 | 是否修改 VM |
1 |
| 配置、Provider 版本、运行状态、Tools、控制台能力 | 否 |
2 |
| 发现 VMware/VirtualBox 虚拟机;可注册进配置 | 仅注册时写配置 |
3 |
| 重新加载配置与凭据,重置控制台连接 | 否 |
4 |
| 获取画面、分辨率与新的 | 否 |
5 |
| 执行一次鼠标/键盘动作,返回新画面 | 是(Guest 输入) |
6 |
| 执行 1–50 个动作,返回最终画面 | 是(Guest 输入) |
7 |
| 向已聚焦输入框粘贴 Unicode/长文本 | 是(Guest 输入) |
8 |
| 输入已保存的用户名/密码,不返回凭据 | 是(Guest 输入) |
9 |
| 通过 Guest Tools 执行命令,返回 | 是(Guest 命令) |
10 |
| 读取同一命令任务的状态与输出 | 否 |
11 |
| 电源、快照、Tools、IP、运行状态 | 电源/快照会修改 VM |
12 |
| 查询电源/快照操作的最终结果 | 否 |
vm_action 的 action
status · start · shutdown · power_off · reboot · pause · resume · suspend · save_state · tools_status · ip · snapshot_list · snapshot_create · snapshot_restore · snapshot_delete
破坏性操作 power_off、snapshot_restore、snapshot_delete 必须显式传入 confirm=true。
工作流
GUI:先观察,再动作
sequenceDiagram
participant AI as AI Agent
participant MCP as multi-vm-mcp
participant VM as VM Console
AI->>MCP: console_observe(vm)
MCP->>VM: 截取当前帧
VM-->>MCP: PNG
MCP-->>AI: image + observation_id
AI->>MCP: console_action(observation_id, click)
MCP->>VM: 注入鼠标
MCP->>VM: 截取动作后的帧
MCP-->>AI: new image + new observation_id规则:
每次 GUI 动作必须使用最新
observation_id。任何动作、快照恢复、电源变化都会让旧编号失效。
出现未知结果时先重新
console_observe,不要盲目重放上一组动作。界面加载较慢时,用
console_batch的interval_ms或动作后重新观察。
命令:job_id 生命周期
stateDiagram-v2
[*] --> running: guest_command
running --> running: command_read(未完成)
running --> succeeded: exit_code = 0
running --> failed: exit_code != 0
running --> timed_out: 超过 timeout_sec长命令原则:继续读同一个 job_id,不要重新执行命令。MCP 重启后仍可用同一 job_id 读取。
电源/快照:operation_id 生命周期
stateDiagram-v2
[*] --> running: vm_action
running --> succeeded: 操作完成
running --> failed: 操作失败
running --> unknown: MCP 重启,无法确认
unknown --> [*]: 先查 lab_status / vm_action status结果不明时不要直接重试,先查询虚拟机当前状态。
给 AI 的使用说明
把 AI_GUIDE.md 交给你的 Agent,它会知道:
12 个工具的参数、返回结构和调用顺序
观察编号、命令任务、VM 操作三套状态机
常见错误码与恢复动作
哪些操作必须先征得用户确认
如何在不泄露密码的前提下完成登录框输入
也可以直接把下面这段放进系统提示词:
You have access to multi-vm-mcp. Always call lab_status first to discover configured VM names.
For GUI work: call console_observe, inspect the returned image, then call console_action or
console_batch with the latest observation_id. Never reuse an observation_id; if you receive
STALE_OBSERVATION, observe again. For commands: use guest_command and poll command_read with
the returned job_id; never re-run a long command. For power/snapshot: use vm_action, then poll
vm_operation_read; if the state is unknown, check the VM state instead of retrying. Ask the user
before destructive actions and pass confirm=true only after approval. Never reveal credentials;
use console_type_saved for saved usernames and passwords.Provider 能力矩阵
能力 | VMware Workstation/Player | VirtualBox |
虚拟机发现 |
|
|
控制台截图 | VNC;失败时降级 |
|
绝对鼠标 | VNC 支持 | Windows COM SDK;依赖 Guest Additions 鼠标集成 |
键盘/快捷键 | VNC keysym |
|
Unicode 粘贴 | Guest 剪贴板助手(需 Tools) |
|
Guest 命令 |
|
|
Guest Tools 状态 |
| Guest Properties |
Guest IP |
| Guest Properties |
电源 |
|
|
快照 |
|
|
内存快照 | 由 VMware 默认策略决定 | 运行中快照默认包含内存状态 |
当前验证范围
VMware Workstation:已在 Windows 宿主机的 CentOS 8 虚拟机上验证 VNC 截图、鼠标移动、批量动作、过期观察拒绝、快照列表。
VirtualBox 7.2:Provider、截图、键盘、Guest 控制、电源与快照代码路径已实现;真实鼠标/键盘和 Guest 命令仍需要在运行中的 VBox 虚拟机上做进一步实测。
Guest 命令:单元测试与命令构造测试通过;真机执行需要配置 Guest 用户名和密码。
测试:
pytest37 项通过,ruff无告警。
安全边界
仅使用 stdio,不监听外部端口;VMware VNC 默认绑定
127.0.0.1。Guest 密码与 VNC 密码存系统 keyring,不写入配置文件、日志或工具返回。
console_type_saved只输入凭据,不返回凭据文本。guest_command等价于在虚拟机内执行任意代码,只应在授权虚拟机上使用。power_off、snapshot_restore、snapshot_delete需要confirm=true。修改前建议先创建快照;恢复快照后必须重新
console_observe。
开发
# 测试
.\.venv\Scripts\python.exe -m pytest -q
# 代码检查
.\.venv\Scripts\ruff.exe check src tests
# 本地启动 MCP Server(stdio)
.\.venv\Scripts\vm-mcp.exe serve项目结构:
src/vm_mcp/
server.py # 12 个 FastMCP 工具
cli.py # init / discover / vm / credential / console / doctor / install
config.py # TOML 配置与路径
credentials.py # 系统 keyring
jobs.py # SQLite 任务与操作存储
models.py # 公共模型与动作校验
errors.py # 结构化错误码
services/lab.py # 观察、任务、操作编排
providers/
base.py # Provider 接口与能力声明
vmware.py # vmrun + VNC
virtualbox.py # VBoxManage + COM
guest_scripts.py # Guest 端 wrapper 生成
console/
vnc.py # VMware VNC 截图与输入
vbox_sdk.py # VirtualBox COM 鼠标注入
vbox_keys.py # VirtualBox scancode 映射
tests/ # 单元测试与 FakeProvider依赖固定为
mcp>=1.9,<2,使用官方 MCP Python SDK 中的 FastMCP API。
Roadmap
ESXi / vCenter Provider(pyvmomi + WebMKS/VNC)
VirtualBox 真机集成测试(Windows/Linux Guest、Guest Additions)
Linux/macOS 宿主机验证
VMware 多显示器截图与显示选择
可选 HTTP 传输与远程部署模式
License
MIT © 2026 ZiYyyun
Available Tools
12 toolscommand_readB
读取同一个命令任务的状态、输出与退出码;MCP 重启后仍可继续读取。
Inputs: job_id (required), wait_sec.
console_actionB
在最新观察上执行一次鼠标或键盘动作,返回动作后的画面与新 observation_id。
Inputs: vm (required), action (required), observation_id (required), format, +1 more.
console_batchA
执行 1-50 个可预期的短动作,返回最终画面与新 observation_id。
Inputs: vm (required), actions (required), observation_id (required), format, +3 more.
console_observeB
获取虚拟机当前画面、分辨率与 observation_id。后续动作必须使用该编号。
Inputs: vm (required), format, max_width.
console_pasteB
向已聚焦的输入框粘贴 Unicode/长文本;submit=true 时在末尾回车。
Inputs: vm (required), text (required), observation_id (required), mode, +3 more.
console_type_savedB
向已聚焦的登录框输入保存的用户名或密码;结果不会返回凭据文本。
Inputs: vm (required), field (required), observation_id (required), format, +2 more.
guest_commandA
通过 Guest Tools 执行命令,返回 job_id;未完成时用 command_read 继续读取。
Inputs: vm (required), command (required), cwd, env, +3 more.
lab_reloadA
重新加载配置与凭据,关闭旧控制台连接;之后必须重新 console_observe。
Inputs: no named parameters.
lab_statusC
查看已配置虚拟机、Provider 安装状态、运行状态、Guest Tools 与控制台能力。
Inputs: vm.
vm_actionC
电源、快照、Tools 与 IP 操作。修改类动作返回 operation_id。
action: status | start | shutdown | power_off | reboot | pause | resume | suspend | save_state | tools_status | ip | snapshot_list | snapshot_create | snapshot_restore | snapshot_delete。
Inputs: vm (required), action (required), force, confirm, +5 more.
vm_discoverC
发现 VMware / VirtualBox 虚拟机;register=true 时把发现的虚拟机追加到配置。
Inputs: register, providers, search_paths.
vm_operation_readA
查询电源或快照操作的最终状态;结果不明时先查虚拟机状态,不要直接重试。
Inputs: operation_id (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
Each tool targets a distinct capability: console observation/action/batch/paste/type, guest command execution vs. reading, VM power/snapshot actions vs. reading operation results. The only soft overlaps are console_action vs console_batch (granularity, but the 1-50 range makes the split clear) and vm_action action=status vs lab_status, which descriptions largely resolve.
Consistent snake_case with category prefixes (console_*, lab_*, vm_*) and a predictable *_read pair for async results. Minor deviation: command_read pairs with guest_command rather than sharing a prefix, so its association is slightly less obvious.
Twelve tools is well within the sweet spot, and every tool earns its place: separate observe/action flows, a batch variant for latency, a saved-credential variant for security, and explicit async read-backs for commands and operations.
The surface covers discovery, config reload, health/status, console interaction, guest execution, and power/snapshot lifecycle with proper async read-back, avoiding dead ends after MCP restarts. Minor gaps remain: no guest file transfer or clipboard read, and no explicit unregister/remove for discovered VMs (only register via vm_discover).
Maintenance
Related MCP Connectors
Remote desktop MCP: let AI see, click, type and run terminal commands on your own Windows or Mac.
Remote MCP server to control your Android phone from AI assistants with per-app permissions.
Remote MCP access to user-authorized Linux, Windows and Intel Mac devices for AI assistants.
Remote MCP server exposing your Node Command fleet (files, shell, processes, browser) to AI hosts.
Related MCP Servers
- AlicenseAqualityDmaintenanceAn MCP server that allows AI agents to remotely control Windows, Linux, and macOS systems via VNC. It provides tools for mouse and keyboard interaction, text input, and screen capturing.62,259 npm62MIT
- AlicenseNot gradedqualityCmaintenanceAn MCP server that gives AI agents direct control over QEMU virtual machines.1MIT
- AlicenseBqualityDmaintenanceA stdio MCP server that controls VMware Workstation via vmrun, enabling VM lifecycle management and snapshot operations.14MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that gives an LLM full control over a VMware-hosted Windows VM: lifecycle, snapshots, remote execution, file transfer, and kernel debugging.MIT