vSphere MCP服务器
使用Python构建的VMware vSphere/ESXi集成MCP(模型上下文协议)服务器 fastmcp 图书馆和 pyVmomi此服务器为AI代理提供了用于管理和监视VMware基础架构的工具。
Docker快速入门
拉动并奔跑
docker pull ghcr.io/presidio-federal/vsphere-mcp:latest
docker run -d \
--name vsphere-mcp \
-p 3012:3012 \
-e VSPHERE_HOST=vcenter.example.com \
-e VSPHERE_USERNAME=administrator@vsphere.local \
-e VSPHERE_PASSWORD=your-password \
-e DISABLE_JWT_AUTH=true \
ghcr.io/leevanginkel/vsphere-mcp:latest
Docker Compose
version: '3.8'
services:
vsphere-mcp:
image: ghcr.io/leevanginkel/vsphere-mcp:latest
container_name: vsphere-mcp
ports:
- "3012:3012"
environment:
- VSPHERE_HOST=vcenter.example.com
- VSPHERE_USERNAME=administrator@vsphere.local
- VSPHERE_PASSWORD=${VSPHERE_PASSWORD}
- VSPHERE_PORT=443
- VSPHERE_VERIFY_SSL=false
- DISABLE_JWT_AUTH=true
restart: unless-stopped
可用工具
虚拟机管理
| 工具 |
说明 |
参数 |
vsphere_vm_get_info |
获取特定虚拟机的详细信息 |
vm_name 或 vm_id |
vsphere_vm_list |
列出具有可选筛选器的虚拟机(默认限制:10) |
datacenter, folder, power_state, limit |
vsphere_vm_power_management |
管理虚拟机电源操作(开机、关机、挂起、重置、关机、重启) |
operation, vm_name 或 vm_id |
vsphere_vm_deploy_from_template |
从内容库模板部署新VM或从现有VM克隆 |
vm_name, datastore_name, template_name,以及许多可选的自定义参数 |
内容库
| 工具 |
说明 |
参数 |
vsphere_content_library_get_info |
获取有关资源库及其项目的信息 |
library_name, library_id, list_items, item_name |
vsphere_content_library_template_info |
获取详细的OVF/OVA模板信息,包括vApp属性 |
template_name, library_name, library_item_id |
主机管理
| 工具 |
说明 |
参数 |
vsphere_host_get_info |
获取特定ESXi主机的详细信息 |
host_name 或 host_id |
vsphere_host_list |
列出所有具有可选筛选器的ESXi主机 |
datacenter, cluster, connection_state |
资源管理
| 工具 |
说明 |
参数 |
vsphere_cluster_get_info |
获取vSphere群集的详细信息 |
cluster_name 或 cluster_id |
vsphere_resource_pool_get_info |
获取资源池的详细信息 |
pool_name 或 pool_id |
网络
| 工具 |
说明 |
参数 |
vsphere_vswitch_get_info |
获取有关虚拟交换机(标准和分布式)的信息 |
host_name, vswitch_name |
vsphere_portgroup_get_info |
获取有关端口组的信息 |
host_name, portgroup_name |
监控
| 工具 |
说明 |
参数 |
vsphere_performance_get_stats |
获取虚拟机或主机的性能统计数据 |
entity_type (vm/主机), entity_name, metrics |
vsphere_health_check |
vSphere基础架构的全面健康检查 |
无 |
环境变量
必需(vSphere连接)
| 变量 |
描述 |
VSPHERE_HOST |
vCenter或ESXi主机名/IP |
VSPHERE_USERNAME |
vSphere用户名 |
VSPHERE_PASSWORD |
vSphere密码 |
可选的
| 变量 |
默认值 |
描述 |
VSPHERE_PORT |
443 |
vSphere API端口 |
VSPHERE_VERIFY_SSL |
false |
验证SSL证书 |
TRANSPORT |
streamable-http |
运输类型(stdio, streamable-http) |
PORT |
3012 |
服务器端口 |
HOST |
0.0.0.0 |
服务器绑定地址 |
DISABLE_JWT_AUTH |
false |
禁用JWT身份验证 |
AZURE_AD_TENANT_ID |
|
Azure AD租户ID(如果启用了JWT,则需要) |
AZURE_AD_CLIENT_ID |
|
Azure AD客户端ID(可选) |
地方发展
先决条件
- Python 3.10或更高版本
- pip(Python包安装程序)
- 访问vSphere/ESXi环境
设置
# Clone the repository
git clone https://github.com/Presidio-Federal/vsphere-mcp.git
cd vsphere-mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
pip install fastmcp[cli]
# Configure environment
cp .env.example .env # Create from example if available
# Edit .env with your vSphere credentials
本地运行
# Using FastMCP CLI (recommended)
fastmcp run server.py --transport http --port 3012
# Or directly with Python
python server.py
# STDIO transport (for MCP client testing)
fastmcp run server.py --transport stdio
建造集装箱
# Build locally
docker build -t vsphere-mcp:local -f dockerfile .
# Run local build
docker run -d \
--name vsphere-mcp \
-p 3012:3012 \
-e VSPHERE_HOST=vcenter.example.com \
-e VSPHERE_USERNAME=administrator@vsphere.local \
-e VSPHERE_PASSWORD=your-password \
-e DISABLE_JWT_AUTH=true \
vsphere-mcp:local
HTTP标头(替代凭据)
您可以通过HTTP标头而不是环境变量传递vSphere凭据:
| 标题 |
描述 |
X-vSphere-Host |
vSphere主机名 |
X-vSphere-Username |
vSphere用户名 |
X-vSphere-Password |
vSphere密码 |
X-vSphere-Port |
vSphere端口 |
X-vSphere-Verify-SSL |
SSL验证(真/假) |
认证
服务器支持两种身份验证模式:
- JWT身份验证 (生产):验证Azure AD JWT令牌。需要
AZURE_AD_TENANT_ID.
- 无认证 (开发):集
DISABLE_JWT_AUTH=true
项目结构
vsphere-mcp/
├── __init__.py # Package initialization
├── __main__.py # Entry point for module execution
├── server.py # Main server implementation
├── utilities.py # Utility functions (auth, credentials)
├── requirements.txt # Python dependencies
├── dockerfile # Container configuration
├── README.md # This file
└── tools/ # Tool implementations
├── vm_management/ # VM tools
├── content_library/ # Content Library tools
├── host_management/ # Host tools
├── resource_management/ # Cluster & Resource Pool tools
├── networking/ # vSwitch & Portgroup tools
└── monitoring/ # Performance & Health tools
故障排除
SSL证书错误
集 VSPHERE_VERIFY_SSL=false 在您的环境变量中。
连接超时
确保您的vSphere主机可访问,防火墙规则允许端口443上的流量。
身份验证失败
- 验证vSphere凭据是否正确
- 检查用户是否具有适当的vSphere权限
- 对于JWT身份验证,请确保Azure AD配置正确
安全说明
- 从不将凭据提交到版本控制
- 使用环境变量或安全密钥管理
- 在生产环境中启用SSL验证
- 在生产部署中使用JWT身份验证
- 定期轮换vSphere凭据
许可证
麻省理工学院