tf-approval-gate
This server lets AI agents safely manage Terraform changes by planning, policy-checking, and cost-estimating them, while making it impossible to apply without a real human's explicit approval.
Initialize or write Terraform files in a sandboxed workspace (
tf_workspace_init,tf_write_file)Run
terraform planand get a resource-level change summary (tf_plan)Run policy checks with Checkov and OPA/Conftest (
tf_policy_check)Estimate monthly cost changes with Infracost (
tf_cost_estimate)Get a combined proposal with plan, policy, and cost plus a safe/needs_review/blocked recommendation (
tf_propose_change)Request human approval via Slack buttons or server-terminal CLI prompt (
tf_request_approval)Poll for approval status and receive a signed, single-use approval token only after a human approves (
tf_check_approval_status)Run
terraform applyonly with a valid approval ID and token, which the server verifies for signature, expiry, single-use, plan checksum, and drift (tf_apply)Optionally override blocking policy verdicts if explicitly enabled server-side
Provides monthly cost estimates for Terraform changes as part of the proposed plan, used when Infracost is configured.
Posts proposed Terraform changes to Slack with Approve/Reject buttons and only allows approval from allow-listed Slack users, minting a token for terraform apply.
Runs Terraform plan, policy checks, and cost estimation in a sandboxed workdir, and gates terraform apply behind a signed, single-use approval token.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@tf-approval-gate Plan my Terraform changes, run policy checks, and request approval."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
TF Approval Gate
An MCP server that lets AI coding agents (Claude Code, Cursor, etc.) plan,
policy-check, and cost-estimate Terraform changes -- but makes it
structurally impossible for the agent to run terraform apply without a
real human clicking Approve in Slack first.
Why
AI agents can now write and run Terraform directly against real cloud
accounts. An agent that can terraform apply on its own can silently
destroy or misconfigure production infrastructure with no human in the loop.
TF Approval Gate closes that gap: every apply requires a signed, single-use
token that only a real human's Slack click (or, in dev mode, a real human at
a terminal) can mint. The agent's own claim that "the human approved" is
never trusted -- the server re-verifies everything itself.
Related MCP server: Laguarde
How it works
Agent edits
.tffiles, then callstf_propose_change-- runsterraform plan, Checkov (+ OPA if configured), and Infracost (if configured), and returns one bundled proposal with a safe/needs_review/blocked recommendation.Agent calls
tf_request_approval-- posts the diff + policy findings + cost to Slack with Approve/Reject buttons (or prompts on the server's terminal inAPPROVAL_MODE=cli). Refuses to post at all if policy findings are blocking.Agent polls
tf_check_approval_status.A human clicks Approve → the server verifies the click came from an allow-listed Slack user and mints a signed, single-use token bound to that exact plan's checksum.
Agent calls
tf_applywith the token. The server re-verifies signature, expiry, single-use status, the plan's binary checksum, and checks for cloud-side drift -- only then does it runterraform apply.
See docs/architecture.md and docs/security-model.md for the full design and threat model.
Quick start (local, no Slack setup needed)
git clone https://github.com/SORABH13/tf-approval-gate.git
cd tf-approval-gate
npm install
npm run build
npm run check-binaries # confirms terraform + checkov are on PATHRequires Terraform and
Checkov on
PATH. OPA/Conftest and Infracost are optional (features soft-skip if
missing). Or skip installing anything and use the
Docker image below, which bundles all three.
Run it in dev mode (APPROVAL_MODE=cli prints the diff to the server's
terminal and waits for a y/n instead of posting to Slack -- good for a first
local test, weaker guarantee than Slack, see
docs/security-model.md):
APPROVAL_MODE=cli TF_APPROVAL_GATE_SECRET=$(openssl rand -hex 32) npm startThen add it as an MCP server in Claude Code (or any MCP client):
{
"mcpServers": {
"tf-approval-gate": {
"command": "node",
"args": ["/absolute/path/to/tf-approval-gate/dist/index.js"],
"env": {
"APPROVAL_MODE": "cli",
"TF_APPROVAL_GATE_SECRET": "<same secret as above>"
}
}
}
}Point your agent at examples/local-demo (uses the null/random
providers, no cloud credentials required) and ask it to run
tf_workspace_init → tf_propose_change → tf_request_approval →
tf_apply.
Docker / devcontainer
docker build produces an image with Node, Terraform, Checkov, and
Conftest (OPA) preinstalled -- no host setup beyond Docker itself.
docker build -t tf-approval-gate .
docker run --rm -it \
-e APPROVAL_MODE=cli \
-e TF_APPROVAL_GATE_SECRET=$(openssl rand -hex 32) \
-v "$(pwd)/examples/local-demo":/examples/local-demo:ro \
-v tf-approval-gate-data:/data \
tf-approval-gateFor Slack mode, add -e SLACK_BOT_TOKEN=... -e SLACK_APP_TOKEN=... -e SLACK_APPROVAL_CHANNEL=... -e SLACK_APPROVER_USER_IDS=...
and drop APPROVAL_MODE=cli. Approval state persists in the /data volume
(SQLite-backed, see docs/architecture.md).
A .devcontainer/devcontainer.json is
also included for VS Code / GitHub Codespaces -- open the repo in a
container and terraform/checkov/conftest are ready immediately.
Slack setup (production mode)
Create a Slack app from examples/slack-app-manifest.yml.
Enable Socket Mode, generate an app-level token (
xapp-...).Install the app to your workspace, copy the bot token (
xoxb-...).Set
SLACK_BOT_TOKEN,SLACK_APP_TOKEN,SLACK_APPROVAL_CHANNEL, andSLACK_APPROVER_USER_IDS(comma-separated Slack user IDs allowed to click Approve/Reject) -- see .env.example.Run with
APPROVAL_MODE=slack(the default).
Full walkthrough: docs/slack-setup.md.
Tools
Tool | Purpose |
| Checks out/copies a Terraform project into a sandboxed workdir. |
| Writes |
|
|
| Checkov (+ OPA/Conftest) against the plan, merged into one report. |
| Infracost monthly cost delta (skipped if unconfigured). |
| Composite: plan + policy + cost in one call. Call this first. |
| Posts to Slack (or CLI) for human approval. |
| Poll for the signed approval token. |
| The only tool that runs |
Full reference: docs/tool-reference.md.
License
MIT -- see LICENSE.
Available Tools
9 toolstf_applyA
The only tool that runs terraform apply. Requires a valid approvalId + approvalToken minted by a real human approval; verifies signature, expiry, single-use, plan checksum, and drift server-side before applying.
Inputs: approvalId (required), workspaceId (required), approvalToken (required).
tf_check_approval_statusB
Polls the status of a pending approval. Returns a signed approvalToken once a human approves.
Inputs: approvalId (required).
tf_cost_estimateB
Runs Infracost against the current plan and returns a monthly cost delta (skipped if INFRACOST_API_KEY is unset).
Inputs: workspaceId (required).
tf_planB
Runs terraform init+plan and returns a resource-level change summary.
Inputs: workspaceId (required).
tf_policy_checkB
Runs Checkov (and OPA/Conftest if configured) against the current plan and returns a merged policy report.
Inputs: workspaceId (required).
tf_propose_changeB
Composite tool: runs plan, policy check, and cost estimate together and returns one bundled Proposal with a recommendation (safe/needs_review/blocked). Call this before tf_request_approval.
Inputs: workspaceId (required).
tf_request_approvalB
Sends the current plan for human approval (Slack, or the server's terminal in APPROVAL_MODE=cli). Refuses if policy findings are blocking. Returns an approvalId to poll.
Inputs: workspaceId (required), overridePolicy.
tf_workspace_initC
Checks out/copies a Terraform project into a sandboxed workdir.
Inputs: workspaceId (required), sourceDir.
tf_write_fileA
Writes a .tf/.tfvars file into a sandboxed workspace (for agents with no native filesystem access).
Inputs: content (required), workspaceId (required), relativePath (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool has a distinct role in the Terraform approval workflow: workspace setup, file writing, planning, policy/cost checks, bundled proposal, approval request, polling, and apply. The composite tf_propose_change is clearly described as an aggregate of the three analysis tools, so there is no real ambiguity about when to use it.
All tools share the tf_ prefix and snake_case style, making them recognizable as part of the same family. However, naming order is not perfectly uniform: tf_workspace_init, tf_policy_check, and tf_cost_estimate are object-first/noun phrases while tf_write_file, tf_propose_change, and tf_request_approval are verb-first.
9 tools is well-scoped for an approval-gate server covering workspace setup, plan analysis, policy/cost evaluation, human approval, and guarded apply. Each tool adds necessary functionality without redundancy or bloat.
The tool surface covers the full Terraform approval lifecycle: prepare workspace, write config, plan, run policy and cost checks, bundle results, request approval, poll for approval status, and apply with server-side validation. There are no obvious dead ends or missing operations for the stated domain.
Maintenance
Related MCP Connectors
Fail-closed policy guardrails for AI agents running kubectl, terraform, helm, and argocd.
Human-in-the-loop for AI coding agents — ask questions, get approvals via Slack.
Security reviews for coding agents: diffs checked against your org policy and live infrastructure.
Authorize AI agent tool calls before they run: policy-as-code, human approval, signed receipts.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceAutonomous multi-agent pipeline that analyzes Terraform files for cost, governance, and compliance issues, providing real-time remediation and XAI console for human-in-the-loop approval.MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI coding agents to evaluate actions against team-defined policies, record decisions, and obtain human approvals for potentially risky operations.63 npm1-
- AlicenseAqualityCmaintenanceEnables AI agents to safely inspect and execute version-controlled operational runbooks with policy checks, dry-run planning, and out-of-band approvals.3MIT
- FlicenseAqualityDmaintenanceEnables 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-