VMware MCP服务器
一个干净、专注的模型上下文协议(MCP)服务器,用于使用pyvmomi进行VMware vCenter管理。
🚀 特性
- 虚拟机管理:列出、创建、打开/关闭虚拟机
- 主机监控:物理主机信息和健康状况
- 性能指标:CPU、内存、磁盘、网络监控
- 快速REST API:快速VM列表和操作
- 多种运输方式:STDIO(鹅)、SSE(n8n)、HTTP(网络)
- 模块化设计:干净、可维护的代码结构
安装
🚀 特性
- VM列表:列出所有VM的详细信息(电源状态、IP、CPU、内存、网络适配器)
- 电源管理:按名称打开/关闭虚拟机
- VM创建:使用完全自定义的模板(IP、主机名、CPU、内存、磁盘)创建新的虚拟机
- MCP标准操作协议:与MCP客户端完全兼容
- Docker支持:易于部署和测试
🏛️ 项目结构
vmware-mcp-server/
├── mcp-server/ # Python logic only
│ ├── server.py # MCP server with stdio protocol
│ ├── vm_info.py # VM listing and information
│ ├── power.py # Power management (on/off)
│ ├── vm_creation.py # VM creation from templates
│ └── test_server.py # Test script
├── requirements.txt # Python dependencies (pyvmomi)
├── pyproject.toml # Project configuration
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── Makefile # Build and run targets
├── env.example # Environment variables template
└── README.md # This file🔧 设置
先决条件
- Python 3.10+
- VMware vCenter访问
- Docker(可选)
环境变量
创建一个 .env 文件基于 env.example:
VCENTER_HOST=your-vcenter-host
VCENTER_USER=your-username
VCENTER_PASSWORD=your-password
VCENTER_INSECURE=true # Set to "true" for self-signed certificates
# MCP Transport Configuration
MCP_TRANSPORT=stdio # Options: stdio, sse, http
MCP_HOST=127.0.0.1 # For sse/http modes
MCP_PORT=8000 # For sse/http modes🚀 快速开始
使用Docker(推荐)
# Setup environment
make setup
# Build and run
make build
make run-docker
# Or run detached
make run-detached
# Test the server
make test-docker使用本地Python
# Install dependencies
make install
# Run locally
make run
# Test locally
make test🌐 运输方式
VMware MCP Server支持用于不同用例的多种传输协议:
STDIO模式(默认)
- 用例:本地工具,如Goose
- 配置:
MCP_TRANSPORT=stdio(默认) - 命令:
python mcp-server/server.py
SSE模式(服务器发送事件)
- 用例:像n8n这样的Web客户端
- 配置:
MCP_TRANSPORT=sse - 命令:
python mcp-server/server.py - 访问:
http://127.0.0.1:8000
HTTP模式
- 用例:Web部署和API
- 配置:
MCP_TRANSPORT=http - 命令:
python mcp-server/server.py - 访问:
http://127.0.0.1:8000/mcp
运输环境变量
# Transport mode (stdio, sse, http)
MCP_TRANSPORT=stdio
# Network configuration (for sse/http modes)
MCP_HOST=127.0.0.1
MCP_PORT=8000
MCP_PATH=/mcp # Only for http mode📋 可用的MCP工具
1.列出虚拟机(list_vms)
列出vCenter中的所有VM及其详细信息。
请求:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list_vms",
"arguments": {}
}
}2.打开虚拟机电源(power_on_vm)
按名称启动VM。
请求:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "power_on_vm",
"arguments": {
"vm_name": "my-vm"
}
}
}3.关闭VM电源(power_off_vm)
按名称关闭VM。
请求:
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "power_off_vm",
"arguments": {
"vm_name": "my-vm"
}
}
}4.从模板创建VM(create_vm_from_template)
从具有完全自定义的模板创建新VM。
请求:
{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "create_vm_from_template",
"arguments": {
"template_name": "ubuntu-template",
"vm_name": "new-vm",
"hostname": "new-vm",
"ip_address": "192.168.1.100",
"netmask": "255.255.255.0",
"gateway": "192.168.1.1",
"network_name": "VM Network",
"cpu_count": 2,
"memory_mb": 2048,
"disk_size_gb": 20,
"datastore_name": "datastore1"
}
}
}🎯 如何提示MCP服务器
以下是可用于MCP服务器的示例提示:
列出所有虚拟机
List all virtual machines in vCenter电源管理
Power on the VM named "ubuntu-server"Power off the VM named "test-vm"创建新VM
Create a new VM named "web-server" from the "ubuntu-template" with IP address 192.168.1.50, 4 CPUs, 8GB RAM, and 50GB disk🛠️ 发展
可用生成目标
make help # Show all available commands
make setup # Create .env file from template
make install # Install Python dependencies
make run # Run server locally
make test # Test server locally
make build # Build Docker image
make run-docker # Run server in Docker
make test-docker # Test server in Docker
make stop # Stop Docker containers
make clean # Clean up Docker resources
make logs # View Docker logs
make docker-shell # Start shell in Docker container测试
# Test locally
make test
# Test in Docker
make test-docker
# Start interactive shell for manual testing
make docker-shell🔍 故障排除
连接问题
- 验证vCenter凭据是否正确
- 检查vCenter的网络连接
- 对于自签名证书,设置
VCENTER_INSECURE=true
VM创建问题
- 确保模板VM存在并且可访问
- 验证网络和数据存储名称是否正确
- 检查目标IP地址是否在网络上可用
电源管理问题
- 验证VM名称是否存在
- 检查VM是否未处于锁定状态
- 确保您有足够的权限
📄 许可证
该项目根据MIT许可证获得许可。
