trackmcp
Back to directory
mirusser

Kubernetes-MCP-Guard

View on GitHub

Guarded Kubernetes MCP gateway where AI agents observe, plan, and propose remediation that execute only after human approval and digest-bound verification.

1 stars C#Others Updated Sep 3, 2026
ai-agentsai-safetydevopsdotnetkubernetesmcpmodel-context-protocoloauth2rbac

Documentation

πŸ›‘οΈ Kubernetes MCP Guard

Human-approved, AI-driven Kubernetes remediation through a guarded MCP gateway.

> Remediation, by design:

>

> Observer detects anomalies.

> Planner proposes an evidence-backed plan.

> Human reviewer approves out-of-band.

> Executor runs only the approved digest-bound plan.

> Everything is auditable.

Unit Tests
Integration Tests
Docker
Quality Gate Status
Coverage

![Badge Hi Mom]

.NET 10
Kubernetes
Docker
MCP
AI Agents

πŸ“ TL;DR

When something breaks, the system can collect evidence, propose a bounded fix, dry-run it, package it into a reviewable plan, and wait for a human to approve.

It is a security-first bridge between AI agents and Kubernetes, with out-of-band, OAuth-authenticated, human-in-the-loop (HITL), plan-based approval for every gateway-exposed mutation.

Why?

AI agents can help diagnose infrastructure problems, but giving them direct mutation access is risky. Kubernetes MCP Guard explores a safer pattern: agents may observe, dry-run, and propose bounded remediations, while humans approve the exact digest-bound plan before any Kubernetes write occurs.

🎬 Demo

https://github.com/user-attachments/assets/4e06b4ee-db80-4d74-96cc-38dfbb413042

> [!NOTE]

> Demo scenario:

>

> 1. A Deployment is intentionally broken.

> 2. The Observer detects the unhealthy workload.

> 3. The Planner proposes a bounded remediation.

> 4. An approval access code is sent to the configured operator by email.

> 5. An authenticated human approves the exact plan in the browser.

> 6. The Executor applies the approved mutation.

>

The walkthrough in docs/demo-failing-deployment.md shows the full flow against a deliberately broken Deployment.

🧠 Core Ideas

Kubernetes MCP Guard explores a practical safety pattern for AI-assisted operations:

  • Plan before mutate: every gateway-exposed write starts as a `request_*` plan built from Kubernetes server-side dry-run evidence.
  • Separate review channel: the MCP client receives an approval URL, while approval happens through `/approvals/*` in a browser OAuth session.
  • Digest-bound approval: execution is bound to an Intent Digest for the executable mutation and a Review Digest for the human-reviewed snapshot.
  • Durable grant model: an approved Approval Challenge records a Challenge Outcome and issues an Approval Grant consumed by pre-execution gates.
  • Narrow Kubernetes scope: namespace allow-lists, namespace-scoped RBAC, supported-kind checks, and bounded read tools keep the operational surface small.
  • Auditable controls: guardrail and approval events are written as JSONL streams with identity, digest, grant, and execution context.
  • Structured multi-agent coordination: Observer, Planner, and Executor are independent processes (agents) that communicate over the A2A protocol (via `a2a-dotnet`), each with a separate OAuth service identity and a narrow gateway scope. The Planner owns a durable per-anomaly Task that persists across restarts and enforces one-remediation-per-anomaly without cross-service locking.

The repository also separates the generic approval lifecycle from the Kubernetes adapter, so the core language is not tied to one infrastructure domain.

See CONTEXT.md, docs/mutation-approval-profile.md, docs/mutation-approval-flow.md.

πŸ—ΊοΈ Architecture

mermaid
---
title: Security Boundaries
---
flowchart TB
    subgraph outer["🌐 Internet / Operator"]
        Human["πŸ‘€ Operator\nbrowser Β· OAuth PKCE"]
        McpClient["πŸ€– MCP Client\nCodex Β· Claude Code"]
    end

    subgraph gateway["πŸ›‘οΈ Gateway β€”  OAuth JWT required"]
        direction LR
        Guard["πŸ” Guardrails\n+ ToolScopeGuard"]
        ApprovalUI["πŸ“‹ Approval UI\n/approvals/*"]
        ApprovalCore["πŸ” Approval Core\nplan Β· challenge Β· grant Β· digest"]
    end

    subgraph agents["πŸ€– Agent Tier  β€”  client_credentials Β· narrow scopes"]
        direction LR
        Obs["πŸ”Ž Observer\nmcp:tools.readonly"]
        Plan["πŸ“‹ Planner\nmcp:tools.propose + readonly"]
        Exec["πŸ› οΈ Executor\nmcp:tools.execute"]
        Obs |"A2A"| Plan |"A2A"| Exec
    end

    subgraph private["πŸ”’ Private Subprocess  β€”  no public port"]
        McpServer["βš™οΈ McpServer\nKubernetes tools"]
    end

    K8s(("☸️ Kubernetes API\n(namespace-scoped RBAC)"))

    Human -->|"review snapshot Β· approve/deny"| ApprovalUI --> ApprovalCore
    McpClient -->|"Bearer JWT Β· mcp:tools.read/write"| Guard -->|"scope-filtered tool call"| ApprovalCore
    agents -->|"Bearer JWT Β· service identity"| Guard
    ApprovalCore -->|"stdio Β· service token"| McpServer -->|"KubernetesClient"| K8s

The Observer notifies the Planner and the Planner dispatches to the Executor synchronously and waits for the outcome.

The Planner's internal remediation pipeline is a concurrent DAG built on `Microsoft.Agents.AI.Workflows`, fanning each incoming anomaly through independent:

`Filter β†’ Dedupe β†’ LLM-Decide β†’ Validate β†’ Propose executor chains`.

Full request-flow diagrams live in docs/architecture.md.

πŸ” Approval Flow

The central safety property is that approval is necessary but not sufficient. A human approval creates execution authorization, but execution still has to pass the pre-execution gates immediately before Kubernetes is mutated.

PhaseWhat happensWhat can block it
PlanA human-driven MCP client calls `request_*`, or the Planner calls `propose_plan`; the Kubernetes adapter gathers dry-run, diff, and policy evidence; the generic core stores a Plan Envelope with Intent and Review Digests.Namespace rejection, manifest allow-list rejection, dry-run failure, domain policy denial, unsupported legacy plan format.
ApproveThe client calls `execute_approved_plan`; the gateway creates or reuses a short-lived Approval Challenge and returns a browser URL. The browser renders the stored review snapshot, not model-supplied approval text.Expired challenge, wrong authenticated subject, anti-forgery failure, changed digest binding, denied/rejected/canceled Challenge Outcome.
ExecuteAfter approval, the client retries `execute_approved_plan`; the gateway validates the Approval Grant, digests, validity window, reuse policy, freshness checks, and domain policy checks before the adapter writes.Missing/expired/mismatched grant, digest mismatch, already-applied Single-Execution Plan, second dry-run failure, policy failure, live-state drift.

Current implementation notes are tracked in docs/mutation-approval-profile.md#current-repository-fit.

🧰 Current Capabilities

πŸ€–πŸ”Ž Anomaly Observer

The InfraGate.Observer is an LLM-driven agent that periodically inspects the cluster through the gateway's read-only tools and emits structured Anomaly Reports.

CapabilityDescription
Scheduled observationBackground `IHostedService` runs cycles on a configurable cadence (default 60s).
On-demand trigger`POST /observe-now` returns a synchronous `AnomalyReport[]` with a 30s timeout.
Anomaly detectionLLM-assisted classification across four categories: Pod unhealthy, Deployment unavailable, Service no endpoints, Warning events.
Severity classificationRules-derived `High`/`Medium`/`Low` with LLM disagreement telemetry.
Deduplication & resolutionIn-memory dedupe window suppresses repeat reports; automatic `Resolved` emission when anomalies clear.
HandoffLog sink always on; JSON file sink and Planner A2A handoff are opt-in; see docs/configuration.md.

πŸ€–πŸ“‹ Remediation Planner

The InfraGate.Planner consumes Anomaly Reports, chooses a bounded remediation operation, and creates approval-pending Operator Approval Policy plans through `propose_plan`.

CapabilityDescription
Anomaly intakeReceives `AnomalyHandoffBatch` payloads from the Observer over A2A; each anomaly is processed independently through a concurrent DAG pipeline: Filter β†’ Dedupe β†’ LLM-Decide β†’ Validate β†’ Propose.
Operation menuChooses only `restart_deployment`, `scale_deployment`, or `set_deployment_image` in v1.
Plan proposalCalls `propose_plan` to create a digest-bound Plan Envelope for operator approval.
Approval notification`propose_plan` creates an Approval Access Code and sends the configured operator email through the gateway SMTP sender when configured.
Durable task lifecycleOne A2A Task per anomaly (keyed by `contextId`) tracks state from `Submitted` through `Working`, `AuthRequired` (awaiting operator approval), to `Completed`/`Failed`/`Rejected`. Persisted to PostgreSQL when `InfraGate__Planner__AuditConnectionString` is set; otherwise in-memory.
Scope boundaryPlanner can propose plans and use read-only inspection tools; it cannot execute plans.

πŸ€–πŸ› οΈ Remediation Executor

The InfraGate.Executor consumes Planner proposals, waits for approval, and executes only after the gateway reports that an Approval Grant exists.

CapabilityDescription
Proposal intakeReceives plan ids from the Planner over synchronous A2A dispatch.
Approval waitCalls `wait_for_plan_approval` for each plan id until approval, timeout, or terminal status.
Approved executionCalls `execute_approved_plan` only after approval is reported.
Scope boundaryExecutor can wait and execute approved plans; it cannot create plans or call read-only inspection tools.
Gateway gatesThe gateway still enforces approval grants, digests, freshness, policy checks, and single execution.

πŸ›‘οΈ Gateway Protections

LayerCurrent behavior
MCP transportHTTP MCP endpoint at `/mcp` using Streamable HTTP.
AuthenticationOAuth JWT validation for MCP calls; browser OAuth cookie for approval pages.
OAuth discoveryProtected-resource metadata and insufficient-scope challenges for MCP clients.
Approval authorityBrowser approval endpoints under `/approvals/*` with same-subject binding and anti-forgery checks.
GuardrailsWarn on suspicious request patterns and redact suspicious response content before it returns to the MCP client.
AuditSeparate JSONL streams for guardrail findings and approval lifecycle events.

πŸ”Ž Read-Only Observability

ToolPurpose
`get_allowed_namespaces`Return the namespace allow-list configured for the server.
`get_k8s_status`Summarize Deployments, Services, ConfigMaps, Pods, and ReplicaSets in a namespace.
`get_k8s_events`Read bounded `events.k8s.io/v1` diagnostics.
`get_pod_logs`Read bounded Pod logs with tail-line and byte caps.
`get_k8s_resource`Return a focused resource summary without Secret values, ConfigMap data, or raw manifests.
`get_deployment_diagnostics`Inspect Deployment health, related Pods, ReplicaSets, and Events.
`get_pod_diagnostics`Inspect Pod status, conditions, container state, and Events.
`get_service_diagnostics`Inspect Service endpoints, backing Pods, and Events.

βœ… Gateway Approval Tools

ToolPurpose
`request_apply_manifest`Dry-run and plan server-side apply for `Deployment`, `Service`, or `ConfigMap`.
`request_delete_manifest`Dry-run and plan deletion for supported manifest kinds.
`request_scale_deployment`Dry-run and plan a Deployment replica-count change.
`request_restart_deployment`Dry-run and plan a Deployment rollout restart.
`request_set_deployment_image`Dry-run and plan a Deployment container image update.
`propose_plan`Create an approval-pending Operator Approval Policy plan for the autonomous Planner operation menu.
`execute_approved_plan`Create the browser approval challenge or execute an approved, digest-bound plan after gates pass.
`get_plan_status`Read the current approval status for a plan.
`wait_for_plan_approval`Wait briefly for an out-of-band browser approval and return status JSON without applying the plan.

Direct Kubernetes mutation tools exist inside the private server surface for the adapter executor. The HTTP gateway exposes `request_*` wrappers plus `execute_approved_plan` instead of exposing raw destructive tools to MCP clients.

⚑ Quick Start

Prerequisites: Docker Compose v2, kubectl, minikube, and git.

Review docs/configuration.md before changing runtime settings.

πŸ“¦ From Packages

The default quickstart uses published images and committed local-demo defaults.

bash
git clone https://github.com/mirusser/Kubernetes-MCP-Guard.git
cd Kubernetes-MCP-Guard

export InfraGate__OpenRouter__ApiKey=""
make quickstart

`make quickstart` starts the local Keycloak-backed OAuth path, PostgreSQL approval store, and published gateway image with `TAG=latest`. Pin a release with `TAG=v0.1.0 make quickstart`. The committed no-SDK defaults come from the `smoke-release` Run Profile: `deploy/local-oauth/release.env.example` supplies both Compose interpolation and `InfraGate__...` runtime settings.

πŸ› οΈ From Source

Use source mode when you want the gateway, Observer, Planner, and Executor built from local code. This path requires the .NET 10 SDK and an OpenRouter API key for the LLM-backed agents. The Docker build fetches the optional secondary, read-only `kubernetes-mcp-server` downstream from its official release, checksum-verified against `scripts/kubernetes-mcp-server.manifest.json`; run `./scripts/install-kubernetes-mcp-server.sh` (needs `curl`, `sha256sum`, `jq`) on the host only when running that downstream or its live integration test directly.

bash
export InfraGate__OpenRouter__ApiKey=""
make quickstart-source

The source quickstart generates `deploy/generated/local-compose.env` (default configuration) from `deploy/run-profiles.yaml` and starts the gateway, Observer, Planner, and Executor from local source builds.

Useful follow-up commands:

bash
make quickstart-logs
make quickstart-down

Other run modes and full setup details are in docs/setup-guide.md.

⌨️ Connect Codex CLI

Add this to `~/.codex/config.toml`:

toml
[mcp_servers.infra-gate]
url = "http://127.0.0.1:3001/mcp"
oauth_resource = "http://127.0.0.1:3001/mcp"
scopes = ["mcp:tools.read"]

Use `mcp:tools.write` for sessions where you intend to create and apply mutation plans. The legacy `mcp:tools` scope grants full access for backward compatibility.

Then authenticate and start Codex:

bash
codex mcp login infra-gate
codex

πŸ’¬ Connect Claude Code

bash
claude mcp add-json --scope user infra-gate \
  '{"type":"http","url":"http://127.0.0.1:3001/mcp","oauth":{"scopes":"mcp:tools.read"}}'

claude
/mcp

πŸ“¦ Container Images

Release images are built by the Docker workflow and published to GHCR and Docker Hub.

RegistryGateway image
GitHub Container Registry`ghcr.io/mirusser/kubernetes-mcp-guard-gateway:`
Docker Hub`mirusser/kubernetes-mcp-guard-gateway:`

Use specific release tags for stable demos. The `:dev` tag tracks the development branch, and `:latest` tracks the most recent stable release.

🧩 Compatibility

AreaSupported / tested
.NET.NET 10
Kubernetesminikube / local cluster initially
MCP transportHTTP MCP endpoint at `/mcp`
OIDCKeycloak local/dev path; external OIDC providers by configuration
Container registriesGHCR, Docker Hub
Platformslinux/amd64 initially

🧭 Project Map

βš–οΈ Boundaries And Non-Goals

> [!IMPORTANT]

> - The project is experimental and not production-certified.

> - The local Keycloak realm runs in development mode over HTTP and is not a production identity provider.

> - Prompt-injection guardrails are defense-in-depth, not a guaranteed hard security boundary.

> - The tool surface does not expose shell execution, `kubectl` passthrough, exec, attach, port-forward, namespace creation, RBAC manipulation, Secret reads, raw manifest reads, or cluster-scoped writes.

> - This is not a full Kubernetes policy engine and not an MCP standard.

See docs/security-model.md for the full threat model.

It is a working reference implementation for a possible MCP mutation-approval profile, designed for early technical evaluation in local or tightly controlled environments, not production-certified infrastructure.

The codebase uses InfraGate as the internal project name.

πŸ“œ Governance


Built with ❀️, β˜• and careful little guardrails πŸ›‘οΈβœ¨

[Badge Hi Mom]: https://img.shields.io/badge/Hi-mom!-ff69b4

Frequently asked questions

What is Kubernetes-MCP-Guard?

Kubernetes-MCP-Guard is Guarded Kubernetes MCP gateway where AI agents observe, plan, and propose remediation that execute only after human approval and digest-bound verification.

How do I install Kubernetes-MCP-Guard?

Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

Is Kubernetes-MCP-Guard open source?

Yes β€” it is hosted on GitHub at https://github.com/mirusser/Kubernetes-MCP-Guard and has 1 stars.

Related MCP tools

IBMmcp-context-forge

An AI Gateway, registry, and proxy that sits in front of any MCP, A2A, or REST/gRPC APIs, exposing a unified endpoint with centralized discovery, guardrails and management. Optimizes Agent & Tool calling, and supports plugins.

4,422 Python
agentsaiapi-gateway+17
skyhook-ioradar

The missing open-source Kubernetes UI with a built-in MCP server for AI agents. See what's broken, why, and what changed. Issues, Topology, event timeline, Helm, GitOps, live service traffic, and cluster audits - all in one Go binary.

3,246 Go
argocdcloud-nativegitops+17
CoplayDevunity-mcp

Unity MCP acts as a bridge between AI assistants and your Unity Editor. Give your LLM tools to manage assets, control scenes, edit scripts, and automate tasks within Unity.

13,915 C#
aiai-integrationmcp+13
IvanMurzakUnity-MCP

AI Skills, MCP Tools, and CLI for Unity Engine. Full AI develop and test loop. Use cli for quick setup. Efficient token usage, advanced tools. Any C# method may be turned into a tool by a single line. Works with Claude Code, Gemini, Copilot, Cursor and any other absolutely for free.

4,137 C#
aiai-integrationgame-development+16
kubesharkkubeshark

eBPF-powered network observability for Kubernetes. Indexes L4/L7 traffic with full K8s context, decrypts TLS without keys. Queryable by AI agents via MCP and humans via dashboard.

12,068 Go
kubernetesgolangrest+17
superglue-aisuperglue

superglue (YC W25) builds integrations and tools from natural language. Get production-grade tools for long tail and enterprise systems.

2,056 TypeScript
apiapi-gatewayetl-automation+15

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP