k8s-mcp
A lightweight MCP server that enables AI assistants to deploy, inspect, and operate Kubernetes workloads through high-level workflow tools, reducing token usage with structured outputs.
README
k8s-mcp
AI-native Kubernetes operations for agents and fast-moving teams.
k8s-mcp is a lightweight MCP server that lets AI assistants deploy, inspect, and operate Kubernetes workloads through high-level workflow tools instead of raw kubectl commands — with structured outputs that significantly reduce token usage.
Works with Claude Code · Codex CLI · Gemini CLI · Opencode · and any MCP-compatible agent.
Less kubectl. More done.
Demo
<!-- Replace VIDEO_ID below with your YouTube video ID (the part after v= or youtu.be/). -->
Why This Exists
AI assistants today can suggest kubectl commands. But actually operating a cluster still means switching contexts, copy-pasting commands, manually debugging failures, and repeatedly checking logs and events. That creates a slow human-in-the-loop cycle.
k8s-mcp closes this gap by giving AI agents task-complete tools instead of low-level primitives. Instead of chaining:
kubectl get pod
kubectl describe pod
kubectl logs
agents can call tools like diagnose_pod() or wait_for_ready() — and get structured results in one shot.
What makes it different
k8s-mcp is designed around workflows, not raw resource access — optimized for:
- AI agent execution loops — deploy, observe, diagnose, retry, validate
- Lower token usage — structured outputs instead of long shell transcripts
- Beginner-friendly operations — less manual command chaining
- Faster iteration — fewer moving pieces between "please deploy this" and a working result
Key capabilities
- Faster and lighter than shell tools — native MCP tools return structured data directly to the AI, avoiding shell spawning, CLI output parsing, and large text streaming
- Diagnose issues in one shot —
diagnose_podcombines status, conditions, events, and failing-container logs into a single report - Autonomous deploy loops — apply manifests, wait for readiness, detect failures, and iterate without manual back-and-forth
- Generate deployment manifests — create a working Kubernetes starting point automatically instead of writing YAML from scratch
- Query and take action — list pods, read logs, inspect configs, scale deployments, restart workloads, apply manifests, and delete resources from the conversation
- Detect config drift — export live resources as YAML and compare against local manifests
- Secure by Design — reuses your
~/.kube/configand your organization's existing auth flow (SSO, OIDC, certificate). Never stores or manages credentials - Work with any MCP client — supports stdio, HTTP, and SSE transports
How it compares
Some Kubernetes MCP servers focus on broad resource-level API access. k8s-mcp focuses on workflow-level tools designed for AI agents.
| k8s-mcp | Traditional MCP servers | |
|---|---|---|
| Focus | Workflow-level tools | Raw resource APIs |
| Usability | Beginner-friendly | Kubernetes expertise required |
| Outputs | Summarized, structured | Raw API responses |
| Agent efficiency | High — fewer calls, lower token usage | Requires more reasoning and chaining |
Who Is This For
- AI engineers building agent workflows that interact with Kubernetes
- Researchers deploying models on Kubernetes without deep k8s expertise
- Developers who want to automate cluster operations from their IDE
- Teams experimenting with AI-driven DevOps
If you want broad, low-level Kubernetes API access, there are other MCP servers better suited for that. If you want an agent that can actually operate a cluster with less manual overhead, this project is for you.
Quick Start
1. Install
git clone git@github.com:jingyanjiang/k8s-mcp.git
cd k8s-mcp
pipx install .
This puts k8s-mcp on your PATH and works from any directory.
You can also use uv tool install . or pip install .. For development, use poetry install.
2. Verify your Kubernetes access
k8s-mcp reads your existing ~/.kube/config. Before using it, verify:
kubectl auth whoami
kubectl get all -n <your-namespace>
The server inherits whatever permissions your kubeconfig user has. No additional credentials are needed.
Note: Some operations (e.g.,
list_namespaces,list_nodes) require cluster-wide permissions. If a request fails with403 Forbidden, ask your cluster admin for the necessary RBAC roles.
3. Add to your MCP client
Claude Code / Claude Desktop
Add to .mcp.json (project-level) or ~/.claude.json (global):
{
"mcpServers": {
"k8s": {
"type": "stdio",
"command": "k8s-mcp",
"args": ["--transport", "stdio"]
}
}
}
OpenAI Codex CLI
Add to ~/.codex/config.toml (user-level) or .codex/config.toml (project-level):
[mcp_servers.k8s]
command = "k8s-mcp"
args = ["--transport", "stdio"]
Gemini CLI
Add to ~/.gemini/settings.json (user-level) or .gemini/settings.json (project-level):
{
"mcpServers": {
"k8s": {
"command": "k8s-mcp",
"args": ["--transport", "stdio"]
}
}
}
Opencode
Add to opencode.json in your project root:
{
"mcp": {
"k8s": {
"type": "local",
"command": ["k8s-mcp", "--transport", "stdio"]
}
}
}
If your MCP client can't find
k8s-mcpon PATH, use the absolute path instead (runwhich k8s-mcpto find it).
The server starts automatically when your MCP client connects — no manual commands needed.
<details> <summary><strong>Using Poetry instead of a global install?</strong></summary>
Replace "command": "k8s-mcp" with "command": "poetry" and set args to ["run", "k8s-mcp", "--transport", "stdio"]. You must also add "cwd": "/absolute/path/to/k8s-mcp" so Poetry can find the project.
</details>
<details> <summary><strong>Other transport modes</strong></summary>
The server supports three transport modes:
# stdio (for local MCP clients like Claude Code)
k8s-mcp --transport stdio
# Streamable HTTP (for remote/networked clients)
k8s-mcp --transport streamable-http
# SSE (Server-Sent Events)
k8s-mcp --transport sse
For HTTP transports, configure bind address and port via environment variables:
export K8S_MCP_HOST=0.0.0.0 # default: localhost
export K8S_MCP_PORT=8000 # default: 8000
</details>
4. (Optional) Install the k8s-ops skill for Claude Code
For Claude Code users, this repo ships an opinionated workflow skill at skills/k8s-ops/. It encodes multi-step playbooks for deploy, debug, rollout, and audit on top of the raw MCP tools — useful when you want the agent to follow a tested sequence (e.g., debug decision tree, pre-flight rollout checks) rather than improvise.
Install with a symlink so updates from git pull flow through automatically:
ln -s "$(pwd)/skills/k8s-ops" ~/.claude/skills/k8s-ops
Then in Claude Code, invoke it with /k8s-ops (e.g., /k8s-ops debug, /k8s-ops audit NAMESPACE=foo). The skill is also model-invoked — it activates automatically when you ask the agent to deploy, diagnose, restart, or audit Kubernetes workloads.
Skip this step if you're using a different MCP client. The MCP server itself works without it.
5. Try it out
Please check the status of my namespace: <namespace>
Please deploy the app in this repo to my k8s cluster. Make a plan first, then implement it.
My pods in namespace X keep crashing. Can you figure out what's wrong?
Sample Use Cases
Check cluster status
"Please check the status of my namespace: xxxxx"
The assistant will list pods, deployments, services, and events in the namespace, surfacing any issues it finds.

Deploy an application
"Please deploy the app/server in this repo to a k8s cluster for me. Make a plan first, then implement it."
The agent will:
- Analyze the repo structure
- Confirm the target cluster, namespace, image registry, and tag
- Generate Kustomize manifests
- Apply the deployment
- Wait for readiness and return structured health results
Diagnose a failing workload
"My pods in namespace X keep crashing. Can you figure out what's wrong?"
The agent will inspect pod status, conditions, events, and container logs — then return a structured explanation with suggested fixes. No more manually running describe and logs in a loop.
Tools
Signature tools
These best represent the project's workflow-oriented design:
| Tool | Description |
|---|---|
diagnose_pod |
One-shot diagnostics — combines status, conditions, events, and failing-container logs |
wait_for_ready |
Poll a pod or deployment until ready or timeout (enables autonomous deploy loops) |
apply_manifest |
Apply YAML manifests (create or update, supports multi-document) |
apply_kustomize |
Render and apply a Kustomize directory (equivalent to kubectl apply -k) |
get_resource_yaml |
Export a live resource as clean YAML (for config drift detection) |
generate_deploy_manifests |
Generate Kubernetes manifests for deploying k8s-mcp itself to a cluster |
<details> <summary><strong>Full tool reference</strong></summary>
All operations are exposed as MCP tools — you interact with them conversationally through your AI assistant.
Cluster Context
| Tool | Description |
|---|---|
get_contexts |
List available kubeconfig contexts |
get_current_context |
Show the active context, cluster, and user |
Namespaces
| Tool | Description |
|---|---|
list_namespaces |
List all namespaces in the cluster |
Pods
| Tool | Description |
|---|---|
list_pods |
List pods (by namespace, label, or all namespaces) |
get_pod |
Get detailed pod information |
get_pod_logs |
Fetch container logs (with tail, previous container support) |
delete_pod |
Delete a pod (with configurable grace period) |
diagnose_pod |
One-shot diagnostics — combines status, conditions, events, and logs from failing containers |
exec_command |
Execute a command inside a running container (e.g., curl, env, nslookup) |
Deployments
| Tool | Description |
|---|---|
list_deployments |
List deployments (by namespace, label, or all namespaces) |
get_deployment |
Get detailed deployment information |
scale_deployment |
Scale a deployment to N replicas |
restart_deployment |
Rolling restart (equivalent to kubectl rollout restart) |
get_rollout_status |
Check if a rollout is complete, in progress, or stuck |
Services
| Tool | Description |
|---|---|
list_services |
List services (by namespace, label, or all namespaces) |
get_service |
Get detailed service information |
ConfigMaps
| Tool | Description |
|---|---|
list_configmaps |
List ConfigMaps (by namespace, label, or all namespaces) |
get_configmap |
Get a ConfigMap's metadata and data contents |
Secrets
| Tool | Description |
|---|---|
list_secrets |
List Secrets with type and key counts |
get_secret |
Get Secret metadata and key names; optionally decode values with masking |
ServiceAccounts
| Tool | Description |
|---|---|
list_service_accounts |
List ServiceAccounts (by namespace, label, or all namespaces) |
get_service_account |
Get ServiceAccount details including secrets and automount config |
RBAC (Roles & Bindings)
| Tool | Description |
|---|---|
list_roles |
List Roles (by namespace or all); optionally include ClusterRoles |
get_role |
Get Role or ClusterRole details including permission rules |
list_role_bindings |
List RoleBindings (by namespace or all); optionally include ClusterRoleBindings |
get_role_binding |
Get RoleBinding or ClusterRoleBinding details including subjects and role reference |
Nodes
| Tool | Description |
|---|---|
list_nodes |
List cluster nodes with status and roles |
get_node |
Get detailed node information |
Events
| Tool | Description |
|---|---|
list_events |
List events, optionally filtered by resource name |
Jobs
| Tool | Description |
|---|---|
list_jobs |
List jobs with completion status and duration |
Ingresses
| Tool | Description |
|---|---|
list_ingresses |
List Ingresses with hosts, class, and TLS info |
get_ingress |
Get detailed Ingress information including routing rules |
Generic Operations
| Tool | Description |
|---|---|
apply_manifest |
Apply YAML manifests (create or update, supports multi-document) |
apply_kustomize |
Render and apply a Kustomize directory (equivalent to kubectl apply -k) |
delete_resource |
Delete any resource by type and name (supports abbreviations like po, svc, deploy) |
describe_resource |
Describe any resource — combines spec/status with related events (like kubectl describe) |
get_resource_yaml |
Export a live resource as clean YAML (for config drift detection) |
Resource Metrics
| Tool | Description |
|---|---|
top_pods |
Show CPU/memory usage per pod (requires metrics-server) |
top_nodes |
Show CPU/memory usage per node with capacity percentages |
Readiness
| Tool | Description |
|---|---|
wait_for_ready |
Poll a pod or deployment until ready or timeout (enables autonomous deploy loops) |
Deployment Generation
| Tool | Description |
|---|---|
generate_deploy_manifests |
Generate Kubernetes manifests for deploying k8s-mcp itself to a cluster |
</details>
Safety
k8s-mcp is designed with practical safeguards:
- Namespace scoping — agents confirm the target namespace before taking action
- Destructive action confirmation — delete, scale-to-zero, and restart operations require explicit user approval
- Read-only queries by default — most tools are non-destructive
Always review actions before applying changes in production environments.
Project Status
This project is actively maintained and evolving. Feedback, suggestions, and contributions are welcome.
Contributing
Pull requests and ideas are welcome. If you're experimenting with AI-driven DevOps, I'd love to hear what workflows would be useful.
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。
