KVM MCP Server
A JSON-RPC server that simplifies managing KVM virtual machines by providing a centralized interface for VM lifecycle, networking, storage, and display management tasks.
README
KVM MCP Server
A powerful JSON-RPC server for managing KVM virtual machines through a simple and intuitive interface. This server provides a centralized way to control and monitor your KVM virtual machines using a standardized protocol.
Why This Project?
Managing KVM virtual machines typically requires using multiple command-line tools like virsh, virt-install, and qemu-system. This project aims to:
- Simplify VM Management: Provide a single, unified interface for all VM operations
- Enable Remote Control: Allow remote management of VMs through JSON-RPC
- Automate VM Operations: Make it easy to script and automate VM management tasks
- Standardize VM Configuration: Ensure consistent VM setup across your infrastructure
Features
-
VM Lifecycle Management:
- Create new VMs with customizable parameters
- Start/stop/reboot VMs
- List all available VMs with their status
-
Network Management:
- Configure VM networking using bridges
- Support for the
brforvmsbridge - Automatic network interface configuration
-
Storage Management:
- Configurable VM disk storage location
- Support for various disk formats (qcow2)
- Configurable disk sizes
-
Display Management:
- VNC support for graphical access
- Automatic VNC port assignment
- Tools to find and connect to VM displays
-
Installation Support:
- Network installation from ISO images
- Local installation from CDROM
- Support for various OS variants
-
Performance Optimizations:
- Connection pooling for libvirt to reduce connection overhead
- VM information caching for improved responsiveness
- Asynchronous processing for better concurrency
- Advanced logging for diagnostics and troubleshooting
- Graceful shutdown handling for proper resource cleanup
Configuration
The server uses a JSON configuration file (config.json) to store default values and paths. This makes the server more portable and easier to customize. The configuration includes:
{
"vm": {
"disk_path": "/vm", // Where VM disks are stored
"default_iso": "/iso/ubuntu-24.04.2-live-server-amd64.iso", // Default installation media
"default_name": "puppy", // Default VM name
"default_memory": 2048, // Default memory in MB
"default_vcpus": 2, // Default number of vCPUs
"default_disk_size": 20, // Default disk size in GB
"default_os_variant": "generic", // Default OS variant
"default_network": "brforvms" // Default network bridge
}
}
You can modify these values to match your environment's requirements.
Getting Started
Prerequisites
- Python 3.6 or higher
- KVM and libvirt installed on the host system
- The network bridge configured (default:
brforvms) - VM storage directory created (default:
/vm/)
Installation
-
Clone this repository:
git clone https://github.com/yourusername/kvm-mcp.git cd kvm-mcp -
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt -
Configure the server:
- Edit
config.jsonto match your environment - Ensure all required directories exist
- Verify network bridge configuration
- Edit
Usage
-
Start the server:
python3 kvm_mcp_server.py -
Send commands using JSON-RPC. Example scripts are provided:
create_vm.sh: Create a new VM using default configurationget_vnc_ports.sh: Find VNC ports for running VMs
Performance Tuning
Connection Pooling
The server uses a connection pool for libvirt to reduce the overhead of repeatedly opening and closing connections. You can configure the pool size in the code:
connection_pool = LibvirtConnectionPool(max_connections=5, timeout=30)
Caching
VM information is cached to reduce repeated queries to libvirt. The cache has configurable settings:
vm_info_cache = VMInfoCache(max_size=50, ttl=60) # Cache up to 50 VMs with 60-second TTL
To bypass the cache when needed, add the no_cache parameter to your requests:
{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "list_vms", "arguments": {"no_cache": true}}, "id": 1}
Logging
Logging is configured to help diagnose performance issues. Logs are rotated automatically:
kvm_mcp.log # Current log file
kvm_mcp.log.1 # Previous log file
Example Commands
Create a New VM
./create_vm.sh
This will create a new VM using the default configuration from config.json. You can override any of these defaults by providing them in the request.
Find VNC Ports
./get_vnc_ports.sh
This will show all running VMs and their VNC ports, making it easy to connect to their displays.
Project Structure
kvm_mcp_server.py: Main server implementationconfig.json: Configuration filerequirements.txt: Python dependencies- Example scripts in the root directory
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。