虚拟化管理工具

一个用于管理和操作虚拟机的命令行工具,支持虚拟机的创建、网络配置、存储池管理等操作。

  • by RyrieNorth
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 ryrienorth/mcp-libvirt

使用说明

创建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服务器:

简单聊天测试:

测试工具调用: