This MCP server provides tools for interacting with the Terraform Registry API, allowing AI agents to query provider information, resource details, and module metadata through the Model Context Protocol.
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 file (~/Library/Application Support/Claude/claude_desktop_config.json
) to add the following code, then Save the file:
{
"mcpServers": {
"terraform-registry": {
"command": "npx",
"args": ["-y", "terraform-mcp-server"]
}
}
}
The MCP server provides several tools for interacting with the Terraform Registry:
These tools require a Terraform Cloud API token (TFC_TOKEN
):
The MCP server supports the following resource URIs for listing and reading via the resources/*
methods:
terraform:providers
- List all namespaces/providersterraform:provider:<namespace>/<name>
- Get details for a specific providerterraform:provider:<namespace>/<name>/versions
- List available versions for a providerterraform:provider:<namespace>/<name>/resources
- List resources for a providerterraform:resource:<namespace>/<name>/<resource_name>
- Get details for a specific resource typeterraform:provider:<namespace>/<name>/dataSources
- List data sources for a providerterraform:dataSource:<namespace>/<name>/<data_source_name>
- Get details for a specific data sourceterraform:provider:<namespace>/<name>/functions
- List functions for a providerterraform:function:<namespace>/<name>/<function_name>
- Get details for a specific functionThe server also supports resources/templates/list
to provide templates for creating:
terraform:provider
terraform:resource
terraform:dataSource
The following prompts are available for generating contextual responses:
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)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 can be configured using 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 |
# Set environment variables
export LOG_LEVEL="debug"
export REQUEST_TIMEOUT_MS="15000"
export TFC_TOKEN="your-terraform-cloud-token"
# Run the server
npm start
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 > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.