by hashicorp
Provides seamless integration with the Terraform ecosystem, enabling advanced automation and interaction capabilities for Infrastructure as Code (IaC) development via Model Context Protocol.
Enables Model Context Protocol (MCP)‑based interaction with Terraform Registry APIs, allowing AI‑assisted tooling to search providers, retrieve module documentation, and query Sentinel policies directly from a local or containerized server.
docker run -i --rm hashicorp/terraform-mcp-server
for stdio mode or add -p 8080:8080 -e TRANSPORT_MODE=streamable-http -e TRANSPORT_HOST=0.0.0.0
for HTTP mode.go install github.com/hashicorp/terraform-mcp-server/cmd/terraform-mcp-server@latest
and run terraform-mcp-server stdio
or terraform-mcp-server streamable-http
.terraform-mcp-server stdio [--log-file /path/to/log]
– communicates via JSON‑RPC over stdin/stdout.terraform-mcp-server streamable-http [--transport-port 8080] [--transport-host 127.0.0.1]
– exposes /mcp
endpoint and health check at /health
.TRANSPORT_MODE
, TRANSPORT_HOST
, TRANSPORT_PORT
, MCP_SESSION_MODE
, MCP_ALLOWED_ORIGINS
, and MCP_CORS_MODE
to tune transport and security.settings.json
or .vscode/mcp.json
using the Docker command shown in the README.make docker-build
workflow.MCP_ALLOWED_ORIGINS
and MCP_CORS_MODE
.Q: Do I need Docker to run the server? A: Docker is the easiest way, but you can also build and run the Go binary locally.
Q: Which transport should I use? A: Use Stdio for local development or when the client runs in the same process. Use Streamable‑HTTP for remote or distributed setups.
Q: How do I restrict access when using HTTP mode?
A: Set MCP_ALLOWED_ORIGINS
to a comma‑separated list of trusted origins and keep MCP_CORS_MODE
set to strict
.
Q: What is the difference between stateful and stateless sessions? A: Stateful retains context between requests (useful for conversational AI), while stateless processes each request independently, aiding scalability behind load balancers.
Q: How can I test the HTTP endpoint?
A: After starting the server in HTTP mode, run curl http://localhost:8080/health
– you should receive a 200 response.
The 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) development.
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 server. 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.
Security Note: When using the StreamableHTTP transport in production, always configure the
MCP_ALLOWED_ORIGINS
environment variable to restrict access to trusted origins only. This helps prevent DNS rebinding attacks and other cross-origin vulnerabilities.
The Terraform MCP Server supports multiple transport protocols:
Standard input/output communication using JSON-RPC messages. Ideal for local development and direct integration with MCP clients.
Modern HTTP-based transport supporting both direct HTTP requests and Server-Sent Events (SSE) streams. This is the recommended transport for remote/distributed setups.
Features:
http://{hostname}:8080/mcp
http://{hostname}:8080/health
TRANSPORT_MODE=http
or TRANSPORT_PORT=8080
to enableEnvironment Variables:
Variable | Description | Default |
---|---|---|
TRANSPORT_MODE |
Set to streamable-http to enable HTTP transport (legacy http value still supported) |
stdio |
TRANSPORT_HOST |
Host to bind the HTTP server | 127.0.0.1 |
TRANSPORT_PORT |
HTTP server port | 8080 |
MCP_ENDPOINT |
HTTP server endpoint path | /mcp |
MCP_SESSION_MODE |
Session mode: stateful or stateless |
stateful |
MCP_ALLOWED_ORIGINS |
Comma-separated list of allowed origins for CORS | "" (empty) |
MCP_CORS_MODE |
CORS mode: strict , development , or disabled |
strict |
# Stdio mode
terraform-mcp-server stdio [--log-file /path/to/log]
# StreamableHTTP mode
terraform-mcp-server streamable-http [--transport-port 8080] [--transport-host 127.0.0.1] [--mcp-endpoint /mcp] [--log-file /path/to/log]
The Terraform MCP Server supports two session modes when using the StreamableHTTP transport:
To enable stateless mode, set the environment variable:
export MCP_SESSION_MODE=stateless
Add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P
and typing Preferences: Open User Settings (JSON)
.
More about using MCP server tools in VS Code's agent mode documentation.
{
"mcp": {
"servers": {
"terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server"
]
}
}
}
}
Optionally, you can add a similar example (i.e. without the mcp key) to a file called .vscode/mcp.json
in your workspace. This will allow you to share the configuration with others.
{
"servers": {
"terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server"
]
}
}
}
More about using MCP server tools in Claude Desktop user documentation. Read more about using MCP server in Amazon Q from the documentation.
{
"mcpServers": {
"terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server"
]
}
}
}
The following sets of tools are available for the public Terraform registry:
Toolset | Tool | Description |
---|---|---|
providers |
search_providers |
Queries the Terraform Registry to find and list available documentation for a specific provider using the specified service_slug . Returns a list of provider document IDs with their titles and categories for resources, data sources, functions, or guides. |
providers |
get_provider_details |
Fetches the complete documentation content for a specific provider resource, data source, or function using a document ID obtained from the search_providers tool. Returns the raw documentation in markdown format. |
providers |
get_latest_provider_version |
Fetches the complete documentation content for a specific provider resource, data source, or function using a document ID obtained from the search_providers tool. Returns the raw documentation in markdown format. |
modules |
search_modules |
Searches the Terraform Registry for modules based on specified module_query with pagination. Returns a list of module IDs with their names, descriptions, download counts, verification status, and publish dates |
modules |
get_module_details |
Retrieves detailed documentation for a module using a module ID obtained from the search_modules tool including inputs, outputs, configuration, submodules, and examples. |
modules |
get_latest_module_version |
Retrieves detailed documentation for a module using a module ID obtained from the search_modules tool including inputs, outputs, configuration, submodules, and examples. |
policies |
search_policies |
Queries the Terraform Registry to find and list the appropriate Sentinel Policy based on the provided query policy_query . Returns a list of matching policies with terraform_policy_id(s) with their name, title and download counts. |
policies |
get_policy_details |
Retrieves detailed documentation for a policy set using a terraform_policy_id obtained from the search_policies tool including policy readme and implementation details. |
The following sets of tools are available for HCP Terraform or Terraform Enterprise:
Toolset | Tool | Description |
---|---|---|
orgs |
list_organizations |
Lists all Terraform organizations accessible to the authenticated user. |
projects |
list_projects |
Lists all projects within a specified Terraform organization. |
Resource URI | Description |
---|---|
/terraform/style-guide |
Terraform Style Guide - Provides access to the official Terraform style guide documentation in markdown format |
/terraform/module-development |
Terraform Module Development Guide - Comprehensive guide covering module composition, structure, providers, publishing, and refactoring best practices |
Resouce Template URI | Description |
---|---|
/terraform/providers/{namespace}/name/{name}/version/{version} |
Provider Resource Template - Dynamically retrieves detailed documentation and overview for any Terraform provider by namespace, name, and version |
Use the latest release version:
go install github.com/hashicorp/terraform-mcp-server/cmd/terraform-mcp-server@latest
Use the main branch:
go install github.com/hashicorp/terraform-mcp-server/cmd/terraform-mcp-server@main
{
"mcp": {
"servers": {
"terraform": {
"command": "/path/to/terraform-mcp-server",
"args": ["stdio"]
}
}
}
}
Before using the server, you need to build the Docker image locally:
git clone https://github.com/hashicorp/terraform-mcp-server.git
cd terraform-mcp-server
make docker-build
# Run in stdio mode
docker run -i --rm terraform-mcp-server:dev
# Run in streamable-http mode
docker run -p 8080:8080 --rm -e TRANSPORT_MODE=streamable-http -e TRANSPORT_HOST=0.0.0.0 terraform-mcp-server:dev
Note: When running in Docker, you should set
TRANSPORT_HOST=0.0.0.0
to allow connections from outside the container.
# Test the connection
curl http://localhost:8080/health
{
"mcpServers": {
"terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"terraform-mcp-server:dev"
]
}
}
}
Command | Description |
---|---|
make build |
Build the binary |
make test |
Run all tests |
make test-e2e |
Run end-to-end tests |
make docker-build |
Build Docker image |
make run-http |
Run HTTP server locally |
make docker-run-http |
Run HTTP server in Docker |
make test-http |
Test HTTP health endpoint |
make clean |
Remove build artifacts |
make help |
Show all available commands |
This project is licensed under the terms of the MPL-2.0 open source license. Please refer to LICENSE file for the full terms.
For security issues, please contact security@hashicorp.com or follow our security policy.
For bug reports and feature requests, please open an issue on GitHub.
For general questions and discussions, open a GitHub Discussion.
Please log in to share your review and rating for this MCP.
Discover more MCP servers with similar functionality and use cases
by zed-industries
Provides real-time collaborative editing powered by Rust, enabling developers to edit code instantly across machines with a responsive, GPU-accelerated UI.
by cline
Provides autonomous coding assistance directly in the IDE, enabling file creation, editing, terminal command execution, browser interactions, and tool extension with user approval at each step.
by continuedev
Provides continuous AI assistance across IDEs, terminals, and CI pipelines, offering agents, chat, inline editing, and autocomplete to accelerate software development.
by github
Enables AI agents, assistants, and chatbots to interact with GitHub via natural‑language commands, providing read‑write access to repositories, issues, pull requests, workflows, security data and team activity.
by block
Automates engineering tasks by installing, executing, editing, and testing code using any large language model, providing end‑to‑end project building, debugging, workflow orchestration, and external API interaction.
by RooCodeInc
An autonomous coding agent that lives inside VS Code, capable of generating, refactoring, debugging code, managing files, running terminal commands, controlling a browser, and adapting its behavior through custom modes and instructions.
by lastmile-ai
A lightweight, composable framework for building AI agents using Model Context Protocol and simple workflow patterns.
by firebase
Provides a command‑line interface to manage, test, and deploy Firebase projects, covering hosting, databases, authentication, cloud functions, extensions, and CI/CD workflows.
by gptme
Empowers large language models to act as personal AI assistants directly inside the terminal, providing capabilities such as code execution, file manipulation, web browsing, vision, and interactive tool usage.