Skip to content

Docs/add mcp server docs #907

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion website/data/docs-nav-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@
"title": "Integration Program",
"path": "partnerships"
},
{ "title": "Terraform Tools", "path": "terraform-tools" },
{
"title": "Terraform Tools",
"routes": [
{
"title": "Overview",
"path": "tools"
},
{
"title": "Terraform MCP server",
"badge": {
"text": "BETA",
"type": "outlined",
"color": "neutral"
},
"routes": [
{
"title": "Overview",
"path": "tools/mcp-server"
},
{
"title": "Deploy server",
"path": "tools/mcp-server/deploy"
},
{
"title": "Prompt model",
"path": "tools/mcp-server/prompt"
}
]
}
]
},
{ "title": "Glossary", "path": "glossary" }
]
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Terraform is part of a rich infrastructure and DevOps ecosystem. The tools below
|[Visual Studio Code Extension](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform) | HashiCorp | Enable syntax highlighting and other editing features in VS Code using the Terraform Language Server.| |
|[Language Server](https://github.com/hashicorp/terraform-ls) | HashiCorp | Add support for the Terraform configuration language to editors that use the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/), like Sublime Text, vim, emacs, etc.| |
|[console](/terraform/cli/commands/console) | HashiCorp | Evaluate Terraform expressions and explore your Terraform project's state. The console helps you develop and debug your configuration, especially when working with complex state data and Terraform expressions.| [Develop Configuration with the Console](/terraform/tutorials/cli/console) |
| [Terraform MCP server](/terraform/docs/tools/mcp-server) | HashiCorp | Helps you use an AI or LLM to write Terraform configuration by retrieving data directly from the Terraform registry. | |


## Manage Infrastructure
Expand Down
103 changes: 103 additions & 0 deletions website/docs/docs/tools/mcp-server/deploy.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
page_title: Deploy the Terraform model context protocol (MCP) server
description: |-
Learn how to deploy the Terraform MCP server, which helps you write configuration using LLM responses sourced from the Terraform registry.
---

# Deploy the Terraform MCP server

This topic describes how to deploy the Terraform model context protocol (MCP) server in a Docker container on your local workstation. The Terraform MCP server connects to a client so that your LLM can use data stored in the Terraform registry to help you write Terraform configuration. Refer to the [overview](/terraform/docs/terraform-tools/mcp-server) for additional information about the Terraform MCP server.

## Overview

Complete the following steps to deploy the Terraform MCP server:

1. Pull the Docker image
1. Connect your client to the MCP server
1. Configure your client

## Requirements

One of the following Docker distributions is required:

- Docker Engine v20.10.21+
- Docker Desktop v4.14.0+

Refer to the [Docker documentation](https://docs.docker.com/desktop) for installation instructions.

The following MCP clients are supported:

- VS Code with CoPilot. Refer to the [VS Code documentation](https://code.visualstudio.com/docs) for installation instructions.
- Cursor. Refer to the [Cursor website](https://www.cursor.com) for more information.
- Anthropic Claude Desktop. Refer to the [Anthropic Claude Desktop documentation](https://support.anthropic.com/en/articles/10065433-installing-claude-for-desktop) for installation instructions.

## Enable MCP in your client

Refer to your client's documentation for instructions on enabling MCP:

- [VS Code](https://code.visualstudio.com/docs/copilot/chat/mcp-servers)
- [Cursor](https://docs.cursor.com/context/model-context-protocol#configuring-mcp-servers)
- [Anthropic Claude Desktop](https://modelcontextprotocol.io/quickstart/user)

## Install the server

For VS Code, create an `mcp.json` file in the `.vscode` or `.cursor` directory of your local workspace and add the following configuration:

```json
{
"servers": {
"terraform-mcp-server": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server:0.1.0"
]
}
}
}
```

For Claude Desktop MCP clients, create an `mcp.json` file and add the following configuration:

```json
{
"mcpServers": {
"servers": {
"hcp-terraform": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"hashicorp/terraform-mcp-server:0.1.0"
]
}
}
}
}
```


## Configure your MCP client

Complete the following steps if you are using Copilot in VS Code:

1. Open the chat interface and choose **Agent** from the mode settings.
1. Click the tools icon to verify that the Terraform MCP server tools are enabled.

Complete the following steps if you are using Cursor:

1. Open the chat pane and choose **Chat Settings** from the ellipses menu.
1. Choose **Agent from the **Default new chat mode** drop-down menu.
1. 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:

1. Open the chat pane and choose the **search and tools** slider icon to the bottom left of the chat pane.
1. 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](/terraform/docs/tools/mcp-server/prompt) for more information.
30 changes: 30 additions & 0 deletions website/docs/docs/tools/mcp-server/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
page_title: Terraform MCP server overview
description: Learn about the Terraform model context protocol (MCP) server and how it can help you write Terraform configuration using AI.
---

# Terraform MCP server overview

This topic provides an overview of the Terraform model context protocol (MCP) server, which helps you write Terraform configuration using an AI or LLM. The server requests information directly from the Terraform registry so that your model can formulate responses using provider code and documentation as the source of truth.

## Introduction

MCP standardizes how AI models can discover and interact with external tools, applications, and data sources. You can configure MCP clients, such as an AI or LLM chat, to send requests through an MCP server so that the model can provide answers to prompts that it may not have been trained on. Refer to the [MCP documentation](https://modelcontextprotocol.io/introduction) for details about how MCP works.

You can configure your AI model to connect to the Terraform MCP server so that it can request information about providers, modules, and other objects from data stored in the Terraform registry. When the Terraform MCP is available to your AI client, the model retrieves information from the most up-to-date source code stored in the registry, instead of relying on outdated training data. As a result, you can get more accurate and actionable information.

Note that to use the server, your questions must pertain to provider configuration from the registry. The LLM uses other sources, such as content from the internet, to respond to general questions about Terraform configuration or requests to generate code.

## Workflow

- [Deploy the Terraform MCP server](/terraform/docs/tools/mcp-server/deploy)
- [Prompt your model](/terraform//docs/tools/mcp-server/prompt)

## Terraform MCP server tools

The Terraform MCP server runs in a Docker container on your local workstation and exposes functionality to clients using tools. The Terraform MCP server includes a set of tools that retrieve different types of information from the Terraform registry:

- `resolveProviderDocID`: Queries the Terraform Registry to find and list available documentation for a specific provider. This tool uses `serviceSlug` to return a list of provider document IDs with their titles and categories for resources, data sources, functions, or guides.
- `getProviderDocs`: Fetches the complete documentation content for a specific provider resource, data source, or function using a document ID obtained from the `resolveProviderDocID` tool. Returns the raw documentation in markdown format.
- `searchModules`: Searches the Terraform Registry for modules based on the specified `moduleQuery` with pagination. Returns a list of module IDs with their names, descriptions, download counts, verification status, and publish dates.
- `moduleDetails`: Retrieves detailed documentation for a module using a module ID obtained from the `searchModules` tool, including inputs, outputs, configuration, submodules, and examples.
Loading