kube-mcp
A Model Context Protocol server that lets AI assistants query multiple Kubernetes clusters simultaneously using natural language.
README
kube-mcp
A Model Context Protocol (MCP) server that lets AI assistants (Claude, VS Code extension, etc.) query multiple Kubernetes clusters simultaneously using natural language.
Each cluster runs a lightweight agent that connects back to a central MCP server. The AI talks to the central server and commands are routed to the right cluster transparently.

Architecture
Claude / VS Code Extension
│ MCP over HTTP
▼
┌─────────────────────┐
│ Central Server │ ← single endpoint, aggregates all clusters
│ (MCP + WebSocket) │
└──────┬──────────────┘
│ WebSocket (wss://)
┌────┴────┐
│ │
┌─▼──┐ ┌──▼──┐
│ A │ │ B │ cluster agents (one per cluster)
└────┘ └─────┘
k8s k8s in-cluster kubectl / helm (read-only)
- Central server — exposes an MCP HTTP endpoint and manages WebSocket connections from cluster agents.
- Cluster agent — deployed as a Kubernetes Deployment with a Helm chart. Uses the in-cluster service account for read-only
kubectl/helmaccess and connects outbound to the central server.
Features
- Query any connected cluster from a single MCP endpoint
- Per-cluster token authentication (each cluster has its own secret)
- Read-only by default — only
get,list,watchverbs allowed - Command injection protection — all arguments passed as arrays, no shell execution
- Blocked flags —
--server,--kubeconfig,--token, etc. are rejected - Output size cap (2 MB) and command timeout (55 s)
- Structured JSON logging with audit trail
- Liveness and readiness probes on the agent
- WebSocket reconnect with exponential backoff
- Per-IP WebSocket connection limit
- Agent reports kubectl and helm versions to the central server on connect
Available MCP Tools
| Tool | Description |
|---|---|
list_clusters |
List all connected clusters with versions and last-seen timestamps |
kubectl |
Run a read-only kubectl command against a specific cluster |
helm |
Run a read-only helm command against a specific cluster |
Example prompts
- "What pods are running in kube-system on my prod cluster?"
- "List all deployments across all clusters"
- "Show me the Helm releases installed on staging"
- "Describe the failing pod on eu-cluster"
Prerequisites
- Kubernetes clusters (1.24+)
- Helm 3
- A container registry to push the images to
- An ingress with TLS for the central server (recommended)
Quick Start
1. Build and push images
# Central server
docker build -t <your-registry>/central-server:latest \
-f packages/central-server/Dockerfile .
docker push <your-registry>/central-server:latest
# Cluster agent
docker build -t <your-registry>/cluster-agent:latest \
-f packages/cluster-agent/Dockerfile .
docker push <your-registry>/cluster-agent:latest
2. Deploy the central server
Generate an MCP API key and a token for each cluster agent:
openssl rand -hex 32 # MCP API key (for Claude / VS Code)
openssl rand -hex 32 # token for cluster-1
openssl rand -hex 32 # token for cluster-2
Install the Helm chart:
helm install central-server ./helm/central-server \
--namespace mcp-system --create-namespace \
--set image.repository=<your-registry>/central-server \
--set config.mcpApiKey="<mcp-api-key>" \
--set config.clusterTokens.prod-us="<token-for-prod-us>" \
--set config.clusterTokens.staging-eu="<token-for-staging-eu>" \
--set ingress.enabled=true \
--set ingress.hosts[0].host=mcp.example.com \
--set ingress.tls[0].hosts[0]=mcp.example.com \
--set ingress.tls[0].secretName=mcp-tls
The ingress must support WebSocket upgrades. For nginx-ingress add these annotations:
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
3. Deploy the cluster agent (repeat per cluster)
helm install cluster-agent ./helm/cluster-agent \
--namespace mcp-system --create-namespace \
--set image.repository=<your-registry>/cluster-agent \
--set config.centralServerUrl=wss://mcp.example.com \
--set config.clusterName=prod-us \
--set config.agentToken="<token-for-prod-us>"
Each cluster's
agentTokenmust match the corresponding entry inclusterTokenson the central server.
4. Connect your MCP client
VS Code (Claude extension) — .mcp.json in your project root:
{
"mcpServers": {
"multi-cluster-k8s": {
"type": "http",
"url": "https://mcp.example.com/mcp",
"headers": {
"X-Api-Key": "<mcp-api-key>"
}
}
}
}
Claude.ai — Remote MCP server URL:
https://mcp.example.com/mcp?api_key=<mcp-api-key>
5. Verify
Ask Claude: "List all connected clusters" — you should see your clusters with their kubectl and helm versions.
Configuration Reference
Central Server
| Environment variable | Required | Description |
|---|---|---|
CLUSTER_TOKENS |
Yes | JSON object mapping cluster names to tokens: {"prod":"token1","staging":"token2"} |
MCP_API_KEY |
No | API key for MCP clients. If unset, the MCP endpoint is open to anyone who can reach it. |
PORT |
No | HTTP port (default: 3000) |
LOG_LEVEL |
No | Pino log level (default: info) |
MAX_AGENT_CONNECTIONS_PER_IP |
No | Max WebSocket connections per source IP (default: 10) |
Cluster Agent
| Environment variable | Required | Description |
|---|---|---|
CENTRAL_SERVER_URL |
Yes | WebSocket URL of the central server, e.g. wss://mcp.example.com |
CLUSTER_NAME |
Yes | Name for this cluster — must match a key in CLUSTER_TOKENS on the server |
AGENT_TOKEN |
Yes | Token for this cluster — must match the corresponding value in CLUSTER_TOKENS |
INSECURE_TLS |
No | Set to true to skip TLS verification (dev only, never in production) |
Security
- Per-cluster tokens — every agent authenticates with its own unique token. A compromised cluster cannot impersonate another.
- Timing-safe comparison — token verification iterates all registered tokens without early exit to prevent timing attacks.
- Read-only RBAC — the cluster agent's ClusterRole only grants
get,list,watchverbs. - Verb allowlist — the executor validates every command against an allowlist before running it.
- Blocked flags — flags like
--server,--kubeconfig,--token,--execare rejected even if the verb is allowed. - No shell execution — all commands are passed as argument arrays to
child_process.spawn, preventing injection. - Non-root containers — both images run as UID 1000 with a read-only root filesystem.
- Output cap — command output is capped at 2 MB to prevent memory exhaustion.
Repository Structure
.
├── packages/
│ ├── central-server/ # MCP server + WebSocket hub
│ └── cluster-agent/ # In-cluster Kubernetes agent
├── helm/
│ ├── central-server/ # Helm chart for the central server
│ └── cluster-agent/ # Helm chart for the cluster agent
├── .dockerignore
├── .gitignore
└── package.json # npm workspace root
Development
npm install
npm run build # build both packages
Each package has its own tsconfig.json and compiles to dist/.
License
MIT — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。