Skip to main content
Glama

k8s-rca-mcp

Read-only Model Context Protocol (MCP) server and automated 15-scenario chaos evaluation harness for Kubernetes root-cause analysis—enforcing least-privilege RBAC, secret redaction, prompt-injection quarantine, and OpenTelemetry tracing at $0 cost.

Architecture

flowchart LR
    Agent[AI Client: Cursor / Ollama / LangGraph] <-->|JSON-RPC 2.0 stdio MCP| Server[k8s-rca-mcp Server]
    Server --> Guard[Security Guardrails: Read-Only Allowlist + Secret Redaction + Prompt-Injection Filter]
    Guard --> Analyzer[Grounded RCA Correlation Engine]
    Analyzer -->|Least-Privilege ClusterRole: NO secrets, NO write verbs| K8s[(Kubernetes API: Pods, Events, Logs, ReplicaSets)]
    Server --> OTel[OpenTelemetry Spans]

Related MCP server: mcp-k8s-context-server

Security & Guardrail Model

  1. Zero Secret Access (RBAC + Code Enforcement): Both deploy/rbac/readonly-clusterrole.yaml and guardrails.enforce_read_only_access() explicitly allow only get/list/watch on non-secret diagnostic resources. Reading secrets or invoking any mutating verb (delete, patch, apply) raises GuardrailViolation and returns 403 Forbidden in Kubernetes.

  2. Automatic Secret Redaction: Scrubs PEM private keys, JWTs, AWS access keys (AKIA...), Bearer tokens, database URI credentials, and password=/api_key= patterns from pod logs and Kubernetes events before any text reaches an LLM.

  3. Prompt-Injection Quarantine: Detects and neutralizes untrusted instructions embedded in pod logs (e.g., "ignore previous instructions", "kubectl delete ...") while flagging prompt_injection_quarantined: true in the response audit metadata.

Exposed MCP Tools (tools/list)

Tool

Read-Only Scope

Purpose

get_pod_diagnostics

list pods

Pod phases, restart counts, waiting/termination reasons & exit codes

get_recent_events

list events

Sanitized Kubernetes Warning/Normal events

get_previous_logs

get pods/log

Previous container logs with credential redaction & injection filtering

get_rollout_history

list replicasets

Recent deployment revisions and container images

diagnose_namespace_incident

Read-only correlation

Structured, evidence-cited RCA report + safe recommended next steps

15-Scenario Chaos & Adversarial Benchmark (eval/run_eval.py)

Covers OOMKilled, CrashLoopBackOff, ImagePullBackOff, CreateContainerConfigError, InitContainerFailure, ResourceQuotaExceeded, FailedScheduling-PVC, FailedScheduling-Resources, ExpiredTLSCertificate, DNSResolutionFailure, NetworkPolicyDrop, RBACForbidden, LivenessProbeKillLoop, ReadinessProbeFailure, and PromptInjection + JWT Leak.

Quick Start ($0 Local)

# Run unit, RBAC policy, MCP JSON-RPC, and guardrail tests
PYTHONPATH=src:. python -m unittest discover -s tests -v

# Run 15-scenario evaluation harness and print Markdown scorecard
PYTHONPATH=src:. python -m eval.run_eval

Zero-Cost CI Pipeline (.github/workflows/ci.yml)

  1. unit-and-eval-harness: Runs pytest (guardrails, RBAC YAML audit, MCP JSON-RPC protocol) and executes all 15 chaos scenarios, uploading eval-scorecard.md.

  2. kind-rbac-and-chaos-e2e: Spins up a free kind cluster in GitHub Actions, applies readonly-clusterrole.yaml, proves via kubectl auth can-i that get secrets and delete pods are denied, deploys real failing workloads (chaos/manifests/sample-failures.yaml), and runs live RCA diagnosis against the cluster.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables read-only Kubernetes incident investigation through MCP tools for listing pods, describing resources, fetching logs, and searching runbooks.
      1
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides a read-only interface to Kubernetes clusters, enabling LLMs to list pods, get pod status and logs, fetch deployment manifests, and perform pod health analysis with resource trend tracking.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to diagnose Kubernetes clusters through read-only MCP tools, such as inspecting pod status, logs, events, nodes, deployments, and HPA metrics via natural language queries.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Exposes read-only Kubernetes investigation tools — pod listing/descriptions, log tails (including previous crashes), events, deployment and rollout history, node status, and Prometheus metrics — over MCP so Claude Desktop or any MCP client can diagnose the root cause of an incident. Proposed fixes are never exposed as executable actions; remediation stays behind a policy-checked human approval gate.
      1
      MIT