创建venv:
uv venv应用虚拟环境:
source .venv/bin/activate安装ansible:
uv pip install ansible -i https://mirrors.ustc.edu.cn/pypi/simple安装基础环境
ansible-playbook playbooks/setup_kvm.yaml安装libvirt开发包:
yum config-manager --set-enabled crb
yum install epel-release
yum install libvirt-devel gcc同步环境:
cd path/to/fetch_time
uv sync配置.env文件:
API_KEY="" // LLM API Key
API_URL="https://api.siliconflow.cn" // LLM API Server
LLM_MODEL="Qwen/Qwen3-30B-A3B" // LLM MODEL
DEBUG=false
LIBVIRT_SERVER = "qemu+ssh://root@192.168.85.10/system" // Libvirt Server, 默认为qemu:///system
LIBVIRT_HOST = "192.168.85.10" // Libvirt Server 服务器IP
LIBVIRT_USER = "root" // Libvirt Server 连接用户
LOG_LEVEL = "WARNING"配置MCP Server与Libvirt Server免密:
ssh-keygen -t rsa -N "" -f /root/.ssh/id_rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.85.10命令行使用:
# 查看帮助
usage: cli.py [-h] {console,hostinfo,net,bridge,pool,vm,vol} ...
Libvirt CLI Tool
positional arguments:
{console,hostinfo,net,bridge,pool,vm,vol}
console Attach to VM console
hostinfo Host related operations
net Net related operations
bridge Bridge related operations
pool Storage pool related operations
vm Virtual machine related operations
vol Volumes related operations
options:
-h, --help show this help message and exit
# 连接console:
[root@localhost ~]# python cli.py console rocky9-by-cli-create
Escape character is ^] (CTRL+])
[root@test ~]#启动MCP Server:
uv run server.py命令行使用:
uv run main.py客户端对接:
工具一览表:
启用MCP服务器:
简单聊天测试:
测试工具调用:
