Mcp Kubernetes

io.github.dockndevai由 GitHub 帳號 dockndevai 發布v0.3.3更新於 Oct 26, 2026

Kubernetes monitoring & ops for AI agents — safe-by-default access modes and guards.

概覽

AI 產生的概覽

本機 MCP 伺服器,讓 AI 助理跨多個情境檢視與操作 Kubernetes 叢集,預設唯讀並具分層安全限制。

可以做什麼
  • 列出情境、命名空間、Pod、Deployment、Service、節點與近期事件
  • 讀取單一 Pod 的完整資訊並取得容器近期日誌
  • 依 apiVersion、kind 與名稱讀取任意 Kubernetes 物件
  • 在讀寫模式下擴縮或重啟 Deployment、變更映像、建立命名空間並套用清單
  • 在管理員模式並明確開啟後刪除資源、進入 Pod 執行指令
  • 對受控操作進行攔截與稽核,支援試執行與可選的本機風險防護常駐程式
適用情境
適合讓助理排查叢集故障、查看 Pod 狀態與日誌、檢查 Deployment 與事件,而不必切換到 kubectl。也適合希望透過明確開關與允許清單來管控寫入或管理操作的環境。
執行需求
透過 npx 從 npm 套件在本機執行,需要 Node.js。需要 kube-config 檔案(以 KUBECONFIG_PATH 指定路徑)或叢集內服務帳號,並能連線至相應叢集。行為由 K8S_MODE、命名空間與情境允許清單,以及刪除、套用、執行等開關等環境變數控制。
安裝前請注意
讀寫與管理員模式可以變更或刪除叢集資源;在需要之前請讓 K8S_MODE 保持唯讀,並依賴允許清單與受保護命名空間。除非啟用 K8S_ALLOW_DELETE、K8S_ALLOW_APPLY 或 K8S_ALLOW_EXEC,刪除、套用與執行功能維持關閉。伺服器使用你的 kube-config 憑證,因此繼承其叢集權限。可選的防護模式會連線至本機 laya-guard 常駐程式。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Mcp Kubernetes,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

mcp-kubernetes

[CI] [License: MIT] [npm]

A Model Context Protocol server for Kubernetes. It lets an MCP-capable client (Claude Desktop, Claude Code, etc.) inspect and operate Kubernetes clusters across multiple contexts — with behaviour controlled entirely by flags.

The design goal is safe by default: it starts read-only, can be scoped to an allowlist of namespaces and contexts, protects system namespaces from mutation, and gates the dangerous operations (delete, apply, exec) behind explicit opt-ins.

Features

  • Multi-cluster — every tool accepts an optional context; scope which contexts are usable with an allowlist.
  • Access modes — read-only → read-write → admin, layered so a mode never exposes tools above its level.
  • Security flags — namespace allowlist, protected namespaces, context allowlist, plus independent opt-ins for delete / apply / exec, dry-run, and JSON audit logging (see below).
  • Standard auth — uses your kube-config (or in-cluster service account). No credentials are stored by the server.

Security model

ConcernFlagDefaultEffect
What can the server do at all?K8S_MODEread-onlyread-only exposes only reads; read-write adds mutations; admin adds destructive tools. Tools above the mode are never registered.
Which namespaces are in scope?K8S_NAMESPACE_ALLOWLIST(all)When set, any operation on a namespace outside the list is refused.
Which namespaces are read-only forever?K8S_PROTECTED_NAMESPACESkube-system,kube-public,kube-node-leaseCan be read but never mutated or deleted, regardless of mode.
Which clusters are reachable?K8S_CONTEXT_ALLOWLIST(all)When set, only these kube-config contexts may be targeted.
Can it delete?K8S_ALLOW_DELETEfalsedelete_resource needs this and admin mode.
Can it apply manifests?K8S_ALLOW_APPLYfalseapply_manifest needs this and read-write mode.
Can it exec into pods?K8S_ALLOW_EXECfalseexec_in_pod needs this and admin mode; the tool isn't even registered otherwise.
Preview without touching the clusterK8S_DRY_RUNfalseWrite/admin tools validate + log intent, then return without calling the API.
Audit trailK8S_AUDIT_LOGtrueEmits a JSON line to stderr per guarded operation (ALLOW / DENY / DRY_RUN).
Interactive confirmation(automatic)—Destructive & high-impact actions prompt the human to approve via MCP elicitation before running; clients without elicitation fall back to the *_ALLOW_* gate.

The layers are independent — e.g. admin mode with all three opt-ins false can restart and scale deployments but can neither delete resources nor exec into pods.

Tools

Read (read-only+): list_contexts, list_namespaces, list_pods, get_pod, get_pod_logs, list_deployments, list_services, list_nodes, list_events, get_resource

Write (read-write+): scale_deployment, restart_deployment, set_deployment_image, create_namespace, apply_manifest (needs K8S_ALLOW_APPLY)

Admin (admin): delete_resource (needs K8S_ALLOW_DELETE), exec_in_pod (needs K8S_ALLOW_EXEC)

Optional AI risk guard. Set K8S_GUARD_MODE=monitor|enforce to have delete_resource, exec_in_pod and apply_manifest consult a local laya-guard daemon (pipx install laya-guard && laya-guard) that classifies the operation allow/confirm/block before it runs. Runs after the delete/exec/apply gates; only tightens, never grants; fails closed.

Quickstart — add to your agent

Published on npm as @dockndevai/mcp-kubernetes. No clone or build needed — your MCP client runs it on demand with npx. Start in read-only mode; see .env.example for every variable and docs/CLIENTS.md for the full per-client guide.

Claude Code (CLI)

bash
claude mcp add kubernetes -e KUBECONFIG_PATH="/Users/you/.kube/config" -e K8S_MODE="read-only" -- npx -y @dockndevai/mcp-kubernetes

Claude Desktop · Cursor · Windsurf — same block in claude_desktop_config.json, .cursor/mcp.json, or ~/.codeium/windsurf/mcp_config.json:

json
{  "mcpServers": {    "kubernetes": {      "command": "npx",      "args": [        "-y",        "@dockndevai/mcp-kubernetes"      ],      "env": {        "KUBECONFIG_PATH": "/Users/you/.kube/config",        "K8S_MODE": "read-only"      }    }  }}

OpenAI Codex CLI — in ~/.codex/config.toml:

toml
[mcp_servers.kubernetes]command = "npx"args = ["-y", "@dockndevai/mcp-kubernetes"]env = { KUBECONFIG_PATH = "/Users/you/.kube/config", K8S_MODE = "read-only" }

VS Code (GitHub Copilot, Agent mode) — in .vscode/mcp.json:

json
{  "servers": {    "kubernetes": {      "type": "stdio",      "command": "npx",      "args": [        "-y",        "@dockndevai/mcp-kubernetes"      ],      "env": {        "KUBECONFIG_PATH": "/Users/you/.kube/config",        "K8S_MODE": "read-only"      }    }  }}

Run from source (development)

Prefer the published package above. To run from a clone:

bash
npm installnpm run buildnode dist/index.js   # with the environment variables set

Develop

bash
npm run dev        # watch modenpm test           # unit tests for the security policynpm run typecheck

Publishing

This server ships a server.json for the official MCP registry and an mcpName for npm ownership validation. See PUBLISHING.md for publishing to npm and listing on the MCP registry, Smithery, Glama, Cursor, and PulseMCP.

License

MIT

來源:README.md,提交 abda11f

工具

10

list_contexts

List kube-config contexts

List the contexts (clusters) available in the loaded kube-config.

無需輸入參數。

list_namespaces

List namespaces

List namespaces in the cluster. Namespaces outside the allowlist are filtered out.

輸入參數context

list_pods

List pods

List pods in a namespace with status, readiness, restarts, and node.

輸入參數contextnamespace必填

get_pod

Get pod

Fetch the full representation of a single pod.

輸入參數name必填contextnamespace必填

get_pod_logs

Get pod logs

Fetch recent logs from a pod container.

輸入參數name必填contextpreviouscontainernamespace必填tailLines

list_deployments

List deployments

List deployments in a namespace with replica status.

輸入參數contextnamespace必填

list_services

List services

List services in a namespace with type and cluster IP.

輸入參數contextnamespace必填

list_nodes

List nodes

List cluster nodes with readiness and kubelet version.

輸入參數context

list_events

List events

List recent events in a namespace — useful for diagnosing failures.

輸入參數contextnamespace必填

get_resource

Get any resource

Read an arbitrary Kubernetes object by apiVersion/kind/name (e.g. apiVersion=apps/v1, kind=Deployment).

輸入參數kind必填name必填contextnamespaceapiVersion必填

版本歷史

3
  1. v0.3.3最新Oct 26, 2026
  2. v0.3.0Sep 27, 2026
  3. v0.2.2Sep 16, 2026

評分

已滿足適用檢查項的 90%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分