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 分