$git clone https://github.com/hashicorp/terraform-mcp-serverThe Terraform MCP Server is a Model Context Protocol (MCP) server that provides seamless integration with Terraform Registry APIs, enabling advanced automation and interaction capabilities for Infrastructure as Code (IaC) developmen
| 1 | # <img src="public/images/Terraform-LogoMark_onDark.svg" width="30" align="left" style="margin-right: 12px;"/> Terraform MCP Server |
| 2 | |
| 3 | The Terraform MCP Server is a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) |
| 4 | server that provides seamless integration with Terraform Registry APIs, enabling advanced |
| 5 | automation and interaction capabilities for Infrastructure as Code (IaC) development. |
| 6 | |
| 7 | ## Features |
| 8 | |
| 9 | - **Dual Transport Support**: Both Stdio and StreamableHTTP transports with configurable endpoints |
| 10 | - **Terraform Registry Integration**: Direct integration with public Terraform Registry APIs for providers, modules, and policies |
| 11 | - **HCP Terraform & Terraform Enterprise Support**: Full workspace management, organization/project listing, and private registry access |
| 12 | - **Workspace Operations**: Create, update, delete workspaces with support for variables, tags, and run management |
| 13 | - **OTel metrics for monitoring tool usage**: Integration with open telemetry meters to track tool-call volume, latency and failures in Streamable HTTP mode. Also exposes default http server metrics when this feature is enabled |
| 14 | |
| 15 | |
| 16 | > **Security Note:** Depending on the query, the MCP server may expose certain Terraform data to the MCP client and LLM. Do not use the MCP server with untrusted MCP clients or LLMs. |
| 17 | |
| 18 | > **Legal Note:** Your use of a third party MCP Client/LLM is subject solely to the terms of use for such MCP/LLM, and IBM is not responsible for the performance of such third party tools. IBM expressly disclaims any and all warranties and liability for third party MCP Clients/LLMs, and may not be able to provide support to resolve issues which are caused by the third party tools. |
| 19 | |
| 20 | > **Caution:** The outputs and recommendations provided by the MCP server are generated dynamically and may vary based on the query, model, and the connected MCP client. Users should thoroughly review all outputs/recommendations to ensure they align with their organization’s security best practices, cost-efficiency goals, and compliance requirements before implementation. |
| 21 | |
| 22 | ## Prerequisites |
| 23 | |
| 24 | 1. Ensure [Docker](https://www.docker.com/) is installed and running to use the server in a containerized environment. |
| 25 | 1. Install an AI assistant that supports the Model Context Protocol (MCP). |
| 26 | |
| 27 | ## Command Line Options |
| 28 | |
| 29 | **Environment Variables:** |
| 30 | |
| 31 | | Variable | Description | Default | |
| 32 | |----------|-------------|---------| |
| 33 | | `TFE_ADDRESS` | Sets the Terraform Enterprise/HCP Terraform address for API calls. Must include the protocol (e.g., `https://app.terraform.io`). In streamable-http mode this is the only way to set the address; it cannot be supplied by clients via header or query parameter. | Optional | |
| 34 | | `TFE_TOKEN` | Terraform Enterprise API token | `""` (empty) | |
| 35 | | `TF_MCP_SHARED_SECRET` | Shared secret sent as the `X-Tf-Mcp-Secret` header on requests to HCP Terraform / TFE, used to identify requests originating from a hosted MCP deployment. Should only be used over TLS. | `""` (empty) | |
| 36 | | `TFE_SKIP_TLS_VERIFY` | Skip HCP Terraform or Terraform Enterprise TLS verification | `false` | |
| 37 | | `LOG_LEVEL` | Logging level: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic` (overrides `--log-level` flag) | `info` | |
| 38 | | `LOG_FORMAT` | Logging format: `text` or `json` (overrides `--log-format` flag)| `text` | |
| 39 | | `TRANSPORT_MODE` | Set to `streamable-http` to enable HTTP transport (legacy `http` value still supported) | `stdio` | |
| 40 | | `TRANSPORT_HOST` | Host to bind the HTTP server | `127.0.0.1` | |
| 41 | | `TRANSPORT_PORT` | HTTP server port | `8080` | |
| 42 | | `MCP_ENDPOINT` | HTTP server endpoint path | `/mcp` | |
| 43 | | `MCP_REDIRECT_ROOT_URL` | URL to redirect requests to `/` to | `""` | |
| 44 | | `MCP_KEEP_ALIVE` | Keep-alive interval for SSE connections (e.g., 30s, 1m). 0 to disable | `0` | |
| 45 | | `MCP_SESSION_MODE` | Session mode: `stateful` or `stateless` | `stateful` | |
| 46 | | `MCP_ALLOWED_ORIGINS` | Comma-separated list of allowed origins for CORS | `""` (empty) | |
| 47 | | `MCP_CORS_MODE` | CORS mode: `str |