mcp-server-terraform
This server lets you manage Terraform infrastructure through natural language, translating conversational requests into real Terraform CLI commands.
Core Terraform Workflow
Initialize (
tf_init): Set up a working directory, download providers/modulesValidate (
tf_validate): Check.tffiles for syntax errors without accessing remote APIsPlan (
tf_plan): Preview changes with a structured risk/cost summary, flagging expensive always-on resources (NAT gateways, EKS/RDS clusters, etc.) with estimated monthly costsApply (
tf_apply): Apply changes with a built-in two-step confirmation flowDestroy (
tf_destroy): Tear down infrastructure with the same two-step confirmation gate
State & Resource Management
Outputs (
tf_output): Retrieve output values from current stateState (
tf_state): List, show, move, or remove resources from stateResources (
tf_resource): Import existing cloud resources, taint/untaint for forced recreation, or refresh stateWorkspaces (
tf_workspace): List, show, select, or create workspaces
Diagnostics & Safety
Preflight checks (
tf_preflight): Verify cloud provider authentication before running commandsDrift detection (
tf_drift): Identify resources changed outside of Terraform via a refresh-only plan/tf-diagnoseprompt: Guides Claude through systematic troubleshooting of failuresSafety modes: Restrict available tools to read-only or non-destructive subsets via environment variables
Audit logging: Every tool call logged as JSON with variable values redacted
Dangerous flag blocking: Prevents use of risky Terraform CLI flags
Allows managing Terraform infrastructure, including planning, applying, destroying, inspecting state, detecting drift, importing resources, and more, all through natural language commands.
mcp-server-terraform
A Model Context Protocol (MCP) server that lets Claude manage Terraform infrastructure through natural language.
Run plans, apply changes, inspect state, and diagnose failures — all from a Claude conversation.
What it does
Instead of switching to a terminal to run terraform plan, you can ask Claude:
"Plan the changes in
/infra/stagingand explain what will change"
"Apply it — but only if no resources will be destroyed"
"Show me all the outputs from the prod workspace"
"Something broke after the last apply — diagnose it"
The server translates these into real terraform CLI commands on your machine, with a built-in safety confirmation flow before any destructive operation runs.
Related MCP server: tfmcp
Tools
Tool | Description | Destructive |
| Initialize a Terraform working directory | No |
| Validate configuration syntax | No |
| Run a plan and return the diff + risk/cost summary | No |
| Apply changes (requires | Yes |
| Destroy infrastructure (requires | Yes |
| Read output values from state | No |
| List, show, move, or remove state entries | Partial |
| List, show, select, or create workspaces | No |
| Check provider CLI authentication before running | No |
| Detect resources changed outside Terraform | No |
| Import, taint, untaint, or refresh resources | Yes |
Plan risk & cost summary
Every plan (and every apply preview) is analyzed via terraform show -json and
annotated with a structured summary — destroyed resources are called out, and
always-on resources that commonly cause bill shock are flagged with rough
monthly costs:
── Plan Summary ──
+ 3 create, ~ 1 update, - 0 destroy, ± 0 replace
💸 EXPENSIVE — always-on resources being created:
⚠ aws_nat_gateway.main (~$32/month + data processing if left running)
Remember to tf_destroy when you're done experimenting.Cost-flagged resource types include NAT gateways, load balancers, EKS/AKS/GKE control planes, RDS/Cloud SQL instances, ElastiCache, Redshift, MSK, and Azure Firewall (~$900/month!).
Drift detection
tf_drift runs a refresh-only plan and reports resources that were changed
outside Terraform (e.g. manually in the cloud console), with the changed
attribute names and remediation options.
Audit logging
Set AUDIT_LOG_PATH to a file path and every tool call is appended as a JSON
line with timestamp, tool name, outcome, and duration. Variable values are
always redacted (db_password=<redacted>) — only names are logged.
Confirmation flow
tf_apply and tf_destroy use a two-step safety flow:
First call (no
confirmed) → runsterraform plan, shows the diff, does nothing elseSecond call (
confirmed: true) → actually applies or destroys
Claude is instructed to never pass confirmed: true without first presenting the plan to you.
Prompt
The server exposes a /tf-diagnose prompt that guides Claude through a systematic 5-step diagnosis of plan or apply failures.
Prerequisites
Node.js 18 or later
Terraform CLI on your PATH
Claude Desktop (or any MCP-compatible client)
Installation
No install needed — run it straight from npm:
npx @rajsir/mcp-server-terraformOr, for development, from source:
git clone https://github.com/RajeevSirohi/mcp-server-terraform.git
cd mcp-server-terraform
npm install
npm run buildClaude Desktop setup
Add to your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"terraform": {
"command": "npx",
"args": ["-y", "@rajsir/mcp-server-terraform"]
}
}
}(If running from source instead, use "command": "node" with "args": ["/absolute/path/to/dist/index.js"].)
Restart Claude Desktop. You should see a hammer icon indicating tools are available.
Usage
Once connected, just talk to Claude about your Terraform workspaces in plain language. Some examples:
First time in a new workspace
"Initialize the terraform config in
C:\infra\stagingand check if I'm logged into the right cloud accounts"
Claude runs tf_init, then tf_preflight — if you're not authenticated it tells you exactly which command to run (az login, aws configure, ...).
The everyday plan → review → apply loop
"Plan the changes in
C:\infra\stagingand explain what will change"
You get the plan diff plus a summary: how many resources created/updated/destroyed, anything destructive called out explicitly, and cost warnings for expensive always-on resources.
"Looks good, apply it"
Claude shows the plan preview one more time and asks for your confirmation — nothing is applied until you say yes. This two-step gate is built into the server itself, not just the prompt, so Claude cannot skip it.
Checking on your infrastructure
"Did anyone change anything outside terraform in the prod workspace?"
tf_drift compares state against reality and reports what was modified in the console, with options to accept or revert.
"Show me all the outputs" · "List everything in state" · "What workspaces exist?"
Learning / experimenting (e.g. cert prep)
"Apply the VPC lab in
C:\labs\vpc, and when I say 'done' destroy everything"
The cost flags are your friend here — if a lab creates a NAT gateway or EKS cluster, the plan summary warns you what it costs per month if forgotten:
💸 EXPENSIVE — always-on resources being created:
⚠ aws_nat_gateway.main (~$32/month + data processing if left running)
Remember to tf_destroy when you're done experimenting.Fixing things
"terraform plan is failing in
C:\infra\staging— diagnose it"
The /tf-diagnose prompt walks Claude through validate → providers → plan → state → outputs systematically. There's also /tf-login for step-by-step authentication setup per provider.
"Import the S3 bucket
my-legacy-bucketinto state asaws_s3_bucket.legacy"
"Taint the web server so it gets recreated on the next apply"
Recommended setup for shared or cautious environments
Run with ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true (see Safety modes below) so apply/destroy are unavailable entirely, and set AUDIT_LOG_PATH so every operation is logged.
Safety modes
Control which tools are available via environment variables:
Variable | Effect |
| Only |
| Blocks |
| Explicit comma-separated allowlist |
Example — read-only mode:
{
"mcpServers": {
"terraform": {
"command": "node",
"args": ["/path/to/dist/index.js"],
"env": {
"ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS": "true"
}
}
}
}Development
npm run dev # watch mode (recompiles on save)
npm test # run tests
npm run build # production buildProject structure
src/
index.ts # MCP server entry point, tool registration
config/ # (reserved for future config/telemetry)
models/
common-parameters.ts # Shared Zod schemas
security/
tf-flags.ts # Dangerous flag blocking
tools/
tf-init.ts
tf-validate.ts
tf-plan.ts
tf-apply.ts # Two-step confirmation flow
tf-destroy.ts # Two-step confirmation flow
tf-output.ts
tf-state.ts
tf-workspace.ts
utils/
terraform-runner.ts # Core exec wrapper, workspace switching
prompts/
index.ts # /tf-diagnose prompt
tests/
tf-flags.test.ts
tf-apply.test.tsAdding a new tool
Create
src/tools/tf-yourcommand.ts— export a*Schemaconst and an async handler functionImport both in
src/index.tsAdd the schema to
readonlyToolsordestructiveToolsarrayAdd a
casein theCallToolRequestSchemahandler switch
Roadmap
Terraform Cloud / Enterprise API support (Phase 2)
OpenTelemetry tracing
SSE / streamable HTTP transport for remote deployments
Docker image on GitHub Container Registry
Plan risk & cost analysis
Drift detection
Import / taint / untaint / refresh
Audit logging
CI (build, test matrix, e2e against real terraform)
Contributing
See CONTRIBUTING.md.
License
MIT — see LICENSE.
Available Tools
11 toolstf_applyADestructive
Apply Terraform changes to real infrastructure.
TWO-STEP SAFETY FLOW:
Call without confirmed=true → runs terraform plan, shows the diff, returns without applying.
Call with confirmed=true after reviewing the diff → actually applies the changes.
Never pass confirmed=true without first showing the plan output to the user.
Inputs: workdir (required), vars, target, varFile, +3 more.
tf_destroyADestructive
Destroy all Terraform-managed infrastructure in the workspace.
TWO-STEP SAFETY FLOW:
Call without confirmed=true → shows the destroy plan (what will be deleted).
Call with confirmed=true after the user explicitly approves → destroys everything.
This is irreversible. Always show the plan and get explicit user approval first.
Inputs: workdir (required), vars, target, varFile, +2 more.
tf_driftA
Detect infrastructure drift — resources that were changed outside of Terraform (e.g. manually in the cloud console). Runs a refresh-only plan and reports differences between state and reality. Read-only, makes no changes.
Inputs: workdir (required), workspace.
tf_initA
Initialize a Terraform working directory. Downloads providers and modules. Run this before plan or apply on a fresh workspace.
Inputs: workdir (required), upgrade, reconfigure.
tf_outputA
Read Terraform output values from the current state. Returns all outputs as JSON, or a specific output by name.
Inputs: workdir (required), name, workspace.
tf_planA
Run terraform plan and return a human-readable diff of what will change. Safe — makes no changes to infrastructure.
Inputs: workdir (required), vars, target, varFile, +2 more.
tf_preflightA
Check which cloud providers are used in a Terraform workspace and verify authentication status for each. Call this before plan or apply to catch credential issues early.
Inputs: workdir (required).
tf_resourceADestructive
Resource-level state operations:
import: Bring an existing cloud resource under Terraform management (requires address + id)
taint: Mark a resource for recreation on next apply (requires address)
untaint: Remove the taint mark (requires address)
refresh: Sync state with real infrastructure (accepts drift into state)
Inputs: workdir (required), operation (required), id, address, +1 more.
tf_stateADestructive
Manage Terraform state. Supports the following operations:
list: List all resources in state
show: Show attributes of a specific resource
mv: Move/rename a resource in state (use with care)
rm: Remove a resource from state without destroying it (destructive)
Inputs: workdir (required), operation (required), address, workspace, +1 more.
tf_validateA
Validate Terraform configuration files for syntax and internal consistency. Does not access remote state or APIs.
Inputs: workdir (required).
tf_workspaceA
Manage Terraform workspaces. Supports:
list: List all workspaces and show which is active
show: Show the current workspace name
select: Switch to a workspace
new: Create a new workspace
Inputs: workdir (required), operation (required), name.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 11 tools
Each tool has a distinct purpose: tf_apply applies changes, tf_destroy destroys, tf_drift detects drift, tf_init initializes, tf_output reads outputs, tf_plan plans, tf_preflight checks auth, tf_resource handles resource-level state ops, tf_state manages state, tf_validate validates config, tf_workspace manages workspaces. No overlap.
All tools follow the tf_ prefix with clear verb names (e.g., apply, destroy, drift, init, output, plan, preflight, resource, state, validate, workspace). The pattern is consistent and predictable.
11 tools cover the essential Terraform operations comprehensively—init, validate, plan, apply, destroy, state management, resource ops, drift detection, outputs, workspace management, and preflight checks. The count is well-scoped for the domain.
The tool set covers the full Terraform workflow: init, validate, plan, apply, destroy, plus state manipulation, resource import/taint/untaint/refresh, drift detection, output reading, workspace management, and preflight authentication checks. No obvious gaps.
Maintenance
Related MCP Connectors
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
An MCP server that provides an API to LLMs to manage their JumpCloud resources.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Related MCP Servers
- AlicenseBqualityDmaintenanceAn implementation of Claude Code as a Model Context Protocol server that enables using Claude's software engineering capabilities (code generation, editing, reviewing, and file operations) through the standardized MCP interface.8188MIT
- AlicenseNot gradedqualityBmaintenance🌍 Terraform Model Context Protocol (MCP) Tool - An experimental CLI tool that enables AI assistants to manage and operate Terraform environments. Supports reading Terraform configurations, analyzing plans, applying configurations, and managing state with Claude Desktop integration. ⚡️373MIT
- AlicenseAqualityDmaintenanceA Model Context Protocol (MCP) server that integrates Claude with the Terraform Cloud API, allowing Claude to manage your Terraform infrastructure through natural conversation.6223MIT
- AlicenseAqualityDmaintenanceA Model Context Protocol server that enables managing Terrakube infrastructure through natural language, handling workspace management, variables, modules, and organization operations.163Apache 2.0