|
1 | | -# vsphere-mcp-pro |
| 1 | +# vSphere-MCP-Pro |
2 | 2 |
|
3 | | -Secure, feature-rich MCP server for VMware vCenter 8.0+. |
| 3 | +A secure, feature-rich Machine Control Plane (MCP) server for VMware vCenter 8.0+. |
| 4 | +This service exposes a controlled set of vCenter operations via MCP tools, including VM lifecycle management, snapshot operations, datastore/host discovery, and more—wrapped with audit logging, RBAC authorization, and rate limiting. |
4 | 5 |
|
5 | | -## Highlights |
6 | | -- SSL verify on by default, optional CA bundle |
7 | | -- vCenter host allow-list |
8 | | -- Bearer token auth + role→tools gating |
9 | | -- Destructive ops require `confirm=True` |
10 | | -- Rate limiting + JSON-lines audit |
11 | | -- Supports `/api` (preferred) and `/rest` endpoints |
| 6 | +--- |
| 7 | + |
| 8 | +## Table of Contents |
| 9 | +- [Overview](#overview) |
| 10 | +- [Key Features](#key-features) |
| 11 | +- [Architecture](#architecture) |
| 12 | +- [Directory Structure](#directory-structure) |
| 13 | +- [Installation](#installation) |
| 14 | +- [Configuration](#configuration) |
| 15 | +- [Running the Server](#running-the-server) |
| 16 | +- [Available Tools / API](#available-tools--api) |
| 17 | +- [Audit Logging](#audit-logging) |
| 18 | +- [Rate Limiting](#rate-limiting) |
| 19 | +- [Security Model](#security-model) |
| 20 | +- [Development](#development) |
| 21 | +- [Docker Usage](#docker-usage) |
| 22 | +- [Troubleshooting](#troubleshooting) |
| 23 | +- [License](#license) |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Overview |
| 28 | + |
| 29 | +`vsphere-mcp-pro` is an MCP server designed for VMware vCenter 8.0+ environments. |
| 30 | +It provides: |
| 31 | + |
| 32 | +- Safe, structured access to vCenter operations |
| 33 | +- Strict authorization via roles → allowed tools |
| 34 | +- Snapshot + VM lifecycle operations |
| 35 | +- Auditing and rate limiting for secure multi-tenant use |
| 36 | +- Support for both `/api` (preferred) and `/rest` vCenter endpoints |
| 37 | +- Optional host allow-listing to prevent accidental cross-cluster operations |
| 38 | + |
| 39 | +The server runs using `FastMCP` and automatically wraps every tool operation with: |
| 40 | +- Token-based RBAC (`Authorizer`) |
| 41 | +- Token bucket rate limiting |
| 42 | +- JSONL audit logging |
| 43 | +- Optional confirmation for destructive operations |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Key Features |
| 48 | + |
| 49 | +### ✔ Secure by design |
| 50 | +- SSL verification enabled by default |
| 51 | +- Optional CA bundle support |
| 52 | +- Allowed-host enforcement prevents unauthorized vCenter targets |
| 53 | + |
| 54 | +### ✔ Strong authorization model |
| 55 | +- Token → role mapping |
| 56 | +- Role → allowed-tools mapping |
| 57 | +- Enforced unless explicitly disabled |
| 58 | +- Destructive operations require `confirm=True` |
| 59 | + |
| 60 | +### ✔ Operationally robust |
| 61 | +- Automatic retry logic for vCenter API calls (`Retry + HTTPAdapter`) |
| 62 | +- Session auto-renewal on 401 |
| 63 | +- Extensive logging for auditing and observability |
| 64 | + |
| 65 | +### ✔ High performance |
| 66 | +- Thread-safe vCenter session management |
| 67 | +- MCP server built with `uvicorn` |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Architecture |
| 72 | + |
| 73 | +**Key modules:** |
| 74 | + |
| 75 | +- **`server.py`** |
| 76 | + Builds the MCP server, registers all tools, injects authorization, rate-limiting, and auditing wrappers. |
| 77 | + |
| 78 | +- **`vsphere_client.py`** |
| 79 | + Handles retries, authentication, and REST/API mode switching for VMware vCenter. |
| 80 | + |
| 81 | +- **`authz.py`** |
| 82 | + Implements: |
| 83 | + - Token → role resolution |
| 84 | + - Role → tool gating |
| 85 | + - Token bucket rate limiting |
| 86 | + |
| 87 | +- **`audit.py`** |
| 88 | + Writes JSON-lines logs for every operation. |
| 89 | + |
| 90 | +- **`config.py`** |
| 91 | + Loads environment variables into a typed `AppConfig` using `pydantic`. |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## Directory Structure |
| 96 | + |
| 97 | +```Structure |
| 98 | +
|
| 99 | +/ |
| 100 | +├── vsphere-mcp-pro/ # Python package |
| 101 | +│ ├── server.py |
| 102 | +│ ├── vsphere_client.py |
| 103 | +│ ├── authz.py |
| 104 | +│ ├── audit.py |
| 105 | +│ ├── config.py |
| 106 | +├── pyproject.toml |
| 107 | +├── README.md |
| 108 | +├── .env.example |
| 109 | +├── Dockerfile |
| 110 | +
|
| 111 | +```` |
| 112 | +
|
| 113 | +--- |
| 114 | +
|
| 115 | +## Installation |
| 116 | +
|
| 117 | +### Prerequisites |
| 118 | +
|
| 119 | +- Python **3.10+** |
| 120 | +- VMware vCenter **8.0+** |
| 121 | +- A valid set of API credentials |
| 122 | +
|
| 123 | +### Install from source |
12 | 124 |
|
13 | | -## Quickstart |
14 | 125 | ```bash |
15 | | -cp env.example .env |
16 | | -# Fill VCENTER_* and tokens |
| 126 | +
|
| 127 | +git clone https://github.com/Warezloder/vSphere-MCP-Pro |
| 128 | +cd vsphere-mcp-pro |
| 129 | +pip install -e . |
| 130 | +
|
| 131 | +```` |
| 132 | +
|
| 133 | +--- |
| 134 | +
|
| 135 | +## Configuration |
| 136 | +
|
| 137 | +Configuration is environment-driven. Copy the example file: |
| 138 | +
|
| 139 | +```bash |
| 140 | +
|
| 141 | +cp .env.example .env |
| 142 | +
|
| 143 | +``` |
| 144 | + |
| 145 | +### Required Environment Variables |
| 146 | + |
| 147 | +| Variable | Description | |
| 148 | +| ----------------------- | --------------------------------------------- | |
| 149 | +| `VCENTER_HOST` | vCenter hostname/IP | |
| 150 | +| `VCENTER_USER` | vCenter username | |
| 151 | +| `VCENTER_PASSWORD` | vCenter password | |
| 152 | +| `ROLES_TO_TOOLS` | JSON map of role → allowed tools | |
| 153 | +| `TOKENS_TO_ROLES` | JSON map of token → role | |
| 154 | +| `ALLOWED_VCENTER_HOSTS` | Optional allowlist for multi-host deployments | |
| 155 | + |
| 156 | +Example snippet: |
| 157 | + |
| 158 | +```python |
| 159 | + |
| 160 | +VCENTER_HOST=vcenter.example.com |
| 161 | +VCENTER_USER=administrator@vsphere.local |
| 162 | +VCENTER_PASSWORD=s3cret |
| 163 | +TOKENS_TO_ROLES={"token1": "read", "token2": "ops"} |
| 164 | +ROLES_TO_TOOLS={"read":["list_vms","get_vm_details"],"ops":["power_on_vm"]} |
| 165 | + |
| 166 | +``` |
| 167 | + |
| 168 | +--- |
| 169 | + |
| 170 | +## Running the Server |
| 171 | + |
| 172 | +### Local execution |
| 173 | + |
| 174 | +```bash |
| 175 | + |
17 | 176 | python -m vsphere_mcp_pro.server |
18 | 177 |
|
19 | | -# Docker |
20 | | -docker build -t vsphere-mcp-pro:latest . |
21 | | -docker run --rm -p 8000:8000 --env-file .env vsphere-mcp-pro:latest |
22 | 178 | ``` |
| 179 | + |
| 180 | +Server defaults (override via env vars): |
| 181 | + |
| 182 | +* Host: `0.0.0.0` |
| 183 | +* Port: `8000` |
| 184 | +* MCP path: `/mcp` |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +## Available Tools / API |
| 189 | + |
| 190 | +Below is a categorized summary of available MCP tools exposed by the server. |
| 191 | + |
| 192 | +### VM Discovery |
| 193 | + |
| 194 | +* `list_vms` |
| 195 | +* `get_vm_details` |
| 196 | + |
| 197 | +### Inventory Discovery |
| 198 | + |
| 199 | +* `list_hosts` |
| 200 | +* `list_datastores` |
| 201 | +* `list_networks` |
| 202 | +* `list_datacenters` |
| 203 | +* `get_datastore_usage` |
| 204 | +* `get_resource_utilization_summary` |
| 205 | + |
| 206 | +### Power Operations |
| 207 | + |
| 208 | +* `power_on_vm` |
| 209 | +* `power_off_vm` |
| 210 | +* `restart_vm` |
| 211 | + |
| 212 | +### Snapshot Operations |
| 213 | + |
| 214 | +* `list_vm_snapshots` |
| 215 | +* `create_vm_snapshot` |
| 216 | +* `delete_vm_snapshot` |
| 217 | + |
| 218 | +### VM Resource Management |
| 219 | + |
| 220 | +* `modify_vm_resources` (CPU / memory) |
| 221 | + |
| 222 | +### Destructive Operations (require `confirm=True`) |
| 223 | + |
| 224 | +* `delete_vm` |
| 225 | +* `delete_vm_snapshot` |
| 226 | + |
| 227 | +--- |
| 228 | + |
| 229 | +## Audit Logging |
| 230 | + |
| 231 | +Every MCP tool call is logged as a JSON line containing: |
| 232 | + |
| 233 | +* tool name |
| 234 | +* execution status |
| 235 | +* duration (ms) |
| 236 | +* sanitized arguments (passwords & tokens masked) |
| 237 | +* optional error message |
| 238 | +* role + host context |
| 239 | + |
| 240 | +Logs either write to stdout or to the configured `AUDIT_LOG_PATH`. |
| 241 | + |
| 242 | +--- |
| 243 | + |
| 244 | +## Rate Limiting |
| 245 | + |
| 246 | +Uses a token-bucket strategy: |
| 247 | + |
| 248 | +* Configurable `RATE_LIMIT_RPS` and `RATE_LIMIT_BURST` |
| 249 | +* Separate buckets per token |
| 250 | +* Disabled by setting `RATE_LIMIT=false` |
| 251 | + |
| 252 | +--- |
| 253 | + |
| 254 | +## Security Model |
| 255 | + |
| 256 | +| Mechanism | Purpose | |
| 257 | +| ---------------------- | ----------------------------------------- | |
| 258 | +| SSL verification | Prevent MITM attacks | |
| 259 | +| Allowed-host list | Prevent unauthorized target selection | |
| 260 | +| Role → tool mapping | Enforce least-privilege principle | |
| 261 | +| Token authentication | Multi-tenant safe access | |
| 262 | +| Required confirmations | Prevent accidental destructive operations | |
| 263 | +| Rate limiting | Protects vCenter and MCP server | |
| 264 | + |
| 265 | +--- |
| 266 | + |
| 267 | +## Development |
| 268 | + |
| 269 | +### Install dev deps |
| 270 | + |
| 271 | +```bash |
| 272 | + |
| 273 | +pip install -e .[dev] |
| 274 | + |
| 275 | +``` |
| 276 | + |
| 277 | +### Run with autoreload |
| 278 | + |
| 279 | +```bash |
| 280 | + |
| 281 | +uvicorn vsphere_mcp_pro.server:main --reload |
| 282 | + |
| 283 | +``` |
| 284 | + |
| 285 | +--- |
| 286 | + |
| 287 | +## Docker Usage |
| 288 | + |
| 289 | +### Build |
| 290 | + |
| 291 | +```bash |
| 292 | + |
| 293 | +docker build -t vsphere-mcp-pro . |
| 294 | + |
| 295 | +``` |
| 296 | + |
| 297 | +### Run |
| 298 | + |
| 299 | +```bash |
| 300 | + |
| 301 | +docker run \ |
| 302 | + --rm \ |
| 303 | + -p 8000:8000 \ |
| 304 | + --env-file .env \ |
| 305 | + vsphere-mcp-pro |
| 306 | + |
| 307 | +``` |
| 308 | + |
| 309 | +--- |
| 310 | + |
| 311 | +## Troubleshooting |
| 312 | + |
| 313 | +### "login failed: HTTP 401" |
| 314 | + |
| 315 | +* Verify vCenter username/password |
| 316 | +* Ensure correct API mode (`VSPHERE_API_MODE=api|rest`) |
| 317 | + |
| 318 | +### "Hostname not in allowed set" |
| 319 | + |
| 320 | +* Add the hostname to `ALLOWED_VCENTER_HOSTS` |
| 321 | + |
| 322 | +### Rate limit errors |
| 323 | + |
| 324 | +* Increase `RATE_LIMIT_BURST` |
| 325 | +* Adjust per-token usage |
| 326 | + |
| 327 | +### SSL certificate issues |
| 328 | + |
| 329 | +* Set `VCENTER_CA_BUNDLE` |
| 330 | + or |
| 331 | +* Disable SSL verification only if absolutely necessary: |
| 332 | + `INSECURE=true` |
| 333 | + |
| 334 | +--- |
| 335 | + |
| 336 | +## License |
| 337 | + |
| 338 | +This project is licensed under your chosen repository license. |
0 commit comments