Skip to main content
Glama
severity1

terraform-cloud-mcp

download_state_file

Retrieve Terraform Cloud state files in raw or JSON format for specific state versions to manage infrastructure configuration and track changes.

Instructions

Download the state file content.

Retrieves the raw state file or JSON formatted state file for a specific state version.

API endpoint: Uses the hosted URLs from GET /state-versions/:state_version_id

Args: state_version_id: The ID of the state version (format: "sv-xxxxxxxx") json_format: Whether to download the JSON formatted state (default: False)

Returns: The raw state file content or JSON formatted state content

See: docs/tools/state_versions.md for reference documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
state_version_idYes
json_formatNo

Implementation Reference

  • The main handler function that executes the tool logic: validates input, fetches state version details to get download URL, handles JSON or raw format, and downloads the state file content using api_request.
    async def download_state_file(
        state_version_id: str, json_format: bool = False
    ) -> APIResponse:
        """Download the state file content.
    
        Retrieves the raw state file or JSON formatted state file for a specific state version.
    
        API endpoint: Uses the hosted URLs from GET /state-versions/:state_version_id
    
        Args:
            state_version_id: The ID of the state version (format: "sv-xxxxxxxx")
            json_format: Whether to download the JSON formatted state (default: False)
    
        Returns:
            The raw state file content or JSON formatted state content
    
        See:
            docs/tools/state_versions.md for reference documentation
        """
        # Validate parameters
        params = StateVersionRequest(state_version_id=state_version_id)
    
        # First get state version details to get the download URL
        state_version = await api_request(f"state-versions/{params.state_version_id}")
    
        # Determine which URL to use based on format request
        url_attr = (
            "hosted-json-state-download-url" if json_format else "hosted-state-download-url"
        )
        download_url = state_version.get("data", {}).get("attributes", {}).get(url_attr)
    
        # Check if URL is available
        if not download_url:
            if json_format:
                return {
                    "error": "JSON state download URL not available. This may be because the state was not created with Terraform 1.3+"
                }
            else:
                return {"error": "State download URL not available for this state version"}
    
        # Use the enhanced api_request to fetch state from the external URL
        return await api_request(download_url, external_url=True, accept_text=True)
  • Pydantic model for input validation of state_version_id parameter used in the handler.
    class StateVersionRequest(APIRequest):
        """Request model for retrieving a state version.
    
        Used to validate the state version ID parameter for API requests.
    
        Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/state-versions
    
        See:
            docs/models/state_versions.md for reference
        """
    
        state_version_id: str = Field(
            ...,
            description="The ID of the state version to retrieve",
            pattern=r"^sv-[a-zA-Z0-9]{16}$",  # Standard state version ID pattern
        )
  • Registers the download_state_file tool function with the MCP framework.
    mcp.tool()(state_versions.download_state_file)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions downloading content and API endpoint usage, but lacks critical behavioral details: authentication requirements, rate limits, error handling, or whether it's a read-only operation. The description is insufficient for a mutation-sensitive context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, API endpoint, args, returns, see). It is front-loaded with the core purpose and avoids redundancy. However, the 'See' reference could be integrated more seamlessly, and some sentences are slightly verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 2 parameters, no annotations, and no output schema, the description is moderately complete. It covers parameters and return types but lacks behavioral transparency and usage guidelines. For a download tool in a complex system, more context on permissions, errors, and sibling differentiation would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description compensates well by explaining both parameters: 'state_version_id' as the ID with format 'sv-xxxxxxxx' and 'json_format' as a boolean for JSON formatting with default False. This adds meaningful context beyond the bare schema, though it could detail output implications more.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Download the state file content' and specifies it retrieves raw or JSON formatted state for a specific state version. It uses specific verbs ('download', 'retrieves') and identifies the resource ('state file'), but does not explicitly differentiate from sibling tools like 'get_state_version' or 'get_state_version_output'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions the API endpoint but does not indicate scenarios, prerequisites, or comparisons with sibling tools such as 'get_state_version' or 'list_state_versions'. Usage context is implied but not explicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/severity1/terraform-cloud-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server