Skip to main content
Glama

Hyper-V MCP

通过 Model Context Protocol(stdio)管理 Windows Hyper-V 虚拟机,支持 Windows 和 Ubuntu 客户机。虚拟机生命周期和检查点操作通过 Hyper-V PowerShell 完成;Windows 客户机支持 PowerShell Direct,Ubuntu 客户机通过 SSH 连接。

功能

  • 列出虚拟机,查看状态、网卡和 IP;启动、正常关机、暂停、恢复、保存和重启。

  • 创建、列出、恢复和删除 Hyper-V 检查点。

  • 在客户机执行命令、列目录、查看进程,以及在本机与客户机间传输文件。

  • 宿主机可为本机 Hyper-V,或通过 SSH 连接的远程 Windows Hyper-V 宿主机。

**注意:**MCP 客户端可以运行命令、停止虚拟机和恢复检查点。只将本服务接入可信的客户端,先在测试环境验证。恢复检查点会回滚数据;操作超时不代表远程进程已停止。

Related MCP server: Ubuntu Fleet Manager

要求

  • Node.js 20 或更高版本及 Windows OpenSSH 客户端。

  • Windows Hyper-V 宿主机,运行服务的宿主机账户必须具备 Hyper-V 管理权限;远程宿主机需能通过非交互式 SSH 连接。

  • Windows PowerShell Direct 需要支持该功能的 Windows 宿主机和 Windows 客户机、正在运行的虚拟机及有效的客户机凭据;无需客户机联网。

  • Ubuntu 客户机需要安装并运行 SSH 服务、网络可达、配置 SSH 密钥和预先验证的主机密钥。支持跳板机。

安装和配置

npm ci
Copy-Item config.example.json config.json

按实际情况编辑 config.json。host.mode 为 local 时,Hyper-V 操作在本机执行;使用远程宿主机时,例如:

"host": { "mode": "ssh", "host": "hyperv.example.com", "user": "Administrator", "port": 22, "key": "C:/path/to/host-key" }

guests 中的键为 Hyper-V 虚拟机名称。Ubuntu 的 host、user、key 为客户机 SSH 信息,可设置 proxy_jump,例如 Administrator@hyperv.example.com。SSH 从运行 MCP 的电脑发起。首次连接请先手动核对并保存 SSH host key。配置文件不包含明文密码;不要提交真实配置或密钥。

Windows transport: direct 的 password_file 是通过 Windows DPAPI(CurrentUser)加密的密码文件。运行 Hyper-V PowerShell 的用户必须与生成文件的用户相同;远程宿主机模式下文件必须位于远程宿主机。可在对应用户会话中生成:

$secure = Read-Host 'Windows guest password' -AsSecureString
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try {
  $bytes = [Text.Encoding]::Unicode.GetBytes([Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr))
  Add-Type -AssemblyName System.Security
  $encrypted = [Security.Cryptography.ProtectedData]::Protect($bytes, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser)
  [IO.File]::WriteAllText('C:\path\to\guest-password.dpapi', [Convert]::ToBase64String($encrypted))
} finally {
  if ($bytes) { [Array]::Clear($bytes, 0, $bytes.Length) }
  [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr)
}

服务默认读取目录下的 config.json;也可设置 HYPERV_MCP_CONFIG 指向其他配置。配置变更后重启 MCP 进程。

Codex 配置

codex mcp add hyperv -- node C:\path\to\Hyper-V-MCP\index.mjs

其他支持 stdio 的 MCP 客户端可将 node 作为命令,index.mjs 的绝对路径作为参数。路径包含空格时请按客户端要求分别传递参数。

限制

  • Ubuntu 命令和文件操作使用 SSH,不是免网络的 Hyper-V 客户机执行通道。

  • Windows Direct 文件传输目前仅支持本机 Hyper-V 宿主机;远程宿主机上的 Direct 文件传输未实现。

  • 截图和鼠标键盘控制尚未实现。vm_get_ip 依赖 Hyper-V 集成服务,可能无法返回客户机 IP。

  • SSH 文件传输使用 SCP/SFTP,local_path 是运行 MCP 的电脑上的路径。请先使用小文件确认服务端及路径兼容性。

  • 客户机连接信息不会因 IP 地址变化自动发现,应根据自己的网络配置稳定地址或名称。

验证

npm test

测试覆盖配置解析和命令编码等基础行为;完整功能需要在有适当权限的 Hyper-V 宿主机及目标客户机上验证。

Tool Schema Changelog

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

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables controlled Hyper-V virtual machine operations over MCP, including status queries, checkpoints, in-guest command execution, and file transfers, without requiring guest networking or WinRM.
      1
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables administering Ubuntu hosts through MCP over stdio, currently exposing a read-only get_system_info tool that reports OS release, hostname, kernel, architecture, memory, and root filesystem capacity.
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables policy-gated control of Hyper-V virtual machines on Windows through a single local stdio server, covering VM inventory, power, checkpointing, PowerShell Direct guest diagnostics and file transfer, synthetic keyboard/mouse console input, serial consoles, ISO media mounting, and serial WinDbg preparation. Every mutation requires an explicit VM allowlist and per-capability flag, with read-only operation as the default.
      44
      MIT
    • A
      license
      Not graded
      quality
      F
      maintenance
      Enables agents to manage headless virtual machines and hypervisors, including listing VMs, inspecting VM details, managing snapshots, listing networks, reporting host information, and running sandboxed code through MCP tools.
      Apache 2.0