Terraform Engine MCP Server
The Terraform Engine MCP Server enables AI agents and clients to manage Terraform-based infrastructure through a set of MCP tools. It supports:
List Tasks: Browse registered Terraform templates, with optional filtering by category (e.g., database, compute) or provider (e.g., AWS, Azure, GCP).
Get Task Schema: Retrieve metadata and JSON input schema for a specific task to understand required variables.
Provision Task: Deploy a new infrastructure environment by providing a task name, unique deployment name, and input payload; triggers an asynchronous Terraform apply.
Get Deployment Status: Check the current status, configuration, and outputs of any deployment.
Destroy Deployment: Tear down and delete a deployment, with built-in dependency checks to prevent removal of parent resources if active child deployments exist.
Additionally, the server exposes a REST API, a modern UI dashboard, and an integrated AI chat interface with multi-provider LLM support. It operates in both local (STDIO) and network (SSE) MCP modes, featuring async execution, caching, and a deterministic FSM orchestrator for safe, efficient infrastructure management.
Provides tools for managing Terraform templates (tasks) and deployments, including provisioning, updating, and tearing down infrastructure.
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., "@Terraform Engine MCP Server show deployment status for 'prod'"
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.
Terraform Engine 🚀
A premium, lightweight, production-ready, self-hosted infrastructure orchestrator with an integrated AI Chat Interface. The engine provides administrative controls to register Terraform templates (called Tasks) and exposes a REST API along with a modern, glassmorphic dashboard and an AI-powered conversational interface to provision, update, and teardown environments (called Deployments) asynchronously.
Features
FastAPI Core: Ultra-fast endpoints for registering tasks and managing deployments.
Async Execution: Arq worker backing (with process-level Mock fallback if Redis is missing).
Two-Tier Caching: Near-instantaneous
terraform initruns with global provider and module caching.Glassmorphism UI: Beautiful, fully responsive theme-aware dashboard (Light & Dark mode).
AI Chat Interface: Built-in conversational assistant powered by Groq, OpenAI, or custom/on-prem LLMs (Ollama, vLLM) with automatic MCP tool calling.
FSM AI Orchestrator: Deterministic Finite-State-Machine (FSM) orchestrator with Redis session persistence, single-purpose LLM subtask nodes, and structural guardrail enforcement.
Comprehensive API: Supports PATCH updates, clean DELETE teardowns, cross-user lookups, and dependency-safe deletion with impact analysis.
MCP Server Support: Exposes local (STDIO) and remote/network (SSE) tools for AI agents (ChatGPT, Claude, Cursor) to manage the infrastructure.
Dependency-Safe Deletion: Automatic dependency detection on deployment deletion — blocks destruction of parent resources (e.g., Subnets, VNets) when active child deployments depend on them (HTTP 409 Conflict with impact report).
Zero-clutter Workspace: Standard directory package hierarchy ready for GitHub and cloud hosting.
Related MCP server: ansible-mcp-server
Directory Layout
.github/
workflows/
ci.yml # Automated GitHub Actions testing flow
PULL_REQUEST_TEMPLATE.md # Standard pull request format
ISSUE_TEMPLATE/ # Structured bug and feature templates
app/ # Main application package
agent/ # FSM Orchestrator, Session State, LLM Client, and Nodes
core/ # Configurations, Auth, Database, Queue
models/ # SQLAlchemy database tables
schemas/ # Pydantic validation schemas
api/ # API endpoint routers (Admin, Public, Lifecycle, Chat)
frontend/ # Jinja2 HTML page router
static/ # Static CSS assets
templates/ # Layouts, dashboard panels, and AI chat interface
docs/ # Detailed architectural design documents
tests/ # Re-organized pytest test suites
pyproject.toml # UV-based Python build description
README.md # Project runbookSee docs/architecture.md for a detailed deep-dive into the architecture, caching schemes, AI orchestration, guardrails, and lifecycle state workflows.
Getting Started
Prerequisites
Python:
3.12or higher.Terraform CLI: Locally installed and configured.
Redis Server (Optional): Used by
arqfor background queues and real-time catalog caching. Falls back to in-process mock if absent.LLM API Key (Optional): A Groq, OpenAI, or custom API key for the AI Chat Interface.
Setup and Installation
This project is configured using uv for fast, reliable package management.
Install dependencies and create virtual environment:
uv syncActivate virtual environment:
On Windows:
.venv\Scripts\activateOn macOS/Linux:
source .venv/bin/activate
Configure environment variables (create a
.envfile):# LLM Provider (groq, openai, or custom) LLM_PROVIDER=groq LLM_MODEL=llama-3.3-70b-versatile GROQ_API_KEY=your-groq-api-key # Optional: OpenAI # OPENAI_API_KEY=your-openai-key # Optional: Custom/On-Prem (Ollama, vLLM) # LLM_BASE_URL=http://localhost:11434/v1 # LLM_API_KEY=not-needed # Token Optimization (recommended for free-tier APIs) TOKEN_OPTIMIZATION_MODE=true MAX_HISTORY_TURNS=2
Running the Application
1. Run the Web Server
Launch the FastAPI development server:
uv run uvicorn app.main:app --port 8080 --reloadAccess the application:
Interactive UI Dashboard: http://127.0.0.1:8080/
AI Chat Interface: http://127.0.0.1:8080/chat
Swagger API Docs: http://127.0.0.1:8080/docs
2. Run the Background Worker
In a separate terminal, launch the arq worker:
uv run arq app.worker.WorkerSettings(If Redis is not running, the web server falls back to running tasks in-process asynchronously using MockArqRedis, so you do not strictly need to start a separate worker for local testing).
AI Chat Interface
The built-in AI Chat provides a conversational interface for infrastructure management. It supports:
Multi-Provider LLM Support: Groq (free Llama-3.3), OpenAI (GPT-4o), or any OpenAI-compatible endpoint (Ollama, vLLM, LocalAI).
Automatic Tool Calling: The LLM autonomously calls
list_tasks,get_task_schema,provision_task,get_deployment_status,list_deployments, anddestroy_deploymentvia the MCP tool definitions.11 Strict Operational Guardrails: Prevent hallucinated deployments, enforce schema validation before provisioning, resolve deployment-name-to-resource-name references, block dependent resource deletion, and more.
Token-Optimized History: Sliding-window pruning (configurable turns) with tool-result compression for low-TPM APIs.
Dynamic Catalog Awareness: System prompt auto-populates recognized categories and providers from Redis cache at zero latency.
Model Context Protocol (MCP) Setup
This project exposes its tasks and deployments as tools through an MCP server. This allows AI clients (like ChatGPT Desktop, Claude Desktop, or Cursor) to inspect schemas and deploy infrastructure directly.
1. Running Locally (STDIO Mode)
Configure your local AI client to launch the MCP server as a subprocess:
Command:
uvArguments:
run --project "/path/to/project" python "/path/to/project/app/mcp_server.py"
(Note: Ensure the FastAPI web server is also running locally so the MCP server can forward requests to the API endpoints).
2. Running over the Network (SSE Mode)
When you start the FastAPI web server, the MCP server is automatically mounted and exposed via Server-Sent Events (SSE) at:
http://<YOUR_IP_ADDRESS>:8001/mcp/sseOther devices on the same network can connect to this endpoint directly without needing to launch a local Python command.
Running Tests
To run the automated pytest suite (which covers task creation, validation, provisioning, update patches, teardown lifecycles, and dependency blocking):
uv run pytestAll tests execute against an isolated test database test_tasks.db and clean up dynamic execution files automatically.
Available Tools
5 toolsdestroy_deploymentB
Tear down and delete an existing deployment by its name.
Args:
deployment_name: The name of the deployment to destroy.
Inputs: deployment_name (required). Returns: result
get_deployment_statusA
Get the current status, configurations, and outputs of a deployment by its name.
Args:
deployment_name: The unique name of the deployment to inspect.
Inputs: deployment_name (required). Returns: result
get_task_schemaA
Get the metadata and input schema (JSON Schema) for a registered task.
Args:
task_name: The unique alphanumeric name of the task.
Inputs: task_name (required). Returns: result
list_tasksA
List all available Terraform tasks (templates) in the registry.
Args:
category: Optional category to filter tasks (e.g. database, network, compute).
provider: Optional cloud provider to filter tasks (e.g. aws, azure, gcp).
Returns:
JSON string representing the list of tasks and their details.
Inputs: category, provider. Returns: result
provision_taskA
Provision a new deployment for a given task.
Args:
task_name: The registered task name to deploy.
deployment_name: A unique name for this deployment instance.
payload: JSON object/dictionary containing the variables matching the task schema.
Inputs: payload (required), task_name (required), deployment_name (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a clearly distinct purpose: listing tasks, getting task schema, provisioning deployments, checking deployment status, and destroying deployments. No overlap or ambiguity.
All tool names follow a consistent verb_noun pattern with underscores (e.g., list_tasks, provision_task, destroy_deployment), making them predictable and easy to understand.
Five tools is an appropriate scope for managing Terraform tasks and their deployments: sufficient to cover listing, schema retrieval, provisioning, status checking, and destruction without being overwhelming.
The set covers the main lifecycle (create, read, delete) but lacks a tool to list existing deployments, which is a notable gap for agents that need to manage multiple deployments. Additionally, there is no update or modification capability.
Maintenance
Related MCP Connectors
Unified API to query AWS, GCP, Azure and generate Terraform/CLI execution kits for AI agents.
Provides capabilities that let LLM agents perform a range of infrastructure management tasks.
Your AI Agent's Infrastructure Layer. Connect Claude, Copilot, Codex, or ChatGPT to 200+ managed open source services. Start databases, pipelines, and applications through natural language.
Query your team's drift, vulnerability, and upgrade data from any AI assistant. OAuth 2.1, 51 tools.
Related MCP Servers
- 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. ⚡️371MIT
- AlicenseCqualityFmaintenanceEnables AI assistants to manage infrastructure using Ansible and Terraform with 58 tools for playbooks, provisioning, security scanning, and more.877MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that exposes Terraform CLI operations as tools for Claude and other MCP-compatible AI assistants, enabling AI-driven infrastructure-as-code workflows including planning, applying, and validating Terraform configurations.71 npmMIT
- AlicenseNot gradedqualityDmaintenanceExposes any OpenAPI spec endpoints as AI agent tools via stdio, requiring no code generation or maintenance.18MIT