Skip to main content
Glama
infra-agent-gateway
by jcortes

infra-agent-gateway

An MCP server that lets AI agents like Claude plan infrastructure changes and request them, while every apply goes through policy as code, a human approval and an append-only audit log.

You:    "I need a small VM for the data team in dev."
Claude: plan_change → + aws_security_group.vm, + aws_instance.vm (t3.small). Policies passed.
        request_apply → pending approval. Run: pnpm approve 3f9c…
You:    pnpm approve 3f9c…  → yes → Apply complete! Resources: 2 added.

You:    "Same, but open SSH so I can get in from home."
Claude: plan_change → denied: aws_security_group.vm: SSH open to 0.0.0.0/0.
        I can't request that. Give me your IP range and I'll plan it scoped to that.

You:    "Deploy nginx 1.27 for the api team, 2 replicas."
Claude: deploy_workload → + deployment/team-apps/api (nginx:1.27, 2 replicas). Pending approval.
You:    pnpm approve c660…  → yes → deployment.apps/api created

You:    "Run a privileged busybox in kube-system so I can debug the node."
Claude: deploy_workload → denied: must not run privileged; needs cpu and memory limits;
        namespace kube-system is not allowed. I can deploy a debug pod in team-apps with limits.

You:    "Did anyone change the data VM by hand?"
Claude: detect_drift → drifted: ~ aws_instance.vm (t3.small). Want me to plan a change to restore it?

How it works

flowchart LR
  A[AI agent] -- MCP --> S[infra-agent-gateway]
  S -- tofu plan -out --> T[OpenTofu]
  S -- plan JSON --> P[Conftest / OPA]
  S -- append --> L[(audit.jsonl)]
  H[Human] -- pnpm approve --> S
  S -- tofu apply planfile --> AWS[(AWS / LocalStack)]
  S -- kubectl apply manifest --> K[(Kubernetes / kind)]

MCP tool

What it does

plan_change

Validates a structured intent (zod), runs tofu plan -out, evaluates the plan JSON with Conftest. Returns planned or denied with reasons. Changes nothing.

request_apply

Moves a planned plan to pending_approval. Refuses denied plans. Applies nothing.

deploy_workload

Renders a Deployment from a structured intent (image, replicas, namespace, limits), checks it with Conftest and, if compliant, leaves it pending_approval. Deploys nothing.

detect_drift

Re-plans the last applied intent for a workspace (tofu plan -detailed-exitcode) and reports what changed outside the gateway. Read-only: fixing drift goes through plan_change.

get_audit_log

Recent audit entries.

There is no approve tool. See ADR 0001.

Related MCP server: agent-sandbox

Guardrails

Risk

Control

Agent writes arbitrary infrastructure

Agents send a typed intent, never HCL; the module decides what gets built

Unsafe config (open SSH, huge instances, missing owner, prod, deletes)

Rego policies in policy/, unit-tested with conftest verify

Unsafe workloads (privileged, no cpu/memory limits, system namespaces)

Rego in policy/k8s.rego, checked against the rendered manifest

Agent applies its own change

No approve tool; the gateway also rejects non-human: approvers

Plan swapped or changed after review

sha256 of the plan file (or rendered manifest) checked at apply; applies the saved file, never re-plans (ADR 0002)

No accountability

Append-only JSONL audit: who, what, plan id, policy result, approver, outcome

Prompt injection via tool output

Output is data; AGENTS.md tells agents so, and no output can trigger an apply on its own

Known limits: one VM shape and one workload shape (a Deployment) so far; drift detection covers VMs only; workspaces are selected per call, so concurrent plans aren't safe yet; the audit log is local (ship it to an immutable store like S3 Object Lock for real use).

Run it

Needs Node 24, pnpm, OpenTofu, Conftest, Docker, kind, kubectl.

pnpm install
docker run -d --name localstack -p 4566:4566 localstack/localstack:4   # free AWS emulator (newer tags need a license)
kind create cluster --name iag    # the gateway only ever uses context kind-iag (override: KUBE_CONTEXT)

pnpm test               # gateway + MCP seams (fast, no tools needed)
pnpm test:policy        # Rego unit tests
INTEGRATION=1 pnpm test test/integration.test.ts   # real OpenTofu + Conftest + LocalStack + kind

Connect Claude Code:

claude mcp add infra-gateway -- pnpm --dir "$PWD" start

Approve from another terminal: pnpm approve <planId>.

Tests

Written test-first at four seams: the gateway core (fakes only for the external CLIs), the MCP surface (a real MCP client over an in-memory transport), the policies (conftest verify), and an integration suite against real OpenTofu, Conftest, LocalStack and kind.

Available Tools

5 tools
deploy_workloadA

Deploy a container to Kubernetes from a structured intent. The gateway renders the Deployment and checks it against policy (no privileged containers, cpu and memory limits required, allowed namespaces only). A compliant workload waits as pending_approval until a human runs pnpm approve <planId>; nothing is deployed by this call.

Inputs: name (required), image (required), replicas (required), namespace (required), +3 more.

detect_driftA
Read-only

Check whether the real infrastructure for a workspace still matches the last applied plan. Read-only: reports what changed outside the gateway, never fixes it. To fix drift, call plan_change.

Inputs: name (required).

get_audit_logC
Read-only

Read the most recent audit log entries.

Inputs: limit.

plan_changeA
Read-only

Plan an infrastructure change from a structured intent. Runs tofu plan and policy checks; never changes anything. Returns a planId, a summary and any policy violations.

Inputs: kind (required), name (required), owner (required), environment (required), +2 more.

request_applyA

Ask a human to approve and apply a plan. Does not apply anything; the plan waits as pending_approval.

Inputs: planId (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 5 tools

    Disambiguation4/5

    plan_change (Terraform/OpenTofu plan) and deploy_workload (Kubernetes Deployment) both funnel into a pending_approval human workflow, which could momentarily confuse an agent choosing between them, but the descriptions clearly separate the two resource domains. request_apply is distinct from both as the approval-request step for an existing planId, and detect_drift / get_audit_log are unambiguously read-only observers.

    Naming Consistency5/5

    Every tool follows a strict verb_noun snake_case pattern: plan_change, request_apply, deploy_workload, detect_drift, get_audit_log. No camelCase, no vague single-word verbs, no mixing of noun-first or verb-first styles.

    Tool Count4/5

    Five tools is a tight, well-scoped surface for a human-in-the-loop infra gateway — each tool maps to a distinct phase (plan, approve, deploy, observe, audit). It leans slightly thin because there is no tool to query plan or approval status, which is the most likely thing an agent needs next.

    Completeness3/5

    The core lifecycle (plan → request approval → human applies → drift check → audit) is covered and cross-references are explicit (detect_drift points to plan_change). However, there is no get_plan / list_plans / pending-approval listing, no workspace enumeration, and no rollback, so an agent cannot verify the outcome of its own request_apply except by falling back to get_audit_log.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      D
      maintenance
      Enables AI coding agents to run Kubernetes inspection and Terraform plan/apply operations inside ephemeral gVisor-sandboxed jobs with short-lived, narrowly-scoped credentials, while routing destructive changes through a human approval gate.
      3
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to perform safe, auditable Kubernetes write actions such as scaling, restarting and rolling back Deployments through a plan → policy-check → approve → apply → audit flow, with server-side guards, single-use plans and scoped RBAC. Read-only planning and Prometheus SLO/alert tools support the same guarded workflow.
      Apache 2.0