使用说明
一个简单的mcp服务器充当AI和串行端口之间的桥梁
概述
有时,你希望AI在虚拟机内执行命令。工具如 vmrun 可以从主机运行命令,但对于交互式程序(例如具有自己CLI的gdb)来说,它们很笨拙,而且您无法看到实时输出。SerialPort MCP解决了这个问题。在您向VM添加串行端口并在VM内启用串行控制台后,此MCP将公开读写服务,以便您的AI可以实时与VM交互。这不仅限于运行命令。您可以让AI登录、运行命令并实时查看输出,例如调试进程、设置断点和观察其行为。(但根据您的工作流程,您可能需要额外的技能)
步骤1:向VM添加串行端口
在VMware中: VMWare -> VM -> Settings -> Hardware那么 Add,选择 Serial Port.
Linux
选择 Socket,示例文件名: /tmp/citrix0方向: Server -> VM (主机充当服务器,然后在主机上使用socat将套接字绑定到PTY)。
视窗
选择 Named pipe,示例文件名: \\.\pipe\latest-citrix-vm-serial方向: This end is the server, The other end is an application.
步骤2:在VM内启用串行控制台
类似FreeBSD的系统示例:
对于BSD系统,您通常会编辑 loader.conf,可能在 /boot/loader.conf 或 /flash/boot/loader.conf.
添加这些线(必要时调整速度):
boot_serial="YES"
comconsole_speed="9600"
boot_multicons="YES"
console="comconsole,vidconsole"
步骤3:运行串行端口MCP
Linux
使用socat创建PTY桥:
socat -d -d pty,raw,echo=0,link=/tmp/vmconsole UNIX-CONNECT:/tmp/citrix0
然后将SerialPort MCP添加到MCP配置中(示例 ~/codex/config.toml):
[mcp_servers.SerialPortMCP]
type = "stdio"
command = "<PATH TO PYTHON>"
args = ["<Path to vmconsole_mcp.py>", "--pipe-style", "linux", "--tty-path", "/tmp/vmconsole"]
改变 --tty-path 以匹配您的socat PTY路径。然后重新启动codex。
视窗
将串行端口MCP添加到MCP配置中(示例 ~/codex/config.toml):
[mcp_servers.SerialPortMCP]
type = "stdio"
command = "<PATH TO PYTHON>"
args = [
"<Path to vmconsole_mcp.py>",
"--pipe-style", "windows",
"--tty-path", "\\\\.\\pipe\\latest-citrix-vm-serial"
]
改变 --tty-path 以匹配您命名的烟斗。然后重新启动codex。
工具
tty_status查询当前pty路径和状态tty_set_path切换pty路径tty_read读取数据- args:
max_bytes(默认值:4096),timeout_ms(默认值:120),encoding(utf-8/latin-1/hex)
- args:
tty_write写入数据- args:
data,append_newline(默认值:false),encoding(utf-8/hex)
- args:
tty_control发送控制字符- args:
key(c-c,c-z,c-d,esc,tab,enter,return,lf,backspace),repeat(可选)
- args:
