tf

tfmcp

A Terraform MCP server allowing AI assistants to manage and operate Terraform environments, enabling reading configurations, analyzing plans, applying configurations, and managing Terraform state.

Publishertfmcp
Submitted date4/13/2025

๐Ÿค– tfmcp: Empowering LLMs to Orchestrate Terraform with the Model Context Protocol

Unleash the power of Large Language Models (LLMs) to manage and automate your Terraform infrastructure with tfmcp, the Terraform Model Context Protocol tool. This innovative tool bridges the gap between AI and Infrastructure as Code (IaC), enabling seamless integration and intelligent automation of your Terraform environments.

๐ŸŽฌ Interactive Demo

Witness tfmcp in action, seamlessly interacting with Claude Desktop to manage Terraform configurations:

tfmcp Demo with Claude Desktop

This demo showcases the potential of LLMs to:

  • Understand Terraform configurations
  • Analyze Terraform plan outputs
  • Apply Terraform changes with confidence
  • Manage Terraform state effectively
  • Create and Modify Terraform configurations intelligently

โœจ Latest Release: v0.1.1

The first stable release of tfmcp is now available on Crates.io! Install it effortlessly using Cargo:

cargo install tfmcp

Key Features

  • Terraform CLI Integration: Deeply integrated with the Terraform CLI, enabling comprehensive analysis and execution of Terraform operations.
  • Model Context Protocol (MCP) Server: Exposes Terraform management capabilities through a standardized MCP server, allowing AI assistants to interact with your infrastructure.
  • Rust-Powered Performance: Leverages the speed and efficiency of the Rust ecosystem for blazing-fast processing of Terraform configurations.
  • Automatic Project Setup: Simplifies the onboarding process by automatically creating sample Terraform projects, ensuring a smooth experience for new users.

Installation Guide

From Source

  1. Clone the repository:

    git clone https://github.com/nwiizo/tfmcp cd tfmcp
  2. Build and install:

    cargo install --path .

From Crates.io

cargo install tfmcp

Prerequisites

  • Rust (edition 2021): Ensure you have a compatible Rust environment installed.
  • Terraform CLI: The Terraform CLI must be installed and accessible in your system's PATH.
  • Claude Desktop (Optional): Required for integration with the Claude Desktop AI assistant.

Usage Instructions

$ tfmcp --help โœจ A CLI tool to manage Terraform configurations and operate Terraform through the Model Context Protocol (MCP). Usage: tfmcp [OPTIONS] [COMMAND] Commands: mcp Launch tfmcp as an MCP server analyze Analyze Terraform configurations help Print this message or the help of the given subcommand(s) Options: -c, --config <PATH> Path to the configuration file -d, --dir <PATH> Terraform project directory -V, --version Print version -h, --help Print help

Integrating with Claude Desktop

  1. Install tfmcp:

    cargo install tfmcp
  2. Locate tfmcp Executable:

    which tfmcp
  3. Configure Claude Desktop: Add the following configuration to ~/Library/Application\ Support/Claude/claude_desktop_config.json:

    { "mcpServers": { "tfmcp": { "command": "/path/to/your/tfmcp", // Replace with the actual path from step 2 "args": ["mcp"], "env": { "HOME": "/Users/yourusername", // Replace with your username "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", "TERRAFORM_DIR": "/path/to/your/terraform/project" // Optional: specify your Terraform project } } } }
  4. Restart Claude Desktop: Enable the tfmcp tool within Claude Desktop.

  5. Automatic Project Creation: tfmcp will automatically create a sample Terraform project in ~/terraform if one doesn't exist, allowing Claude to immediately interact with Terraform. This sample project is based on the examples in the example/demo directory of this repository.

Troubleshooting and Logging

  • Log Location: The tfmcp server logs are located at ~/Library/Logs/Claude/mcp-server-tfmcp.log.

  • Common Issues:

    • Claude Connection Issues: Verify the path to the tfmcp executable in your configuration.
    • Terraform Project Issues: tfmcp automatically creates a sample project if none is found.
    • Method Not Found Errors: Ensure MCP protocol support includes resources/list and prompts/list methods.

Environment Variables

  • TERRAFORM_DIR: Specifies a custom Terraform project directory. Defaults to ~/terraform if not set. The project directory can also be changed at runtime using the set_terraform_directory tool.
  • TFMCP_LOG_LEVEL: Controls logging verbosity (debug, info, warn, error).
  • TFMCP_DEMO_MODE: Enables demo mode with enhanced safety features (true).

Security Considerations

  • tfmcp executes Terraform commands, potentially modifying infrastructure.
  • Use appropriate IAM permissions and role boundaries in production environments.
  • Thoroughly review all Terraform plans before applying them, especially those generated by AI.
  • Be aware that sensitive information in your Terraform state may be accessible to AI assistants.

Contributing

Contributions are highly encouraged!

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

Roadmap

Completed Milestones

  • Core Terraform Integration: Implemented core integration with the Terraform CLI.
  • MCP Server Implementation: Developed the initial Model Context Protocol server.
  • Automatic Project Creation: Added automatic creation of sample Terraform projects.
  • Claude Desktop Integration: Enabled seamless integration with Claude Desktop.
  • Core MCP Methods: Implemented essential MCP methods (resources/list, prompts/list).
  • Enhanced Error Handling: Improved error handling and recovery mechanisms.
  • Dynamic Project Switching: Added the ability to change the active Terraform project directory at runtime.
  • Crates.io Publication: Published the package to Crates.io.

Ongoing Development

  • Advanced Terraform Analysis: Implement deeper parsing and analysis of Terraform configurations, plans, and state files.
  • Multi-Environment Support: Add support for managing multiple Terraform environments, workspaces, and modules.
  • Security Hardening: Enhance security features with improved authentication and authorization.
  • Expanded MCP Support: Implement additional MCP methods for richer AI assistant integration.
  • Interactive TUI: Develop a terminal-based user interface for local usage and debugging.
  • Cost Estimation: Integrate with cloud provider pricing APIs to estimate Terraform plan costs.
  • Performance Optimization: Optimize resource usage and response times for large projects.
  • Broader AI Platform Integration: Extend support beyond Claude to other AI assistants.
  • Comprehensive Testing: Expand test coverage with integration tests using real Terraform configurations.
  • Plugin Architecture: Develop a plugin system to extend core functionality.

Visit More

View All