Kubernetes MCP E3b29152

MCP运维云端

提供方 achetronic

运维云端 stdio · 本地进程 OAuth 授权 社区 / 第三方
查看接入方式

一个通过自然语言管理Kubernetes集群的工具,提供25种Kubernetes操作工具、多集群支持、高级RBAC和企业级安全功能。

一句话选型结论

按资料字段整理

Kubernetes MCP E3b29152 属于运维云端类 MCP 服务器,stdio · 本地进程,OAuth 授权,有可直接执行的安装命令。接入前先确认权限范围;涉及写入、删除或付款的操作,建议先在测试环境验证。

分类运维云端 传输方式stdio · 本地进程 鉴权OAuth 授权 部署方式本地部署
GitHub 星标 40 仓库热度,无公开仓库时显示未标注
工具数 25 暴露给模型的工具数量
资源 / 提示词 0 / 0 资源与提示词模板数量
维护方 社区 / 第三方 核验等级 仅资料核对

工具与能力

运维云端
数量来自来源目录的标注,具体工具清单以官方文档为准
工具数量25暴露给模型可调用的工具个数
资源数量0可读取的资源条目
提示词数量0内置提示词模板数量

能力标签

适用场景

Kubernetes管理Go本地部署自然语言处理多集群支持RBAC企业安全

安装与配置

stdio · 本地进程 OAuth 授权
客户端在本机拉起子进程,数据不出本机
docker run -d \

这条命令只是入口,具体启动参数请按官方文档补齐,不要直接照搬到别的服务器。

  1. 1
    准备运行环境

    stdio 服务在本地起进程,需要先装好 Docker,再按安装命令拉取依赖。

  2. 2
    安装服务

    复制上面的安装命令执行;命令里带占位符的位置,换成自己的密钥或路径。

  3. 3
    写入客户端配置

    在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4
    验证是否可用

    连接成功后客户端会列出约 25 个工具,随便调一个只读工具确认能返回结果。

典型使用场景

3 类
按分类与标签整理的常见用法,具体以官方文档为准
云资源查询

查实例、存储、账单等云上资源状态。

部署与发布

把部署、重启、回滚这类操作接进对话。

监控与告警

拉取监控指标,异常时让模型帮你判断。

选择建议

选之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 资料标注 25 个工具,覆盖面较广,能满足多种调用。
  • 有现成的安装命令,不用自己找入口,照着跑就能起服务。

先想清楚的地方

  • stdio 方式要求本地装好运行时(如 Node.js),换机器要重新装一遍。
  • 使用前要准备好OAuth 授权对应的凭据,并按最小权限配置。
  • 版本更新与行为细节以官方仓库为准。

更适合

  • 需要在运维云端场景里让模型直接调用外部能力的人。
  • 想先快速试一下、能接受在本地或自有环境跑服务的人。

不太适合

  • 完全不想在本地装环境的人。
  • 不方便管理密钥或第三方授权的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
MCP 服务器工具数传输方式部署方式安装命令最后核验
Kubernetes MCP E3b29152当前 25 stdio · 本地进程 本地部署 有 2026-05-17
lobehub 未标注 stdio · 本地进程 本地部署 有 2026-04-11
TrendRadar 未标注 stdio · 本地进程 本地部署 有 2026-04-13
Ui Tars Desktop 8a825770 未标注 stdio · 本地进程 本地部署 有 2026-05-17
ruflo 未标注 stdio · 本地进程 本地部署 有 2026-04-13
FastGPT 未标注 stdio · 本地进程 本地部署 有 2026-04-11

服务器档案

运维云端
字段来自项目仓库与公开索引,中文说明由本站标注
提供方achetronic上游标注的维护方 achetronic
分类运维云端本站按上游分类展示
连接方式stdio · 本地进程客户端在本机拉起子进程,数据不出本机
鉴权方式OAuth 授权远程服务建议用最小权限凭据
维护方社区 / 第三方核验等级 仅资料核对
包名 / 运行时未标注 · Docker本地安装时用到的包标识与运行时
部署类型本地部署上游给出的部署形态
最近核验2026-05-17上游最后核验时间

详细介绍

28.0 KB
来自项目仓库与上游目录的原文,未做删改

Why Kubernetes MCP?

AI assistants are powerful, but they struggle with Kubernetes because:

  • Context window limits: A single kubectl get pods -A can blow your token budget
  • Security concerns: You don't want AI deleting your production database
  • Multi-cluster complexity: Jumping between clusters is error-prone

Features

🎯 25 Kubernetes Tools

Full cluster management through natural language:

Category Tools
Read get_resource, list_resources, describe_resource
Modify apply_manifest, patch_resource, delete_resource, delete_resources
Scale & Rollout scale_resource, get_rollout_status, restart_rollout, undo_rollout
Debug get_logs, exec_command, list_events
Cluster Info get_cluster_info, list_api_resources, list_api_versions, list_namespaces
Context get_current_context, list_contexts, switch_context
RBAC & Metrics check_permission, get_pod_metrics, get_node_metrics
Diff diff_manifest

All resource-addressing tools take GVR parameters: group + version + resource (plural lowercase form, e.g. pods, deployments, ingresses, storageclasses). NOT the Kind. The two manifest tools (apply_manifest, diff_manifest) parse apiVersion/kind from the YAML and resolve the GVR via the cluster's discovery API, so CRDs and irregular plurals work transparently.

Built-in safety rails:

  • apply_manifest rejects multi-document YAML and reports created vs updated.
  • delete_resources requires either namespace or an explicit all_namespaces=true (mutually exclusive), and refuses to delete more than kubernetes.tools.bulk_operations.max_resources_per_operation items per call (default 100).
  • get_logs truncates output at 1 MiB; exec_command is non-interactive, supports a configurable timeout_seconds (1..300, default 30) and caps stdout+stderr at 1 MiB.
  • restart_rollout / undo_rollout only operate on apps/{deployments,statefulsets,daemonsets}; undo_rollout defaults to N-1 (kubectl-compatible) and reads ReplicaSet history for Deployments / ControllerRevisions for StatefulSets and DaemonSets.

🔍 Context-Window-Friendly Filtering

All tools support yq expressions to filter responses before they reach your AI. Just ask naturally:

> "Get the image of the my-app deployment"

The AI automatically uses filtering to return just nginx:1.25 instead of 200+ lines of YAML — saving your context window for what matters.

Complex queries work too:

> "List all running pods with their IPs"

Behind the scenes, the AI chains multiple yq expressions to filter and transform the response.

🔐 Advanced RBAC

Fine-grained access control with rules-based policies — filter by tools, contexts, API groups, resources (plural GVR), namespaces, and resource names. Deny always wins, default deny, full glob support. See Authorization for details and examples.

🌐 Multi-Cluster Support

Manage multiple clusters with independent configurations:```yaml
kubernetes:
default_context: "staging"
contexts:
- name: "production"
kubeconfig: "/etc/kubernetes/prod.kubeconfig"
description: "Production - handle with care"
denied_namespaces: ["kube-system", "istio-system"]

- name: "staging"
  kubeconfig: "/etc/kubernetes/staging.kubeconfig"
  description: "Staging - safe for testing"

- name: "development"
  kubeconfig: "/etc/kubernetes/dev.kubeconfig"
  description: "Development - experiment freely"

# Or auto-load from directory (context name = current-context of each file)
contexts_dir: "/etc/kubernetes/clusters/"


**Hot-reload**: Kubeconfig files are watched for changes. When a sidecar or external process updates a kubeconfig, the client is automatically reloaded — no restart required.

🛡️ Enterprise-Ready Security

- **OAuth 2.1 compliant** with RFC 8414 and RFC 9728 endpoints
- **JWT validation** with JWKS and CEL-based claim conditions
- **API key authentication** with static tokens and configurable payloads
- **Namespace allow/deny lists** per cluster
- **Access logs** with header redaction

---

## Quick Start

### Option 1: Claude Desktop (Local Binary)

**1. Download the binary:**```bash
# Linux
curl -L https://github.com/achetronic/kubernetes-mcp/releases/latest/download/kubernetes-mcp-linux-amd64.tar.gz | tar xz

# macOS (Intel)
curl -L https://github.com/achetronic/kubernetes-mcp/releases/latest/download/kubernetes-mcp-darwin-amd64.tar.gz | tar xz

# macOS (Apple Silicon)
curl -L https://github.com/achetronic/kubernetes-mcp/releases/latest/download/kubernetes-mcp-darwin-arm64.tar.gz | tar xz

2. Create config file:```yaml

~/.config/kubernetes-mcp/config.yaml

server:
name: "Kubernetes MCP"
version: "0.1.0"
transport:
type: "stdio"

middleware:
jwt:
enabled: false

kubernetes:
default_context: "default"
contexts:
- name: "default"
kubeconfig: "" # Empty: $KUBECONFIG -> ~/.kube/config -> in-cluster
description: "Local cluster"
discovery:
refresh_interval: "10m"

authorization:
allow_anonymous: true
policies:
- name: "allow-all"
match:
expression: "true"
rules:
- effect: allow
tools: [""]
contexts: ["
"]
resources:
- groups: [""]
resources: ["
"]
- groups: ["_"]
resources: ["*"]


**3. Configure Claude Desktop:**

Edit `claude_desktop_config.json`:```json
{
  "mcpServers": {
    "kubernetes": {
      "command": "/path/to/kubernetes-mcp",
      "args": ["--config", "/path/to/config.yaml"]
    }
  }
}

4. Restart Claude Desktop and start managing your clusters!


Option 2: Docker

1. Create a config file:```yaml

config.yaml

server:
name: "Kubernetes MCP"
version: "0.1.0"
transport:
type: "http"
http:
host: ":8080"

middleware:
jwt:
enabled: false

kubernetes:
default_context: "default"
contexts:
- name: "default"
kubeconfig: "/root/.kube/config"
description: "My Kubernetes cluster"
discovery:
refresh_interval: "10m"

authorization:
allow_anonymous: true
policies:
- name: "allow-all"
match:
expression: "true"
rules:
- effect: allow
tools: [""]
contexts: ["
"]
resources:
- groups: [""]
resources: ["
"]
- groups: ["_"]
resources: ["*"]


**2. Run with Docker:**```bash
docker run -d \
  --name kubernetes-mcp \
  -p 8080:8080 \
  -v ~/.kube/config:/root/.kube/config:ro \
  -v $(pwd)/config.yaml:/config.yaml:ro \
  ghcr.io/achetronic/kubernetes-mcp:latest \
  --config /config.yaml

3. Test it:

The MCP server exposes the protocol under /mcp (POST, JSON-RPC) and OAuth
discovery under /.well-known/oauth-* when those are enabled. There is no
plain /health endpoint; verify the server is up by issuing the MCP
initialize handshake:```bash
curl -s -X POST http://localhost:8080/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}'


A `200` response with a `serverInfo` block means the server is up and
talking MCP. The response also includes an `Mcp-Session-Id` header that
clients propagate on subsequent requests.

---

### Option 3: Kubernetes with Helm

We use bjw-s/app-template directly — a popular generic Helm chart that avoids reinventing the wheel. No wrapper chart needed.```bash
# Add the bjw-s repository
helm repo add bjw-s https://bjw-s-labs.github.io/helm-charts
helm repo update

# Download our values file and install
curl -LO https://raw.githubusercontent.com/achetronic/kubernetes-mcp/master/chart/values.yaml
helm install kubernetes-mcp bjw-s/app-template --version 4.2.0 \
  -f values.yaml -n kubernetes-mcp --create-namespace

Edit values.yaml to configure your environment. See chart/values.yaml for all options.

In-cluster credentials and RBAC

When running inside the cluster, leave kubeconfig: "" in your config and
the server will fall through to the Pod's ServiceAccount token
(/var/run/secrets/kubernetes.io/serviceaccount). The chart values do
not ship a default ClusterRoleBinding — you decide what the server is
allowed to do at the Kubernetes RBAC level. A minimal "let it do
everything" example to drop into your manifests:```yaml


apiVersion: v1
kind: ServiceAccount
metadata:
name: kubernetes-mcp
namespace: kubernetes-mcp


apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kubernetes-mcp
rules:
- apiGroups: [""]
resources: ["
"]
verbs: [""]
- nonResourceURLs: ["
"]
verbs: ["get"]


apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubernetes-mcp
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubernetes-mcp
subjects:
- kind: ServiceAccount
name: kubernetes-mcp
namespace: kubernetes-mcp


This is the equivalent of `cluster-admin` for the ServiceAccount. Restrict
the rules block before exposing the server outside trusted networks. The
MCP authorization layer (CEL policies) is independent from the cluster's
RBAC and is checked first; both layers must allow a call for it to reach
the API server.

---

## Configuration Reference

### Complete Example```yaml
# MCP Server Configuration
server:
  name: "Kubernetes MCP"
  version: "0.1.0"
  transport:
    type: "http" # or "stdio"
    http:
      host: ":8080"

# Middleware Configuration
middleware:
  access_logs:
    excluded_headers:
      - X-Request-Id
    redacted_headers:
      - Authorization

  jwt:
    enabled: true
    validation:
      jwks_uri: "https://keycloak.example.com/realms/mcp/protocol/openid-connect/certs"
      cache_interval: "10s"
      allow_conditions:
        - expression: "has(payload.email)"

  api_keys:
    enabled: true
    keys:
      - name: "ci-cd-pipeline"
        token: "$CI_API_KEY"
        payload:
          sub: "ci-cd-service"
          email: "ci@company.com"
          groups:
            - "ci-cd"

# OAuth Configuration (optional, for remote clients)
oauth_authorization_server:
  enabled: true
  issuer_uri: "https://keycloak.example.com/realms/mcp"

oauth_protected_resource:
  enabled: true
  resource: "https://kubernetes-mcp.example.com/mcp"
  auth_servers:
    - "https://keycloak.example.com/realms/mcp"
  scopes_supported: [openid, profile, email, groups]

# Kubernetes Configuration
kubernetes:
  default_context: "production"

  # Explicit contexts with custom names
  contexts:
    - name: "production"
      kubeconfig: "/etc/kubernetes/prod.kubeconfig"
      kubeconfig_context: "gke_myproject_prod"  # Optional: use specific context from kubeconfig
      description: "Production cluster"
      allowed_namespaces: [] # Empty = all allowed
      denied_namespaces:
        - kube-system
        - kube-public
        - istio-system

    - name: "staging"
      kubeconfig: "/etc/kubernetes/staging.kubeconfig"
      description: "Staging cluster"

  # Auto-load kubeconfigs from directory (context name = current-context of each file)
  # contexts_dir: "/etc/kubernetes/clusters/"

  # API discovery cache. The RESTMapper uses it to translate Kind <-> Resource
  # for 'apply_manifest' / 'diff_manifest', to resolve the Kind in
  # 'describe_resource' (used to filter related events) and to surface newly
  # installed CRDs. The cache is invalidated on this interval. Default: 10m.
  discovery:
    refresh_interval: "10m"

  tools:
    bulk_operations:
      # Hard cap on the number of resources delete_resources may match in a
      # single call. Selectors that match more are rejected. Default: 100.
      max_resources_per_operation: 100

# Authorization Configuration
authorization:
  allow_anonymous: false
  policies:
    - name: "sre-full-access"
      description: "SRE team has full access"
      match:
        expression: 'payload.groups.exists(g, g == "sre-team")'
      rules:
        - effect: allow
          tools: ["*"]
          contexts: ["*"]
          resources:
            - groups: ["*"]
              resources: ["*"]
            - groups: ["_"]
              resources: ["*"]

    - name: "developers-limited"
      description: "Developers: full in staging, read-only in prod"
      match:
        expression: 'payload.groups.exists(g, g == "developers")'
      rules:
        - effect: allow
          tools: ["*"]
          contexts: ["staging"]
          resources:
            - groups: ["*"]
              resources: ["*"]
        - effect: deny
          tools: ["delete_resource", "delete_resources", "exec_command"]
          contexts: ["production"]

Environment Variables

All config values support environment variable expansion at load time
($VAR or ${VAR}):```yaml
kubernetes:
contexts:
- name: "production"
kubeconfig: "$PROD_KUBECONFIG" # Expanded at runtime


### Authentication

Kubernetes MCP supports two authentication methods. Both produce the same `payload` map used
by authorization policies, so RBAC rules work identically regardless of the method.

#### JWT Validation

Validates Bearer tokens against a JWKS endpoint. Claims from the JWT become the `payload`
available in CEL expressions.```yaml
middleware:
  jwt:
    enabled: true
    validation:
      jwks_uri: "https://keycloak.example.com/realms/mcp/protocol/openid-connect/certs"
      cache_interval: "10s"
      allow_conditions:
        - expression: 'has(payload.email)'
Field Description
jwks_uri URL to the JWKS endpoint for signature verification
cache_interval How often to refresh the JWKS keys
allow_conditions CEL expressions that must all evaluate to true for the JWT to be accepted

API Key Authentication

Static Bearer tokens with a preconfigured payload. Useful for CI/CD pipelines, service accounts,
or environments where an identity provider is not available.```yaml
middleware:
api_keys:
enabled: true
keys:
- name: "ci-cd-pipeline"
token: "$CI_API_KEY"
payload:
sub: "ci-cd-service"
email: "ci@company.com"
groups:
- "ci-cd"

  - name: "monitoring"
    token: "$MONITORING_API_KEY"
    payload:
      sub: "monitoring-agent"
      groups:
        - "readonly"

| Field | Description |
|-------|-------------|
| `name` | Human-readable identifier for the key (used in logs) |
| `token` | The Bearer token value. Supports environment variable expansion |
| `payload` | Map of fields injected as the authentication payload for RBAC evaluation |

> **Security**: Tokens are compared using constant-time comparison (SHA-256 hashed at startup)
> to prevent timing attacks. Use environment variables (`$CI_API_KEY`) instead of hardcoding tokens.

#### Combined Usage

When both methods are enabled, the middleware chain tries JWT first. If the token is not a valid JWT,
it falls through to API key matching. If neither succeeds, the request proceeds unauthenticated
(denied by default unless `allow_anonymous: true`).

### Authorization Policy Evaluation

1. If no payload and anonymous not allowed → **deny**
2. Find **all** policies whose `match` CEL expression is true
3. Collect **all rules** from matched policies into a flat list
4. If **ANY deny rule** matches the request → **deny** (deny always wins)
5. If **ANY allow rule** matches the request → **allow**
6. Default: **deny**

**Deny takes priority**: A deny rule always overrides an allow rule, regardless of which policy it comes from. Omitting a tool from all allow rules also denies it (default deny).

### Resource-Level Authorization

Control access by **API group**, **resource** (plural lowercase GVR), **namespace**, and **name**.

#### Reference

| Field | Example | Behavior when omitted |
|-------|---------|----------------------|
| `groups` | `[""]` (core), `["apps"]`, `["_"]` (virtual) | Any group |
| `versions` | `["v1"]`, `["v1beta1"]` | Any version |
| `resources` | `["pods", "secrets"]` | Any resource |
| `namespaces` | `["default"]`, `["team-*"]`, `[""]` (cluster-scoped) | Any namespace + cluster-scoped |
| `names` | `["myapp-*"]`, `["*-config"]` | Any name |

> **Tip**: Resources use plural lowercase form matching Kubernetes GVR (e.g. `pods`, `deployments`, `configmaps`). Omit `versions` unless you need a specific API version.

#### Wildcards

| Pattern | Meaning |
|---------|---------|
| `*` | Match all |
| `prefix-*` | Starts with |
| `*-suffix` | Ends with |

#### Example: Allow everything except sensitive resources```yaml
- name: "all-except-sensitive"
  match:
    expression: "true"
  rules:
    - effect: allow
      tools: ["*"]
      contexts: ["*"]
      resources:
        - groups: ["*"]
          resources: ["*"]
        - groups: ["_"]
          resources: ["*"]
    - effect: deny
      resources:
        - groups: [""]
          resources: ["secrets"]
        - groups: ["rbac.authorization.k8s.io"]
          resources: ["*"]
        - groups: ["certificates.k8s.io"]
          resources: ["*"]
        - groups: ["*"]
          resources: ["*"]
          namespaces: ["kube-system", "kube-public"]

Example: Block Secrets```yaml

  • name: "no-secrets"
    match:
    expression: "true"
    rules:
    • effect: allow
      tools: [""]
      contexts: ["
      "]
      resources:
      • groups: [""]
        resources: ["
        "]
    • effect: deny
      resources:
      • groups: [""]
        resources: ["secrets"]

#### Example: Read-only, no sensitive resources```yaml
- name: "read-only-safe"
  match:
    expression: '"developers" in payload.groups'
  rules:
    - effect: allow
      tools: ["get_resource", "list_resources", "describe_resource", "get_logs"]
      contexts: ["*"]
      resources:
        - groups: ["", "apps", "batch", "networking.k8s.io"]
          resources: ["*"]
    - effect: deny
      tools: ["get_*", "list_*", "describe_*"]
      resources:
        - groups: [""]
          resources: ["secrets"]
        - groups: ["rbac.authorization.k8s.io"]
          resources: ["*"]

Example: Write only in team namespaces```yaml

  • name: "write-own-namespaces"
    match:
    expression: '"developers" in payload.groups'
    rules:
    • effect: allow
      tools: ["apply_manifest", "patch_resource", "delete_resource"]
      contexts: ["staging"]
      resources:
      • groups: ["", "apps"]
        resources: [""]
        namespaces: ["team-
        "]
    • effect: deny
      resources:
      • groups: [""]
        resources: ["secrets"]

#### Example: CI/CD service account```yaml
- name: "cicd-deploy"
  match:
    expression: 'payload.client_id == "ci-cd-service"'
  rules:
    - effect: allow
      tools: ["apply_manifest", "diff_manifest", "get_resource"]
      contexts: ["production"]
      resources:
        - groups: ["", "apps"]
          resources: ["deployments", "services", "configmaps"]
          namespaces: ["app-*"]

Example: Full admin access```yaml

  • name: "sre-full-access"
    match:
    expression: '"sre" in payload.groups'
    rules:
    • effect: allow
      tools: [""]
      contexts: ["
      "]
      resources:
      • groups: [""]
        resources: ["
        "]
      • groups: ["_"]
        resources: ["*"]

#### Example: Safe operations (read + selective delete)

A production-safe policy. The allow rules cover read, diff, scale, rollout
and pod logs. `delete_resource` is permitted only for pods in the
`aplicacion-*` namespaces (and `default`). Anything not listed in any allow
rule is denied by default — including `apply_manifest`, `patch_resource`
and `delete_resources`. The deny rules narrow the allows further: reading
secrets, service accounts and the various secret-management CRDs is
forbidden, and `exec_command` is blocked outright.```yaml
- name: "safe-operations"
  match:
    expression: 'has(payload.sub)'
  rules:
    - effect: allow
      tools: ["get_*", "list_*", "describe_*", "diff_*", "check_*", "scale_*", "*_rollout*", "get_logs"]
      contexts: ["*"]
      resources:
        - groups: ["*"]
          resources: ["*"]
        - groups: ["_"]
          resources: ["*"]
    - effect: allow
      tools: ["delete_resource"]
      resources:
        - groups: [""]
          resources: ["pods"]
          namespaces: ["aplicacion-*", "default"]
    - effect: deny
      tools: ["get_*", "list_*", "describe_*"]
      resources:
        - groups: [""]
          resources: ["secrets", "serviceaccounts"]
        - groups: ["external-secrets.io", "cert-manager.io", "certificates.k8s.io"]
          resources: ["*"]
    - effect: deny
      tools: ["exec_command"]

Virtual MCP Resources

Tools that don't operate on K8s resources use virtual resources under group _:

Tools Resource
list_api_resources, list_api_versions apidiscovery
get_cluster_info clusterinfo
get_current_context, list_contexts, switch_context contexts
# Allow discovery and context switching
resources:
  - groups: ["_"]
    resources: ["apidiscovery", "clusterinfo", "contexts"]

Usage Examples

Ask your AI assistant:```

"List all pods in the production namespace that are not running"


The AI will use:```yaml
tool: list_resources
version: v1
resource: pods       # plural lowercase GVR, NOT the Kind
namespace: production
yq_expressions:
  - '.items[] | select(.status.phase != "Running") | {name: .metadata.name, phase: .status.phase}'

More examples:

Request Tool Used
"What's using the most memory in staging?" get_pod_metrics with yq sort
"Restart the api deployment" restart_rollout
"Show me the diff if I change the image to nginx:1.26" diff_manifest
"Scale the workers to 5 replicas" scale_resource
"Why is the payment pod failing?" describe_resource + get_logs
"Switch to the development cluster" switch_context

Development

Prerequisites

  • Go 1.25+
  • Access to a Kubernetes cluster
  • (Optional) Docker for building images

Build & Run```bash

Build binary

make build

Run with HTTP transport

make run

Run with custom config

./bin/kubernetes-mcp-linux-amd64 --config /path/to/config.yaml


### Project Structure```
kubernetes-mcp/
├── cmd/main.go                    # Entrypoint
├── api/config_types.go            # Configuration types
├── internal/
│   ├── k8stools/                  # MCP tools implementation
│   │   ├── manager.go             # Tool registration
│   │   ├── helpers.go             # Shared utilities
│   │   ├── tools_read.go          # get_resource, list_resources, describe_resource
│   │   ├── tools_modify.go        # apply, patch, delete
│   │   ├── tools_scale_rollout.go # scale, rollout operations
│   │   ├── tools_logs_exec.go     # logs, exec, events
│   │   ├── tools_cluster.go       # cluster info, namespaces, api resources
│   │   ├── tools_context.go       # context management
│   │   ├── tools_rbac_metrics.go  # permissions, metrics
│   │   ├── tools_diff.go          # manifest diff
│   │   └── e2e_*_test.go          # End-to-end tests (build tag 'e2e')
│   ├── kubernetes/client.go       # Multi-cluster client manager
│   ├── authorization/evaluator.go # RBAC evaluator
│   ├── yqutil/evaluator.go        # yq expression processor
│   ├── middlewares/               # Auth, JWT, API key, logging middlewares
│   └── handlers/                  # OAuth endpoints
├── docs/
│   ├── config-http.yaml           # HTTP mode example
│   └── config-stdio.yaml          # Stdio mode example
├── chart/                         # Helm values for bjw-s/app-template
├── .agents/                       # Internal architecture & design docs
└── .github/workflows/             # CI: release-binaries, release-docker-images, e2e-tests

Adding a New Tool

  1. Create handler in internal/k8stools/tools_.go:```go
    func (m *Manager) registerMyTool() {
    tool := mcp.NewTool("my_tool",
    mcp.WithDescription("Does something useful"),
    mcp.WithString("param", mcp.Required(), mcp.Description("A parameter")),
    )
    m.mcpServer.AddTool(tool, m.handleMyTool)
    }

func (m Manager) handleMyTool(ctx context.Context, request mcp.CallToolRequest) (mcp.CallToolResult, error) {
args := request.GetArguments()
// ... implementation
return successResult("Done!"), nil
}


2. Register in `manager.go`:```go
func (m *Manager) RegisterAll() {
    // ... existing tools
    m.registerMyTool()
}

Running Tests```bash

Format and vet

make fmt
make vet

Lint (auto-installs golangci-lint)

make lint

Unit tests (no cluster needed)

make test

End-to-end tests against a Kind cluster

- 'kind-up' creates a local Kind cluster (idempotent)

- 'test-e2e' runs the e2e suite (build tag 'e2e')

- 'kind-down' deletes the cluster

- 'test-e2e-clean' = down + up + tests + down (CI-style)

make test-e2e
make test-e2e-clean

Run e2e against an existing cluster (no Kind dance)

KMCP_E2E_CONTEXT=$(kubectl config current-context) \
go test -tags=e2e -timeout 10m ./internal/k8stools/...


#### End-to-End Tests

The e2e suite lives in `internal/k8stools/e2e_*_test.go` (build tag `e2e`). It exercises every tool against a real cluster, with each test running in its own throw-away namespace. Coverage includes:

| Area | Highlights |
|------|-----------|
| Read | `get_resource`, `list_resources` filters, `describe_resource` with events resolved via RESTMapper |
| Modify | `apply_manifest` create/update round-trip preserving `Service.clusterIP`, multi-doc rejection, patch types, delete + bulk cap + cross-namespace barrier |
| Scale / Rollout | scale, rollout status (Deployment / StatefulSet / DaemonSet), restart, **undo for all three workload kinds** |
| Cluster info | `list_namespaces`, `list_api_resources` (group / namespaced filters), `list_api_versions`, `get_cluster_info` |
| Logs / exec / events | log retrieval and tail, exec with output cap, events sorted by timestamp and filtered by type/field selector |
| RBAC / metrics | `check_permission` including subresource (`pods/exec`), graceful degradation when metrics-server is missing |
| Discovery | newly-installed CRDs become visible after `RESTMapper.Reset()` |
| Hardening | empty-patch rejection, `replicas` validation, `propagation_policy` validation, `delete_resources` element cap, `apply_manifest` create-vs-update |

Set `KMCP_E2E_CONTEXT` to the kubeconfig context to use (defaults to the kubeconfig's current-context). Tests skip metrics happy paths when metrics-server is not installed.

CI runs the same suite on every PR and push to `master` via `.github/workflows/e2e-tests.yaml` using `helm/kind-action`.

### Building Docker Image```bash
make docker-build IMG=your-registry/kubernetes-mcp:tag

Documentation

  • MCP Specification
  • MCP Authorization
  • RFC 9728 - OAuth Protected Resource Metadata
  • mcp-go Library
  • CEL Expressions
  • yq Manual

Contributing

All contributions are welcome! Whether you're reporting bugs, suggesting features, or submitting code — thank you!

  • Open an issue to report bugs or request features
  • Submit a pull request to contribute improvements

License

Kubernetes MCP is licensed under the Apache 2.0 License.

常见问题

7 问
答案由本站依据条目字段整理,不引用上游原文
Kubernetes MCP E3b29152 怎么安装?

在客户端按下面的安装命令接入:docker run -d \。装完在客户端配置里引用同一个包或端点。

Kubernetes MCP E3b29152 怎么在客户端里配置?

它的传输方式未标注,在客户端 MCP 配置里按官方文档填写启动命令和参数,保存后重启客户端生效。

Kubernetes MCP E3b29152 收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

Kubernetes MCP E3b29152 需要 API Key 吗?

资料标注需要OAuth 授权认证,使用前准备好对应凭据,并按最小权限配置。

Kubernetes MCP E3b29152 能提供哪些能力?

资料显示约 25 个工具;能力标签包括 Kubernetes管理、Go、企业安全、自然语言处理。具体工具清单以官方文档为准。

Kubernetes MCP E3b29152 需要什么运行环境?

运行时为 Docker;属于本地进程,需要在本机装好运行环境。

Kubernetes MCP E3b29152 是本地还是远程?

它是本地进程(stdio),由客户端在本机拉起。传输方式为stdio · 本地进程。

热门专题

按标签挑服务器
全部专题 →

服务器信息以作者仓库与官方文档为准;分类、传输方式与鉴权方式的中文说明为中文整理,最近核验 2026-05-17。