Mcp K8s Ro

io.github.your-ko由 GitHub 账号 your-ko 发布v1.2.2更新于 Oct 30, 2026

Read-only Kubernetes MCP server: inspect resources, logs, events, and metrics. Secrets are masked.

概览

AI 生成的概览

只读的 Kubernetes MCP 服务器,让助手列出和查看资源、读取 Pod 日志与事件,并查询 CPU/内存用量。

可以做什么
  • 列出并查看集群资源,支持任意资源类型及其完整 YAML
  • 通过 discovery API 列出可用资源类型,可按 API 组过滤
  • 读取 Pod 日志,支持选择容器、指定行数以及查看崩溃前的日志
  • 按命名空间或整个集群列出 Kubernetes 事件,按时间倒序
  • 查看每个 Pod 和每个节点的 CPU 与内存用量,并给出占可分配容量的百分比
适用场景
适合值班和排障场景:让助手在不改动集群的前提下查看 Pod 状态、重启次数、日志、事件和资源压力。也适合希望每个服务器实例固定对应一个集群上下文的团队。
运行要求
以 stdio 本地进程运行,可使用预编译二进制或 Docker 镜像。需要 kubeconfig 文件,通过 KUBECONFIG 指定,默认 ~/.kube/config,并需具备目标集群的凭据。指标类工具要求集群中部署 metrics-server。macOS 二进制未签名,需要绕过 Gatekeeper。
安装前请注意
服务器通过 kubeconfig 持有集群凭据,并能读取日志、事件和资源 YAML,因此只应指向愿意暴露给模型的集群。Secret 的 data 与 stringData 会被遮蔽,但其他字段仍会返回。设计上为只读,需要变更时只打印 kubectl 命令;上下文在启动时固定,切换集群需重启。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Mcp K8s Ro,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[Main] [golangci-lint] [Link validation]

mcp-k8s-ro

A read-only MCP server that gives Claude access to Kubernetes clusters. Built in Go, it communicates over stdio using the MCP protocol.

Design

  • Read-only — only get, describe, logs, and top style operations. No create, update, or delete. If a mutating operation is needed, the server prints the equivalent kubectl command for you to run manually. Safe to use while on-call at night: Claude can never accidentally mutate your cluster, even under prompt fatigue.
  • Secret-safe — secret values are masked before being sent to the model, so your secrets cannot leak due to misconfiguration or prompt injection.
  • Token-efficient — responses include only relevant fields (name, status, restarts, etc.) rather than raw Kubernetes API objects, keeping context usage low.
  • Cluster-aware — every response includes the active context and cluster name, so Claude always knows which cluster it is talking to.
  • Context-pinned — the server locks to the active kubeconfig context at startup. Switching contexts in another terminal has no effect on the running server.
  • No extra infra — runs as a local binary or Docker container, connects to whatever kubeconfig context is active at startup.

Redacted fields

Object/FieldReason
Secret.dataSecret leak prevention
Secret.stringDataSecret leak prevention
CertificateSigningRequest.spec.requestLarge base64 PEM blob, no diagnostic value, saves tokens
Certificate (cert-manager) .spec.keystoresCert chain PEM blobs, no diagnostic value, saves tokens
Certificate (cert-manager) status.conditions[].messageCert chain PEM blobs, no diagnostic value, saves tokens
*.managedFieldsNo diagnostic value, saves tokens

Tools

ToolDescription
k8s_list_resourcesList any resource type by name — pods, deployments, CRDs, etc. Accepts optional namespace filter. Returns name, status, readiness, restarts, node, IP, and more depending on resource kind.
k8s_describe_resourceReturn the full YAML of a single resource. Secret data is masked.
k8s_list_resource_typesList all available resource types via the discovery API. Accepts optional API group filter.
k8s_get_logsFetch pod logs. Supports container selector, tail lines, and --previous for crashed containers.
k8s_get_eventsList Kubernetes events for a namespace or the whole cluster, sorted by most recent.
k8s_top_podsCPU and memory usage per pod, with per-container breakdown. Requires metrics-server.
k8s_top_nodesCPU and memory usage per node, with percentage of allocatable capacity. Requires metrics-server.

Configuration

Environment variableDefaultDescription
KUBECONFIG~/.kube/configPath to kubeconfig file

Usage with Claude

Docker (recommended)

bash
claude mcp add --scope user --transport stdio k8s-ro \  -- docker run --rm -i -v ~/.kube:/home/nonroot/.kube:ro ghcr.io/your-ko/mcp-k8s-ro:latest

Pinning a specific version (check the latest release ) is recommended for production use:

bash
claude mcp add --scope user --transport stdio k8s-ro \  -- docker run --rm -i -v ~/.kube:/home/nonroot/.kube:ro ghcr.io/your-ko/mcp-k8s-ro:1.1.0

Binary

Download a pre-built binary from GitHub Releases:

bash
# macOS Apple Silicon — change ARCH for other platforms: darwin-amd64, linux-amd64, linux-arm64ARCH=darwin-arm64VERSION=$(curl -fsSL https://api.github.com/repos/your-ko/mcp-k8s-ro/releases/latest | grep tag_name | cut -d'"' -f4)curl -fsSL "https://github.com/your-ko/mcp-k8s-ro/releases/download/${VERSION}/mcp-k8s-ro-${VERSION}-${ARCH}" -o ~/.local/bin/mcp-k8s-rochmod +x ~/.local/bin/mcp-k8s-roxattr -d com.apple.quarantine ~/.local/bin/mcp-k8s-ro 2>/dev/null  # macOS only: remove Gatekeeper quarantineclaude mcp add --scope user --transport stdio k8s-ro ~/.local/bin/mcp-k8s-ro

macOS Gatekeeper: The binary is not code-signed, so macOS will block it. The xattr command above removes the quarantine flag. Alternatively, go to System Settings → Privacy & Security and click "Allow Anyway" after the first blocked attempt. [img.png]

Or build from source:

bash
make buildclaude mcp add --scope user --transport stdio k8s-ro ./bin/mcp-k8s-ro

Custom kubeconfig location

If your kubeconfig is not at ~/.kube/config, set the KUBECONFIG environment variable:

bash
# Binaryclaude mcp add --scope user --transport stdio -e KUBECONFIG=/path/to/kubeconfig k8s-ro ~/.local/bin/mcp-k8s-ro
# Dockerclaude mcp add --scope user --transport stdio k8s-ro \  -- docker run --rm -i -e KUBECONFIG=/config/kubeconfig -v /path/to/kubeconfig:/config/kubeconfig:ro ghcr.io/your-ko/mcp-k8s-ro:latest

Single-cluster design

The server intentionally operates on one kubeconfig context and provides no tool to switch clusters at runtime. The reasons are:

  • Prompt injection isolation — a malicious value in one cluster's resources (e.g. a pod annotation) cannot instruct Claude to pivot to a different cluster, including production.
  • Explicit audit boundary — every tool response includes the context and cluster name, so there is never ambiguity about which cluster was queried.

To point the server at a different cluster, stop the server, switch context, and restart:

bash
kubectl config use-context my-other-cluster# then restart the MCP server / reload Claude Desktop

To work with multiple clusters simultaneously, register a separate server instance per cluster in your MCP config:

json
{  "mcpServers": {    "k8s-staging": {      "type": "stdio",      "command": "/path/to/bin/mcp-k8s-ro",      "env": { "KUBECONFIG": "/path/to/.kube/config" }    },    "k8s-prod": {      "type": "stdio",      "command": "/path/to/bin/mcp-k8s-ro",      "env": { "KUBECONFIG": "/path/to/.kube/config-prod" }    }  }}

Claude will address each server by name and each instance only ever sees its own cluster.

MCP registry

This server is published on registry.modelcontextprotocol.io

来源:README.md,提交 d083672

工具

0
SourceWeft 曾在隔离沙箱中以无凭据方式启动该软件包一次,以列出其工具,但未能完成:该软件包类型无法在沙箱中运行。

版本历史

2
  1. v1.2.2最新Oct 30, 2026
  2. v1.2.1Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分