Terraform
Deploy the Terraform MCP server
The Terraform MCP (Model Context Protocol) server runs in a Docker container that you can deploy to either your local workstation or a remote instance. When running the server locally, start it in the default stdio
mode. In this mode, the server communicates over standard input/output. When running the server on a remote instance, start the server in streamable-http
mode so that you can communicate with the server using the Streamable HTTP transport.
Note
This feature is currently in beta. Do not use beta functionality in production environments.
Overview
Complete the following steps to deploy the server.
Standard IO transport
- Enable MCP in your client
- Install the server
- Configure your client
Streamable HTTP transport
- Configure environment variables
- Build the Docker image
- Configure your client
- Start the server
Requirements
One of the following Docker distributions is required:
- Docker Engine v20.10.21+
- Docker Desktop v4.14.0+
Refer to the Docker documentation for installation instructions.
The following MCP clients are supported:
- VS Code with CoPilot. Refer to the VS Code documentation for installation instructions.
- Cursor. Refer to the Cursor website for more information.
- Anthropic Claude Desktop. Refer to the Anthropic Claude Desktop documentation for installation instructions.
Enable MCP in your client
Refer to your client's documentation for instructions on enabling MCP:
Install the server
You can install the server using the following methods if you intend to run the server locally:
- Install the binary into your client. The binaries are available at releases.hashicorp.com.
- Install from source into your client.
For remote installations, download the source to the remote and build the Docker image.
Compiled binary
Refer to Requirements for supported clients.
To install the server so that it's available for all workspaces, add the following JSON block to your user setting JSON file:
{
"mcp": {
"servers": {
"terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server"
]
}
}
}
}
Alternatively, you can install the server in specific workspaces. Create an mcp.json
file in the .vscode
directory of your workspace and add the following JSON block:
{
"servers": {
"terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server"
]
}
}
}
Start or restart Docker to start the container using the standard transport.
Install from source
You can pull the source from either the latest
release version or pull from the main
branch to install from source.
Latest:
$ go install github.com/hashicorp/terraform-mcp-server/cmd/terraform-mcp-server@latest
Main:
$ go install github.com/hashicorp/terraform-mcp-server/cmd/terraform-mcp-server@main
After pulling the image, add the following JSON block to your client and specify the path to the server binary in the command
attribute:
{
"mcp": {
"servers": {
"terraform": {
"command": "/path/to/terraform-mcp-server",
"args": ["stdio"]
}
}
}
}
Start or restart Docker to start the container using the standard transport.
Configure environment variables
If you intend to run the MCP server on a remote instance, log into the remote machine and specify the following environment variables:
Variable | Description | Default |
---|---|---|
TRANSPORT_MODE | Set to streamable-http to enable HTTP transport | stdio |
TRANSPORT_HOST | Host to bind the HTTP server | 0.0.0.0 |
TRANSPORT_PORT | HTTP server port | 8080 |
Build the Docker image
You can download the source to your local machine or to a remote instance and build the server locally.
- Clone the repository:
git clone https://github.com/hashicorp/terraform-mcp-server.git
cd terraform-mcp-server
- Build the Docker image:
make docker-build
Use the image to run the server in stdio
mode or to run it in streamable-http
mode:
stdio
mode:
$ docker run -i --rm terraform-mcp-server:dev
streamable-http
mode:
$ docker run -p 8080:8080 --rm -e MODE=streamabe-http terraform-mcp-server:dev
Configure your MCP client
Complete the following steps if you are using Copilot in VS Code:
- Open the chat interface and choose Agent from the mode settings.
- Click the tools icon to verify that the Terraform MCP server tools are enabled.
Complete the following steps if you are using Cursor:
- Open the chat pane and choose Chat Settings from the ellipses menu.
- Choose Agent from the Default new chat mode** drop-down menu.
- Choose MCP from the Cursor Settings sidebar to verify that the Terraform MCP server tools are enabled.
Complete the following steps if you are using Claude Desktop:
- Open the chat pane and choose the search and tools slider icon to the bottom left of the chat pane.
- Click terraform-mcp-server to verify that all the tools are enabled.
Next steps
After downloading the Terraform MCP server and connecting it to your client, you can begin prompting your model about your Terraform configuration code. Refer to Prompt an AI model for more information.