Skip to main content
Glama
vSphere 7 MCP Server

vSphere 7 MCP Server

by jonnyfiveiq
README.md
# vSphere 7 MCP Server

MCP server exposing tools to manage vSphere VMs.

## Tools
- `list_vms` — list all VMs (optionally filter by datacenter, folder, power_state; outputs table or JSON)
- `create_vm` — clone a new VM from a template
- `delete_vm` — delete a powered-off VM
- `power_on_vm` — power on a VM
- `power_off_vm` — power off a VM

---

## 1) Local shell script (no Docker/Ansible)
```bash
./scripts/start_local.sh
```
The script will:
- Create a `.venv` if needed
- Install requirements
- Load `.env` variables (VCENTER creds)
- Run the MCP server

Edit `.env` to match your vCenter.

---

## 2) Docker
```bash
docker build -t vsphere7-mcp-server:latest .
docker compose up
```
`docker-compose.yml` reads env vars from `.env` in this folder.

---

## 3) Ansible (installs a systemd service)
```bash
cd ansible
ansible-playbook -i inventory.ini site.yml --ask-become-pass
```
- Installs to `/opt/vsphere7-mcp-server`
- Creates venv and writes `/etc/vsphere7-mcp-server.env`
- Manages `vsphere7-mcp-server.service`

Check:
```bash
systemctl status vsphere7-mcp-server
journalctl -u vsphere7-mcp-server -f
```

---

## 4) Claude Desktop — test any running server

Claude can launch the MCP server via stdio. Example entries for your `claude_desktop_config.json`:

### 4.a Docker-based
```json
{
  "mcpServers": {
    "vsphere-docker": {
      "command": "docker",
      "args": [
        "run", "--rm", "-i",
        "--env-file", "/Users/johnhardy/Downloads/vsphere7-mcp/.env",
        "vsphere7-mcp-server:latest"
      ],
      "cwd": "/Users/johnhardy/Downloads/vsphere7-mcp"
    }
  }
}
```

### 4.b Ansible-installed (direct venv python with env inline)
```json
{
  "mcpServers": {
    "vsphere-ansible": {
      "command": "/opt/vsphere7-mcp-server/.venv/bin/python",
      "args": ["/opt/vsphere7-mcp-server/mcp-vsphere-server.py"],
      "env": {
        "VCENTER_HOST": "192.168.0.195",
        "VCENTER_USER": "administrator@vsphere.local",
        "VCENTER_PASSWORD": "xxxxxxx",
        "VCENTER_VERIFY_SSL": "false"
      }
    }
  }
}
```

### 4.c Ansible-installed (recommended wrapper script)
Create `/usr/local/bin/vsphere-mcp.sh` on the host:
```bash
#!/usr/bin/env bash
set -a
source /etc/vsphere7-mcp-server.env
set +a
exec /opt/vsphere7-mcp-server/.venv/bin/python /opt/vsphere7-mcp-server/mcp-vsphere-server.py
```
Make it executable:
```bash
sudo chmod +x /usr/local/bin/vsphere-mcp.sh
```
Claude config:
```json
{
  "mcpServers": {
    "vsphere-ansible-wrapper": {
      "command": "/usr/local/bin/vsphere-mcp.sh",
      "args": []
    }
  }
}
```

---

## Quick MCP tool tests (from Claude)
- List everything:
  ```
  list_vms()
  ```
- Only powered-on:
  ```
  list_vms(power_state="on")
  ```
- Create from a template:
  ```
  create_vm(name="test-01", template="my-template", datacenter="Datacenter", cluster="Cluster1", datastore="datastore1", power_on=false)
  ```

---

## License
MIT License (c) 2025