Skip to main content
Glama
mcp-vmwhere
by Bright0505

mcp-vmware

一個唯讀的 MCP server,讓 Claude 能查詢 VMware vCenter 環境。

  • 只讀不控 — 不提供任何開關機、修改、刪除等操作。

  • inventory 查詢透過 vSphere Automation REST API(/api/vcenter/*),僅發出 GET 請求 (唯一例外是 session 登入/登出)。

  • VM 歷史效能數據透過 vSphere Web Services(SOAP)的 PerformanceManager,只呼叫唯讀方法 (REST API 在 vCenter 7 沒有效能端點)。

  • 遵循 MCP 2026-07-28 規範(MCP Python SDK 2.x)。

MCP 2.x 規範對應

規範要點

本專案實作

Stateless protocol core(2026-07-28)

使用 SDK 2.x 的 MCPServer,協定版本 2026-07-28

Tool annotations

所有 tool 標註 readOnlyHint=true、destructiveHint=false、idempotentHint=true

Structured output

每個 tool 都有 outputSchema,回傳 structuredContent(見 models.py)

Tool title / server title

server 與 tool 皆提供人類可讀的 title

Cacheable list results

tools/list、server/discover 帶 cache hint(TTL 1 小時、public)

Lifespan 資源管理

vCenter session 由 server lifespan 建立,結束時自動登出

Related MCP server: VMware-Monitor

需求

  • Python 3.10+

  • vCenter Server 7.0 / 8.0(使用 /api/vcenter/* REST 路徑)

  • 一組具備唯讀(Read-only)權限的 vCenter 帳號即可

安裝

pip install -e .

相依套件:mcp>=2.2.0、httpx2(MCP SDK 2.x 隨附的 HTTP client)、pydantic、 pyvmomi(效能數據查詢用)、tzdata(時區資料)。

設定

透過環境變數提供連線資訊(可參考 .env.example):

變數

必填

說明

VCENTER_HOST

是

vCenter FQDN 或 IP,例 vcenter.example.com

VCENTER_USER

是

帳號,例 administrator@vsphere.local

VCENTER_PASSWORD

是

密碼

VCENTER_INSECURE

否

設為 true 時關閉 TLS 憑證驗證(內部自簽憑證環境用),預設 false

VCENTER_TIMEZONE

否

get_vm_performance 分日與時間顯示用的時區(IANA 名稱,例 Asia/Taipei),無效名稱啟動時報錯;未設定時用行程本機時區(容器通常是 UTC)

啟動

python -m mcp_vmware

以 stdio transport 執行,通常由 MCP 用戶端(Claude Code / Claude Desktop)自動啟動。

接入 Claude Code

claude mcp add vmware \
  -e VCENTER_HOST=vcenter.example.com \
  -e VCENTER_USER=administrator@vsphere.local \
  -e VCENTER_PASSWORD=yourpassword \
  -- python -m mcp_vmware

接入 Claude Desktop

Claude Desktop 由 app 直接啟動 server 行程,不會繼承終端機的 PATH 與虛擬環境 — command 請填 Python 直譯器的絕對路徑(有用虛擬環境就填該環境下的 python), 否則會出現找不到指令或 No module named mcp_vmware。

取得絕對路徑:

# 先啟用安裝本專案的環境,再執行
python -c "import sys; print(sys.executable)"

設定步驟

  1. 開啟 Claude 選單(macOS 在系統最上方的選單列)→ Settings… → 左側 Developer → 按 Edit Config,會開啟設定檔:

    • macOS:~/Library/Application Support/Claude/claude_desktop_config.json

    • Windows:%APPDATA%\Claude\claude_desktop_config.json

  2. 在 mcpServers 底下加入 vmware(把路徑與帳密換成自己的):

    macOS / Linux:

    {
      "mcpServers": {
        "vmware": {
          "command": "/Users/yourname/git/mcp-vmware/.venv/bin/python",
          "args": ["-m", "mcp_vmware"],
          "env": {
            "VCENTER_HOST": "vcenter.example.com",
            "VCENTER_USER": "readonly@vsphere.local",
            "VCENTER_PASSWORD": "yourpassword",
            "VCENTER_INSECURE": "false"
          }
        }
      }
    }

    Windows(路徑的反斜線要寫成 \\):

    {
      "mcpServers": {
        "vmware": {
          "command": "C:\\Users\\yourname\\git\\mcp-vmware\\.venv\\Scripts\\python.exe",
          "args": ["-m", "mcp_vmware"],
          "env": {
            "VCENTER_HOST": "vcenter.example.com",
            "VCENTER_USER": "readonly@vsphere.local",
            "VCENTER_PASSWORD": "yourpassword",
            "VCENTER_INSECURE": "false"
          }
        }
      }
    }
  3. 完全結束(Quit,不是關視窗)Claude Desktop 後重新開啟。

  4. 在對話輸入框左下角點 Add files, connectors, and more → Connectors → Manage connectors,選 vmware 就會看到本 server 的 10 個唯讀工具。

試著問問看

  • 「現在有幾台 VM 是開機狀態?」

  • 「列出所有 ESXi 主機和它們的連線狀態」

  • 「哪個 datastore 的剩餘空間最少?」

  • 「給我 vm-123 近一週的效能分析」

疑難排解

看不到 vmware 或工具呼叫失敗時,先看 log:

# macOS
tail -n 50 -f ~/Library/Logs/Claude/mcp*.log
# Windows
type "%APPDATA%\Claude\logs\mcp-server-vmware.log"

再用同一組路徑與環境變數手動啟動一次,確認 server 本身沒問題:

VCENTER_HOST=vcenter.example.com \
VCENTER_USER=readonly@vsphere.local \
VCENTER_PASSWORD=yourpassword \
/Users/yourname/git/mcp-vmware/.venv/bin/python -m mcp_vmware

正常情況下不會有任何輸出(server 在等 stdin),按 Ctrl-C 結束即可。

常見原因:

症狀

原因

完全看不到這個 connector

claude_desktop_config.json JSON 格式錯誤(多一個逗號就整份不載入)

log 出現 No such file / No module named mcp_vmware

command 用了相對路徑,或該直譯器沒裝本專案

log 出現「缺少必要環境變數: …」

env 少填 VCENTER_HOST / VCENTER_USER / VCENTER_PASSWORD

TLS 憑證錯誤

自簽憑證環境請設 "VCENTER_INSECURE": "true"

用 MCP Inspector 測試

npx @modelcontextprotocol/inspector python -m mcp_vmware

提供的 Tool(全部唯讀)

Tool

說明

回傳型別

list_vms

列出虛擬機摘要(可依電源狀態、名稱過濾)

VMSummary[]

get_vm

取得單一 VM 詳情(硬體、電源、客體 OS)

VMDetail

get_vm_performance

取得單一 VM 近 N 天的效能數據(CPU、記憶體、磁碟、網路)與統計

VMPerformance

list_hosts

列出 ESXi 主機(可依連線狀態過濾)

HostSummary[]

list_clusters

列出叢集

ClusterSummary[]

list_datastores

列出 Datastore 容量資訊

DatastoreSummary[]

list_networks

列出網路 / Port Group

NetworkSummary[]

list_datacenters

列出資料中心

DatacenterSummary[]

list_resource_pools

列出資源池

ResourcePoolSummary[]

list_folders

列出資料夾

FolderSummary[]

回傳模型的欄位名稱與 vSphere REST API 一致,且允許額外欄位 — 不同 vCenter 版本多回的欄位會原樣保留,不會被丟棄或造成驗證失敗。

get_vm_performance 說明

參數

預設

說明

vm_id

—

VM 的 managed object id,例 vm-123

days

7

查詢最近幾天(1~365)

include_series

false

是否附上完整時間序列

  • 取樣間隔依 vCenter「統計資料」設定,自動選擇能涵蓋查詢範圍的最細間隔 (預設:1 天內 5 分鐘、1 週內 30 分鐘、1 個月內 2 小時、1 年內 1 天); 都涵蓋不到時取保留最久者,並寫在 notes。查詢結束時間以 vCenter 伺服器時間為準。

  • 指標(皆取彙總值):CPU 使用率/MHz/Ready、記憶體 usage/consumed/active/balloon/swap、 磁碟吞吐量與最大延遲、網路吞吐量。

  • 每個指標回傳 min / max / avg / p95 / 最新值、峰值時間,以及每日平均、最大值與當日峰值時間(daily[].peak_time)。

  • 單位換算:百分比已除以 100、記憶體為 MiB、吞吐量為 KBps;cpu.ready.summation 換算為「每 vCPU 平均 Ready %」。

  • 統計層級 1(vCenter 預設)不收集 mem.active、mem.swapped, 這些會列在 unavailable_metrics;需要時可把該統計間隔的層級調到 2。 查詢期間全無資料(全為 -1)的指標也會列在這裡。

  • 每日統計與時間以 VCENTER_TIMEZONE 為準;容器部署請設定,否則會以 UTC 分日(台灣會偏 8 小時)。

  • 權限:唯讀(Read-only)角色即可,不需額外權限。

安全說明

  • 本 server 不會對 vCenter 做任何異動;vcenter.py 中除 session 登入(POST /api/session) 與登出(DELETE /api/session)外,僅有 GET 請求。

  • perf.py 走 SOAP API(協定上一律是 POST),只呼叫 Login / Logout、CurrentTime、 屬性讀取,以及 QueryAvailablePerfMetric / QueryPerf 這些唯讀方法。

  • 所有 tool 皆標註 readOnlyHint,用戶端可據此判斷本 server 不會改動環境。

  • 建議搭配僅具唯讀權限的 vCenter 服務帳號使用,以從權限層面再加一道保險。

  • Claude Desktop / Claude Code 的設定檔會以明文存放 VCENTER_PASSWORD,請勿把設定檔提交進版控; macOS 可再收緊權限:chmod 600 ~/Library/Application\ Support/Claude/claude_desktop_config.json。

HTTP 模式(Open WebUI 原生 MCP 連線)

除了 stdio,也可用 Streamable HTTP 執行,端點 /mcp/:

PYTHONPATH=src HTTP_PORT=8000 MCP_AUTH_TOKEN=<token> python -m http_server
  • 驗證:請求需帶 Authorization: Bearer <MCP_AUTH_TOKEN>(可逗號分隔多組以便輪替)。 未設 MCP_AUTH_TOKEN 時不驗證並在 log 警告 —— 任何連得到的人都能讀整個 vCenter inventory,只限本機除錯。 另支援選用的 OAuth access token(MCP_OAUTH_ISSUER/MCP_OAUTH_AUDIENCE/MCP_OAUTH_JWKS_URL,三者皆設定才啟用), 詳見 src/mcp_vmware/auth.py。

  • /health 免驗證,供容器健康檢查使用。

  • 缺 VCENTER_HOST/VCENTER_USER/VCENTER_PASSWORD 時程序直接結束(健康檢查會失敗)。

  • 無狀態(stateless)、JSON 回應;全程序共用一個 vCenter session。

  • 工具名不帶前綴;Open WebUI 的函式名是「連線識別碼+底線+工具名」,例 vmware_list_vms。

  • 所有 list_* 工具都回傳物件而非裸陣列:附 total 與依狀態/類型分組的計數(list_datastores 另附 GiB 換算、 used_pct,並已依使用率由高到低排序)。數量一律由工具算好 —— LLM 自行計算長清單 容易數錯。list_vms 另有 name_contains(不分大小寫的部分名稱比對)。

容器與部署

docker build --target production -t mcp-vmware .

docker run -d --name mcp-vmware -p 8000:8000 \
  -e VCENTER_HOST=vcenter.example.com \
  -e VCENTER_USER=readonly@vsphere.local \
  -e VCENTER_PASSWORD=yourpassword \
  -e MCP_AUTH_TOKEN=<token> \
  mcp-vmware

curl http://localhost:8000/health
  • 容器內預設執行 python -m http_server,監聽 HTTP_PORT(預設 8000)。

  • 建議以 --env-file .env 或部署平台的 secret 機制注入 VCENTER_* 與 MCP_AUTH_TOKEN,勿寫進 image。

  • 依賴版本以 constraints.txt 鎖定;有意升級時在建好的 image 內 pip freeze 重新產生。

授權

MIT

Available Tools

9 tools
get_vm取得虛擬機詳情A
Read-onlyIdempotent

取得單一虛擬機的詳細資訊。

彙整硬體設定(CPU、記憶體、磁碟、網卡)、電源狀態,以及客體 OS 身分資訊 (需 VM 開機且 VMware Tools 執行中才有客體資訊)。

參數: vm_id: VM 的 managed object id,例如 "vm-123"(可由 list_vms 取得)。

Inputs: vm_id (required). Returns: 單一虛擬機詳情(硬體 / 電源 / 客體 OS)。

list_clusters列出叢集A
Read-onlyIdempotent

列出 vCenter 中的叢集(Cluster)。

回傳 total、啟用 DRS/HA 的叢集數,以及每個叢集的 id、名稱與 DRS/HA 設定。

Inputs: no named parameters. Returns: total, clusters, ha_enabled_count, drs_enabled_count

list_datacenters列出資料中心A
Read-onlyIdempotent

列出 vCenter 中的資料中心(Datacenter):total 與每個資料中心的 id、名稱。

Inputs: no named parameters. Returns: total, datacenters

list_datastores列出 DatastoreA
Read-onlyIdempotent

列出 vCenter 中的 Datastore(儲存),附上算好的容量與使用率。

回傳: total: Datastore 數量(直接引用,不要自己數)。 total_capacity_GiB / total_free_GiB / overall_used_pct: 全部合計。 used_pct_at_least_90 / used_pct_at_least_80: 使用率達 90%/80% 以上的數量。 datastores: 每個 datastore 的 id、名稱、類型、capacity/free_space(位元組)、 capacity_GiB、free_GiB、used_pct(已用百分比),已依 used_pct 由高到低排序 (容量為 0 或未知者排最後)。

Inputs: no named parameters. Returns: total, sorted_by, datastores, total_free_GiB, +4 more

list_folders列出資料夾A
Read-onlyIdempotent

列出 vCenter 中的資料夾(Folder)。

回傳 total、依類型分組的數量(DATACENTER、VIRTUAL_MACHINE、HOST、DATASTORE、NETWORK), 以及每個資料夾的 id、名稱與類型。

Inputs: no named parameters. Returns: total, folders, type_counts

list_hosts列出 ESXi 主機A
Read-onlyIdempotent

列出 vCenter 管理的 ESXi 主機,並附上依狀態分組的台數。

回傳 total(主機台數,直接引用)、connection_state_counts、power_state_counts, 以及每台主機的 id、名稱、連線狀態與電源狀態(依名稱排序)。

參數: connection_state: 選填,依連線狀態過濾。

Inputs: connection_state. Returns: hosts, total, power_state_counts, connection_state_counts

list_networks列出網路A
Read-onlyIdempotent

列出 vCenter 中的網路 / Port Group。

回傳 total、依類型分組的數量(STANDARD_PORTGROUP、DISTRIBUTED_PORTGROUP 等), 以及每個網路的 id、名稱與類型。

Inputs: no named parameters. Returns: total, networks, type_counts

list_resource_pools列出資源池B
Read-onlyIdempotent

列出 vCenter 中的資源池(Resource Pool):total 與每個資源池的 id、名稱。

Inputs: no named parameters. Returns: total, resource_pools

list_vms列出虛擬機A
Read-onlyIdempotent

列出 vCenter 中的虛擬機(VM),並附上算好的彙總。

回傳: total: 符合條件的 VM 台數(要回答「幾台」請直接引用,不要自己數 vms)。 power_state_counts: 依電源狀態分組的台數。 total_cpu_count / total_memory_GiB: 符合條件 VM 的 vCPU 與記憶體配置合計。 vms: 每台 VM 的 id、名稱、電源狀態、CPU 數與記憶體(MiB),依名稱排序。

參數: power_state: 選填,依電源狀態過濾。 name: 選填,VM 名稱完全比對。 name_contains: 選填,名稱包含此關鍵字(不分大小寫)。只知道部分名稱時用這個。

Inputs: name, power_state, name_contains. Returns: vms, total, total_cpu_count, total_memory_GiB, +1 more

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 9 tools

    Disambiguation5/5

    Each tool targets a distinct vCenter object type (VM, host, cluster, datastore, network, datacenter, resource pool, folder), and get_vm is clearly differentiated from list_vms by returning detailed single-object data. There is no plausible way to confuse the tools at selection time.

    Naming Consistency5/5

    All names use a consistent snake_case verb_noun pattern (list_vms, list_hosts, get_vm), with 'list_' for collection queries and 'get_' for single-object retrieval. The convention is predictable and readable.

    Tool Count5/5

    Nine tools is well within the ideal range and each maps to a real vCenter inventory entity, so nothing feels padded. The one list-per-resource-type layout is the natural minimal surface for this domain.

    Completeness3/5

    The server is a read-only inventory surface: it lists every major vCenter entity but offers no mutations, no VM power operations (power on/off/reset), and no detail getters for hosts, datastores, or clusters analogous to get_vm. Agents can survey the environment but cannot act on it or drill into non-VM objects.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Read-only VMware vCenter/ESXi monitoring. 8 MCP tools for VM inventory, host status, datastore capacity, cluster info, alarms, events, and VM details. Code-level enforced safety — no destructive operations exist in the codebase. Supports vSphere 6.5–8.0. Works with local models via Ollama/LM Studio.
      33
      534 PyPI
      20
      MIT