The Terraform Registry MCP server provides a Model Context Protocol interface for interacting with the Terraform Registry API, allowing AI agents to query provider information, resource details, and module metadata.
To install and use this MCP server in Cursor:
In Cursor, open Settings (⌘+,) and navigate to the "MCP" tab.
Click "+ Add new MCP server."
Enter the following:
Click "Add" then scroll to the server and click "Disabled" to enable the server.
Restart Cursor, if needed, to ensure the MCP server is properly loaded.
To install and use this MCP server in Claude Desktop:
In Claude Desktop, open Settings (⌘+,) and navigate to the "Developer" tab.
Click "Edit Config" at the bottom of the window.
Edit the config file to add the following code, then Save the file:
{
"mcpServers": {
"terraform-registry": {
"command": "npx",
"args": ["-y", "terraform-mcp-server"]
}
}
}
Tool | Description |
---|---|
providerDetails |
Gets detailed information about a Terraform provider |
resourceUsage |
Gets example usage of a Terraform resource and related resources |
moduleSearch |
Searches for and recommends Terraform modules based on a query |
listDataSources |
Lists all available data sources for a provider and their basic details |
resourceArgumentDetails |
Fetches comprehensive details about a resource type's arguments |
moduleDetails |
Retrieves detailed metadata for a Terraform module |
functionDetails |
Gets details about a Terraform provider function |
providerGuides |
Lists and views provider-specific guides and documentation |
policySearch |
Searches for policy libraries in the Terraform Registry |
policyDetails |
Gets detailed information about a specific policy library |
These tools require a Terraform Cloud API token (TFC_TOKEN
):
Tool | Description |
---|---|
listOrganizations |
Lists all organizations the authenticated user has access to |
privateModuleSearch |
Searches for private modules in an organization |
privateModuleDetails |
Gets detailed information about a private module |
explorerQuery |
Queries the Terraform Cloud Explorer API to analyze data |
listWorkspaces |
Lists workspaces in an organization |
workspaceDetails |
Gets detailed information about a specific workspace |
lockWorkspace |
Locks a workspace to prevent runs |
unlockWorkspace |
Unlocks a workspace to allow runs |
listRuns |
Lists runs for a workspace |
runDetails |
Gets detailed information about a specific run |
createRun |
Creates a new run for a workspace |
applyRun |
Applies a run that's been planned |
cancelRun |
Cancels a run that's in progress |
listWorkspaceResources |
Lists resources in a workspace |
The MCP server supports the following resource URIs:
Resource Type | Example URI(s) |
---|---|
Providers | terraform:providers |
terraform:provider:<namespace>/<name> |
|
Provider Versions | terraform:provider:<namespace>/<name>/versions |
Provider Resources | terraform:provider:<namespace>/<name>/resources |
terraform:resource:<namespace>/<name>/<resource_name> |
|
Provider Data Sources | terraform:provider:<namespace>/<name>/dataSources |
terraform:dataSource:<namespace>/<name>/<data_source_name> |
|
Provider Functions | terraform:provider:<namespace>/<name>/functions |
terraform:function:<namespace>/<name>/<function_name> |
The server provides the following prompts for generating contextual responses:
Prompt | Description | Required Arguments |
---|---|---|
migrate-clouds |
Generate Terraform code to migrate infrastructure between cloud providers | sourceCloud , targetCloud , terraformCode |
generate-resource-skeleton |
Helps users quickly scaffold new Terraform resources with best practices | resourceType |
optimize-terraform-module |
Provides actionable recommendations for improving Terraform code | terraformCode |
migrate-provider-version |
Assists with provider version upgrades and breaking changes | providerName , currentVersion , targetVersion , terraformCode (optional) |
analyze-workspace-runs |
Analyzes recent run failures and provides troubleshooting guidance | workspaceId , runsToAnalyze (optional, default: 5) |
Note: There is a known issue with the getPrompt
functionality that can cause server crashes. The server properly registers prompts and can list them, but direct requests using the getPrompt
method may cause connectivity issues.
The server runs using stdio transport for MCP communication:
npm install
npm start
You can configure the server using these environment variables:
Environment Variable | Description | Default Value |
---|---|---|
TERRAFORM_REGISTRY_URL |
Base URL for Terraform Registry API | https://registry.terraform.io |
DEFAULT_PROVIDER_NAMESPACE |
Default namespace for providers | hashicorp |
LOG_LEVEL |
Logging level (error, warn, info, debug) | info |
REQUEST_TIMEOUT_MS |
Timeout for API requests in milliseconds | 10000 |
RATE_LIMIT_ENABLED |
Enable rate limiting for API requests | false |
RATE_LIMIT_REQUESTS |
Number of requests allowed in time window | 60 |
RATE_LIMIT_WINDOW_MS |
Time window for rate limiting in milliseconds | 60000 |
TFC_TOKEN |
Terraform Cloud API token for private registry access |
Example usage with environment variables:
# Set environment variables
export LOG_LEVEL="debug"
export REQUEST_TIMEOUT_MS="15000"
export TFC_TOKEN="your-terraform-cloud-token"
# Run the server
npm start
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "terraform-registry" '{"command":"npx","args":["-y","terraform-mcp-server"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"terraform-registry": {
"command": "npx",
"args": [
"-y",
"terraform-mcp-server"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"terraform-registry": {
"command": "npx",
"args": [
"-y",
"terraform-mcp-server"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect