Get the FREE Ultimate OpenClaw Setup Guide β†’

tfmcp

🌍 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. ⚑️

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio nwiizo-tfmcp tfmcp mcp \
  --env HOME="/Users/yourusername" \
  --env PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
  --env TERRAFORM_DIR="/path/to/your/terraform/project" \
  --env TFMCP_LOG_LEVEL="info"

How to use

tfmcp is an MCP server that exposes Terraform tooling through the Model Context Protocol. It lets an AI assistant connect to Terraform, inspect configurations, plan and apply changes, manage state, and analyze both plans and the current state with risk scoring and recommendations. The server integrates with the Terraform CLI and offers a suite of MCP tools organized into core Terraform operations, workspace and state management, code and output utilities, and security-focused analysis. You can run tfmcp as an MCP server and interact with it via MCP-enabled clients like Claude Desktop, enabling automated Terraform workflows driven by AI. Typical usage involves starting the server (tfmcp mcp) and issuing commands such as analyze_plan, apply_terraform, or terraform_workspace to manage workspaces, inspect plans, and validate configurations.

Key capabilities include:

  • Core Terraform operations: init_terraform, get_terraform_plan, analyze_plan, apply_terraform, destroy_terraform, validate_terraform, validate_terraform_detailed, get_terraform_state, analyze_state, list_terraform_resources, set_terraform_directory.
  • Workspace and state management (v0.1.9): terraform_workspace, terraform_import, terraform_taint, terraform_refresh.
  • Code and output utilities: terraform_fmt, terraform_graph, terraform_output, terraform_providers.
  • Analysis and security: risk-aware analysis, guidance on best practices, and provider/lockfile insights.

To use with Claude Desktop or another MCP client, configure an mcpServers entry pointing to the tfmcp executable and pass the mcp command. You can also run tfmcp with Docker if you prefer containerized deployment, and you can mount your Terraform project into the container as needed.

How to install

Prerequisites:

  • Rust toolchain (edition 2021) and Cargo
  • Terraform CLI installed and available in PATH
  • Optional: Docker for containerized deployment
  • Optional: Claude Desktop (for AI assistant integration)

From Source:

  1. Clone the repository and navigate into it:
# Clone the repository
git clone https://github.com/nwiizo/tfmcp
cd tfmcp
  1. Build and install the tfmcp binary locally:
cargo install --path .

From Crates.io:

cargo install tfmcp

Using Docker:

# Build the Docker image from the repository (run inside the repo directory)
docker build -t tfmcp .

# Run the MCP server by default (mcp command)
docker run -it tfmcp

Running as MCP server:

# Start tfmcp as an MCP server
tfmcp mcp

Note: If you use Docker, you can pass environment variables and mount your Terraform project as needed, e.g.:

docker run -it -v /path/to/your/terraform:/app/terraform tfmcp mcp

Additional notes

Tips and common considerations:

  • Ensure Terraform CLI is installed and accessible in PATH for real Terraform operations.
  • You can set TFMCP_LOG_LEVEL to control logging verbosity (e.g., debug).
  • Use TERRAFORM_DIR to point the MCP server at your Terraform project directory for initial sample projects or during workflows.
  • If using Claude Desktop, you may want to prepare a sample Terraform project that tfmcp can auto-create when needed.
  • Docker-based usage is convenient for isolated environments; remember to mount your Terraform project and set TERRAFORM_DIR accordingly.
  • The MCP server supports 31 tools across several domains (Core Operations, Workspace/State, Code/Output, and Analysis/Security). Familiarize yourself with essential tools like analyze_plan, get_terraform_plan, apply_terraform, terraform_workspace, terraform_import, terraform_fmt, terraform_graph, and terraform_providers to leverage AI-assisted Terraform workflows.
  • For production deployments, review security and access controls, especially if integrating with CI/CD or sensitive Terraform configurations.

Related MCP Servers

Sponsor this space

Reach thousands of developers β†—