k8s-ops-mcp-agent
An AI SRE copilot for Kubernetes that lets LLM agents inspect cluster health and, with explicit human confirmation, restart or scale deployments.
README
k8s-ops-mcp-agent
An AI SRE copilot for Kubernetes, built on the Model Context Protocol (MCP). It lets an LLM (Claude, or any MCP-compatible agent) inspect the health of a cluster and — only with explicit human confirmation — restart or scale deployments.
Built to explore how LLM agents can be given real operational tools without becoming a liability: read access is open, write access is gated.
Why this exists
Incident response burns a lot of engineer time on repetitive diagnosis: "which pods are crash-looping, what do the logs say, what changed recently." This project gives an LLM agent the tools to answer that in seconds, while keeping a human explicitly in the loop for anything destructive.
Architecture
┌─────────────────┐ MCP (stdio) ┌──────────────────────┐ Kubernetes API
│ Claude Desktop │ ───────────────────────▶ │ k8s-ops-mcp-agent │ ───────────────────────▶ Cluster
│ (or any MCP │ ◀─────────────────────── │ (this repo) │ ◀─────────────────────── (kind / EKS / etc.)
│ client) │ tool calls/results └──────────────────────┘
└─────────────────┘
The agent process talks to the cluster using the official Kubernetes Python
client and a standard kubeconfig — the same credentials you'd use with
kubectl. It never embeds cluster credentials in the LLM prompt.
Tools exposed
| Tool | Type | Description |
|---|---|---|
list_pods |
read | Pod status, restart counts, age for a namespace |
get_pod_logs |
read | Tail logs for a specific pod |
get_events |
read | Recent Kubernetes events (crash loops, image pull errors, scheduling failures) |
get_deployment_status |
read | Desired vs ready vs available replicas |
restart_deployment |
write | Rolling restart — requires confirm=True |
scale_deployment |
write | Scale replicas (0-50 range enforced) — requires confirm=True |
Safety design
This is the part I care most about — an agent with unrestricted write access to production infrastructure is a bad idea. So:
- Read tools require no confirmation — an agent should be free to look around and diagnose.
- Write tools refuse to execute unless called with
confirm=True. The intended flow is: agent proposes an action → human says "do it" → agent calls the tool again with confirmation. This is enforced in code, not just in the prompt, so it can't be bypassed by prompt injection from logs or pod output the agent reads. - Replica counts are hard-capped (0-50) regardless of confirmation, as a last line of defense against a runaway agent loop.
- Every tool call is logged with timestamp and arguments for auditability.
- Actions are always scoped to a single namespace passed explicitly by the caller — there is no cluster-wide destructive tool.
See server/k8s_ops_server.py and the tests in
tests/test_guardrails.py, which specifically
verify the refusal logic (six passing tests covering confirm/no-confirm and
out-of-range scaling).
Setup
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# Point at a real or local cluster (e.g. kind/minikube)
kind create cluster --name ops-demo
# Run the server directly (for local testing via MCP inspector)
python server/k8s_ops_server.py
To use it from Claude Desktop, add an entry to your MCP config — see
docs/claude_desktop_config.example.json.
Running the tests
python -m unittest tests/test_guardrails.py -v
No cluster required — the Kubernetes client is mocked so the guardrail logic can be verified in isolation (and in CI).
Example session
> "What's going on with checkout-api in staging?"
[agent calls get_deployment_status, get_pod_logs, get_events]
The checkout-api deployment has 1/3 pods ready. One pod is in
CrashLoopBackOff — the logs show a database connection timeout at startup.
Events confirm 4 restarts in the last 10 minutes. This looks like the DB
hasn't finished migrating. Want me to restart the deployment once the
migration job completes, or scale down to reduce restart pressure?
> "Yes, restart it."
[agent calls restart_deployment(confirm=True)]
Restart triggered for checkout-api in staging at 2026-07-20T14:32:01Z.

Roadmap / possible extensions
- Slack integration so the confirmation step happens in a thread
- Read-only cost/right-sizing recommendations tool (via AWS Compute Optimizer)
- Multi-cluster support with per-cluster kubeconfig context switching
Stack
Python · Kubernetes Python client · Model Context Protocol (MCP) · unittest
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。