opentofu
Provides tools to run OpenTofu commands (init, validate, fmt, plan, show, output, state list, apply) against a confined working directory, with plan-file-only applies, explicit APPLY confirmation, and audit logging.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
opentofu-mcp
A Model Context Protocol server that lets Cursor drive OpenTofu — without letting it run away with your infrastructure.
Large language models are good at writing infrastructure code and bad at knowing when not to execute it. This server exposes OpenTofu as a small set of narrow, auditable tools, built around one rule:
applyonly ever runs a plan file that already exists on disk, and only when the caller literally passesconfirm: "APPLY".
Everything else is read-only or produces an artefact you can inspect first.
Why this exists
The usual loop with an AI assistant and Terraform/OpenTofu looks like this: the model edits .tf files, then someone copy-pastes commands into a terminal and hopes the plan is what the model said it was.
This server closes that gap:
the model can generate a plan and read it back as JSON;
you review the plan;
the model applies that exact plan file, nothing else;
every invocation is written to an audit log with arguments, exit code and duration.
It is deliberately boring. That is the point.
Related MCP server: agent-sandbox
Safety model
Control | Behaviour |
No shell | Commands are spawned with |
Working directory confinement | Absolute paths are rejected; relative paths are resolved and refused if they escape |
No | The flag is rejected before the process is spawned |
No | Destructive applies must be planned explicitly, reviewed, and applied as a plan |
Explicit confirmation |
|
Plan-first |
|
Audit trail | One JSON line per call: timestamp, tool, args, cwd, exit code, duration |
Timeouts | Every command is killed after |
The server never stores credentials. It inherits the environment you launch it with, exactly like running tofu yourself.
Requirements
Node.js 18+
OpenTofu installed and reachable (
tofu version)A directory containing your
.tfconfiguration
Install
git clone https://github.com/aleraze/opentofu-mcp.git
cd opentofu-mcp
npm install
npm run buildThe compiled entry point is dist/index.js.
Configure Cursor
Add the server to Cursor's MCP configuration — either globally (~/.cursor/mcp.json) or per project (.cursor/mcp.json):
{
"mcpServers": {
"opentofu": {
"command": "node",
"args": ["/absolute/path/to/opentofu-mcp/dist/index.js"],
"env": {
"TOFU_WORKDIR": "/absolute/path/to/your/infrastructure",
"TOFU_BIN": "tofu",
"TOFU_MCP_TIMEOUT_MS": "300000"
}
}
}
}Then open Cursor → Settings → MCP and enable the opentofu server. The tools appear in the chat's tool picker.
TOFU_WORKDIRis the only directory the server will operate on. Point it at your infrastructure repository, not at your home directory.
Tools
Tool | Arguments | Changes infrastructure? |
|
| No — downloads providers, prepares the backend |
| — | No |
|
| No — rewrites formatting only when |
|
| No — writes a plan file |
|
| No — reads a plan or the current state |
|
| No |
| — | No |
|
| Yes |
Output is truncated at 40,000 characters; use tofu_show with json: true to inspect a specific part of a large plan.
A real workflow: single node → three nodes
This is the loop the server was built for — growing a single-node cluster into a three-node one without blind applies.
1. tofu_init { upgrade: false }
2. tofu_validate {}
3. tofu_fmt { check: true } → the diff must be empty
4. tofu_plan { out: "grow-3nodes.tfplan", varFile: "prod.tfvars" }
5. tofu_show { planFile: "grow-3nodes.tfplan" } → you read what will change
6. — human review, out loud, on the plan —
7. tofu_apply { planFile: "grow-3nodes.tfplan", confirm: "APPLY" }
8. tofu_output {}If step 5 shows anything you did not expect, you delete the plan file and go back to step 4. Nothing has been touched.
Environment variables
Variable | Default | Purpose |
|
| The only directory the server operates on |
|
| Path to the OpenTofu binary |
|
| Per-command timeout |
|
| Where the audit trail is written |
Audit log
Each call appends a single JSON line:
{"ts":"2026-12-03T09:14:02.118Z","tool":"tofu_apply","args":["apply","-input=false","-no-color","/srv/infra/grow-3nodes.tfplan"],"cwd":"/srv/infra","exitCode":0,"durationMs":48213,"outcome":"ok","note":"plan applied"}It is append-only and never rotated automatically: treat it as evidence, archive it with your logs.
Limitations
One working directory per process. Multiple environments means multiple server entries in
mcp.json.No remote state helpers. Backend authentication is whatever your environment already provides.
No
tofu importyet — it mutates state without a plan, so it is intentionally out of scope.No
destroyshortcut. Plan withdestroy: true, review, then apply the plan.
Roadmap, in order of usefulness: tofu_state_show, tofu_import behind an explicit plan, a --dry-run global switch, and Windows path tests.
License
MIT — see LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Design, plan and apply cloud infrastructure across AWS, GCP, Azure and Hetzner, with human approval.
Fail-closed policy guardrails for AI agents running kubectl, terraform, helm, and argocd.
Provides capabilities that let LLM agents perform a range of infrastructure management tasks.
Permission checks, human approval cards, and signed audit trails for AI agent tool calls.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables generating, validating, planning, and applying Terraform configurations to manage infrastructure through natural language.MIT
- 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-
- AlicenseAqualityDmaintenanceEnables AI coding agents to plan, policy-check, and cost-estimate Terraform changes while requiring human approval through Slack or CLI before any terraform apply can execute.97 npmMIT
- FlicenseAqualityCmaintenanceEnables coding agents to perform workspace-confined file operations, read-only Git inspection, and structured shell commands, while requiring out-of-band human approval for mutations and external executions and maintaining an audit trail.143-