使用说明
vSphere MCP服务器
用于VMware vSphere基础架构管理的MCP服务器。通过模型上下文协议提供对vSphere环境的全面访问。
特性
- 无缝身份验证:基于域的凭据缓存,带有GUI提示
- 虚拟机管理:列出、检查和控制虚拟机
- 基础设施监控:监视主机、数据中心和数据存储
- 网络发现:探索网络并提取VLAN信息
- 组织工具:浏览文件夹和组织结构
- 安全凭证存储:macOS钥匙链与TTL集成
安装
来自PyPI(推荐)
pip install vsphere-mcp-server
来源
# Clone the repository
git clone https://github.com/rorymcmahon/vsphere-mcp-server.git
cd vsphere-mcp-server
# Install dependencies
pip install -r requirements.txt
# Install in development mode
pip install -e .
配置
添加到MCP客户端配置中:
{
"mcpServers": {
"vsphere": {
"command": "python",
"args": ["-m", "vsphere_mcp_server.server"]
}
}
}
可用工具
认证
vsphere_clear_credentials(hostname)-清除域的缓存凭据
虚拟机管理
list_vms(hostname)-列出所有VM及其基本信息get_vm_details(hostname, vm_id)-详细的VM配置power_on_vm(hostname, vm_id)-打开VM电源power_off_vm(hostname, vm_id)-关闭VM电源
基础设施管理
list_hosts(hostname)-列出ESXi主机get_host_details(hostname, host_id)-主机详细信息list_datacenters(hostname)-列出数据中心get_datacenter_details(hostname, datacenter_id)-数据中心详细信息list_datastores(hostname)-列出具有容量的数据存储get_datastore_details(hostname, datastore_id)-数据存储详细信息
组织
list_folders(hostname, folder_type)-按类型列出文件夹get_folder_details(hostname, folder_id)-文件夹详细信息
网络
list_networks(hostname)-列出带有VLAN信息的网络get_network_details(hostname, network_id)-网络详细信息list_vlans(hostname)-从网络名称中提取VLAN信息
使用示例
基本VM操作
# List all virtual machines
list_vms("vcenter.domain.local")
# Get detailed VM information
get_vm_details("vcenter.domain.local", "vm-123")
# Power operations
power_on_vm("vcenter.domain.local", "vm-123")
power_off_vm("vcenter.domain.local", "vm-123")
基础设施监控
# Check datastore capacity
list_datastores("vcenter.domain.local")
# Monitor host status
list_hosts("vcenter.domain.local")
get_host_details("vcenter.domain.local", "host-456")
网络发现
# Explore network configuration
list_networks("vcenter.domain.local")
# Extract VLAN information
list_vlans("vcenter.domain.local")
凭证管理
# Clear stored credentials if needed
vsphere_clear_credentials("vcenter.domain.local")
认证
服务器使用基于域的凭据缓存:
- 首先使用:GUI提示输入用户名和密码
- 凭据存储:存储在macOS钥匙串中,TTL为4小时
- 自动续订:凭据过期时重新提示
- 域提取:
vcenter.domain.local→domain.local
支持的用户名格式
username@domain.localdomain\username(转换为@格式)username(自动附加域)
安全
- 安全存储在macOS钥匙串中的凭据
- 4小时TTL可防止过时的凭据使用
- 默认情况下禁用SSL验证(在企业环境中很常见)
- 用于API身份验证的会话令牌
- 退出时自动清理会话
错误处理
服务器提供清晰的错误消息和故障排除步骤:
- 身份验证错误:建议清除凭据
- 连接错误:表示网络/主机名问题
- API错误:显示特定的vSphere API响应
发展
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black src/ tests/
isort src/ tests/
# Type checking
mypy src/
故障排除
身份验证问题
- 清除凭据:
vsphere_clear_credentials("hostname") - 验证用户名格式是否包含域
- 检查vCenter的网络连接
连接问题
- 验证主机名是否可访问
- 检查vCenter是否正在运行且可访问
- 确认SSL/TLS配置
权限问题
- 验证用户是否具有所需的vSphere权限
- 检查vCenter中的角色分配
- 确保用户可以访问所需的对象
许可证
MIT许可证-有关详细信息,请参阅许可证文件。