
Qemu Mcp
io.github.0xmortuex由 GitHub 账号 0xmortuex 发布v0.1.0更新于 Nov 7, 2026
Boot and drive QEMU VMs from an AI agent: keys, screenshots, serial. No guest agent.
概览
让 AI 助手以无头方式启动 QEMU 虚拟机,并通过按键、截图和串口控制台输入输出进行操控,无需客户机代理。
- 可以做什么
- 启动与管理虚拟机:从 ISO、内核或磁盘启动任意受支持架构的虚拟机,列出运行中的虚拟机,并暂停、恢复和停止
- 创建磁盘镜像,并保存、加载、列出或删除 qcow2 快照
- 向客户机发送输入:输入文本、按键与组合键、移动并点击鼠标
- 读写串口控制台,并等待特定文本出现或画面稳定
- 截取 VGA 帧缓冲的 PNG 截图
- 更换可移动介质,并执行任意 QMP 命令
- 适用场景
- 适合操作系统与内核开发者,让助手完成“编辑—构建—启动—查看”的闭环并自行启动测试改动;也适合需要助手在操作系统之下操作引导程序、安装镜像、BIOS/UEFI 菜单、恢复控制台或固件的场景。
- 运行要求
- 需要 Python 3.10+ 以及安装在 PATH 中的 QEMU(Windows 上会自动查找默认安装目录,或设置 QEMU_DIR)。以本地 stdio 进程运行;未声明需要账号、API 密钥或网络访问。
安装
在 SourceWeft 中
- 打开 控制台中的 Qemu Mcp,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
qemu-mcp
Let your AI agent boot an operating system and drive it.
qemu-mcp is an MCP server that gives AI agents (Claude Code, or any MCP client) hands on a QEMU virtual machine: boot an ISO or a raw kernel, press keys, take screenshots, read the serial console, and wait for boot markers — all headless, with zero cooperation from the guest. No SSH, no guest agent, no network. If it boots in QEMU, an agent can drive it.
[MORT OS terminal after the agent typed help — captured through qemu-mcp]
This screenshot was taken by an AI agent: it booted MORT OS (a hobby kernel with no SSH, no agent, no TCP required) headless, pressed Esc, typed help, and captured the framebuffer — four tool calls.
Who this is for
OS developers and hobby kernel hackers. The osdev inner loop is: edit kernel → build → boot in QEMU → look at the screen → type something → read serial → repeat. An AI agent can already do the edit and build steps; qemu-mcp gives it the rest of the loop, so it can boot-test its own kernel changes and actually see the triple fault.
It's equally useful for anyone who needs an agent to poke at a VM below the OS level: bootloaders, installers, BIOS/UEFI menus, recovery consoles, firmware.
Why another QEMU MCP server?
The existing ones assume a full, running guest OS — they exec commands over SSH or a guest agent. That's useless when your guest is a 40 KB kernel you wrote yourself, an installer ISO, or anything pre-boot. qemu-mcp is built for the boot-test loop instead:
- Serial console capture — continuously logged to a file, readable at any time (
qemu_serial), and writable too (qemu_serial_send) qemu_wait_serial— block until"kernel ready"(or"login:", or your panic string) appears, the reliable way to sequence an automated boot test-kernelboot — boot a multiboot/bzImage kernel directly, withappend/initrd- Screenshots of the VGA framebuffer — works headless, shows exactly what a monitor would
- Raw QMP escape hatch — the full QEMU Machine Protocol when you need
memsave,system_reset,device_add…
Tools
Multiple named VMs can run at once.
Every tool declares all four MCP behaviour hints, so your client knows which calls to
confirm with you. Only the waiting and reading tools (qemu_screenshot, qemu_serial,
qemu_wait_serial, qemu_wait_screen, qemu_snapshot_list, qemu_version) are
read-only. qemu_boot and qemu_list are marked destructive because they clean up VMs
that exited on their own, deleting their serial logs; read a crashed guest's output with
qemu_serial first. qemu_boot and qemu_qmp are open-world: extra_args and raw QMP
can reach anything QEMU can.
Install
Requirements: Python 3.10+, and QEMU on your PATH (on Windows, C:\Program Files\qemu is found automatically, or set QEMU_DIR).
Claude Code:
Any other MCP client (stdio transport):
Or without installing, via uv: claude mcp add qemu -- uvx qemu-mcp
Example session
you: boot build/os.iso and check the shell works
agent:
qemu_boot(name="test", iso="build/os.iso", arch="i386")→ bootedqemu_wait_serial(name="test", text="boot ok")→ FOUNDqemu_type(name="test", text="help\n")qemu_screenshot(name="test")→ sees the help output renderedqemu_stop(name="test", force=true)"Your ISO boots, the shell responds tohelp, and the new command is listed. Screenshot attached."
A typical kernel test the agent can run by itself:
Non-x86 archs
x86_64 and i386 boot with no machine argument. Other archs have no
default machine in QEMU and need -M set explicitly, or they'll fail to
boot:
Check qemu-system-<arch> -M help for the full list of machines an arch supports.
virt has no default display device — unlike the PC-family boards x86_64/
i386 boot with, it doesn't wire up VGA on its own. qemu_screenshot/
qemu_wait_screen against a virt VM will see an empty/black framebuffer (or
a QMP error, depending on QEMU version) unless the guest itself sets one up,
which most bare-metal aarch64/riscv64 kernels don't. Add a display device
explicitly if you need screenshots:
(This is documented QEMU virt-board behavior, not verified against a real
boot in this environment — no QEMU available here.)
Hardware acceleration
qemu_boot defaults to TCG (QEMU's software emulator) with no accel given -
correct on any host, but a real slowdown for anything beyond a trivial kernel.
Opt into your host's accelerator with accel, falling back to TCG if it's
unavailable so the boot doesn't hard-fail on a host without it:
If the requested accelerator genuinely isn't usable on the host (no /dev/kvm
permission, virtualization disabled in firmware, etc.) QEMU itself reports why
QEMU exited, and qemu_boot surfaces that in the error it raises.
CPU model
qemu_boot defaults to QEMU's own default CPU model for the arch/machine.
Pass cpu (QEMU -cpu) to test guest code against a specific model or
feature set instead:
Check qemu-system-<arch> -cpu help for the full list of models/features an
arch supports.
CPU topology
smp alone sets a flat vCPU count. For guest code that cares about the
socket/core/thread shape (ACPI MADT entries, CPUID topology leaves,
per-socket vs. per-core scheduling), pass smp_cores/smp_threads/
smp_sockets/smp_maxcpus too - they're combined onto the same -smp flag:
smp itself is optional when the topology params are given - QEMU can infer
the total CPU count from cores/threads/sockets.
Host port forwarding
To reach a guest service (SSH, a web server under test) from the host without
needing QEMU's NIC/chipset flags, pass hostfwd (QEMU's hostfwd rule):
This adds -netdev user,id=net0,hostfwd=... and -device e1000,netdev=net0
for you - the guest needs its own e1000 driver, which most general-purpose
OSes (Linux included) already have built in. For a bare-metal kernel with its
own NIC driver (like the rtl8139 example above), use extra_args instead -
hostfwd is for forwarding a port to a guest that already has working
networking, not for picking which NIC a from-scratch kernel talks to.
Debugging the kernel
qemu-mcp lets an agent see a crash. To find out why it happened, pair it with gdbstub-mcp. Boot with QEMU's gdbstub on and an interrupt log:
Then the agent can debug_connect with the kernel ELF, set breakpoints on symbols
or file.c:line, read registers and memory, and get backtraces. If the VM triple
faults, debug_explain_fault turns int.log into the exception chain and its root
cause. No gdb binary is needed.
Tests
Unit tests for the character/key-name -> QMP qcode translation in keys.py,
the screen-fraction -> QMP pointer-event translation in mouse.py, the
serial chardev args and reconnect logic in serial.py, the framebuffer
stability tracker in screen.py, the snapshot tag validation and HMP
command-line building in snapshot.py, the QMP client's error handling in
qmp.py, the missing-binary error path, the __version__/pyproject.toml
version-drift guard in test_version.py, the pinned tool behaviour hints
(readOnlyHint/destructiveHint/idempotentHint/openWorldHint) in
test_tool_hints.py, and an MCP stdio handshake smoke test all need no QEMU
install - this is what CI runs on every push:
There's also an end-to-end test that boots a real ISO and exercises every tool:
qemu_snapshot_save/qemu_snapshot_load need a qcow2 disk rather than an
ISO, so they're only exercised if you also set QEMU_MCP_TEST_QCOW2 to a
qcow2 disk image (booted as a second VM alongside the ISO one).
Notes
- VMs run headless (
-display none); screenshots still work because QEMU keeps rendering the VGA framebuffer. - Serial output requires the guest to write to COM1 (most hobby kernels and all Linux
console=ttyS0setups do). Guests that only draw to VGA are still fully drivable via screenshots + keys. qemu_stoptries ACPI powerdown first; hobby kernels usually ignore it and get killed after a grace period — useforce=trueto skip the wait, or raisegraceful_timeout_s(default 10s) for a guest that legitimately needs longer to shut down cleanly.qemu_stopwaits briefly (up to 5s, best-effort) for any in-flightqemu_wait_serial/qemu_wait_screen/qemu_screenshot/qemu_serial_send/qemu_qmp/qemu_change_media/qemu_type/qemu_key/qemu_mouse/qemu_pause/qemu_resume/qemu_snapshot_save/qemu_snapshot_load/qemu_snapshot_delete/qemu_snapshot_listcall against the same VM to finish before closing its QMP/serial connections and removing its temp directory, so a call racing a concurrent stop sees a clean result instead of an error from a handle closed out from under it.- This server launches QEMU processes on your machine with files you point it at.
extra_argsis passed to QEMU verbatim — same trust level as running QEMU yourself.
Changelog
See CHANGELOG.md.
Contributing
See CONTRIBUTING.md for the exact local setup and checks CI runs.
License
MIT
来源:README.md,提交 d3c0731
工具
0版本历史
1- v0.1.0最新Nov 7, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分