Skip to main content
Glama
severity1

terraform-cloud-mcp

list_state_versions

Retrieve and filter state versions from a Terraform Cloud workspace to track infrastructure changes and manage configuration history.

Instructions

List state versions in a workspace.

Retrieves a paginated list of all state versions in a Terraform Cloud workspace. Results can be filtered using status to find specific state versions.

API endpoint: GET /state-versions

Args: organization: The name of the organization that owns the workspace workspace_name: The name of the workspace to list state versions from page_number: The page number to return (default: 1) page_size: The number of items per page (default: 20, max: 100) filter_status: Filter state versions by status: 'pending', 'finalized', or 'discarded'

Returns: Paginated list of state versions with their configuration settings and metadata

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
organizationYes
workspace_nameYes
page_numberNo
page_sizeNo
filter_statusNo

Implementation Reference

  • The core handler function implementing the list_state_versions tool. It validates inputs using Pydantic models, converts filter status to enum, builds query parameters, and makes the API request to list state versions.
    @handle_api_errors
    async def list_state_versions(
        organization: str,
        workspace_name: str,
        page_number: int = 1,
        page_size: int = 20,
        filter_status: Optional[str] = None,
    ) -> APIResponse:
        """List state versions in a workspace.
    
        Retrieves a paginated list of all state versions in a Terraform Cloud workspace.
        Results can be filtered using status to find specific state versions.
    
        API endpoint: GET /state-versions
    
        Args:
            organization: The name of the organization that owns the workspace
            workspace_name: The name of the workspace to list state versions from
            page_number: The page number to return (default: 1)
            page_size: The number of items per page (default: 20, max: 100)
            filter_status: Filter state versions by status: 'pending', 'finalized', or 'discarded'
    
        Returns:
            Paginated list of state versions with their configuration settings and metadata
    
        See:
            docs/tools/state_versions.md for reference documentation
        """
        # Convert filter_status string to enum if provided
        status_enum = None
        if filter_status:
            try:
                status_enum = StateVersionStatus(filter_status)
            except ValueError:
                valid_values = ", ".join([s.value for s in StateVersionStatus])
                raise ValueError(
                    f"Invalid filter_status value: {filter_status}. Valid values: {valid_values}"
                )
    
        # Validate parameters
        params = StateVersionListRequest(
            filter_workspace_name=workspace_name,
            filter_organization_name=organization,
            page_number=page_number,
            page_size=page_size,
            filter_status=status_enum,
        )
    
        # Build query parameters using utility function
        query = query_params(params)
    
        # Make API request
        return await api_request("state-versions", params=query)
  • Pydantic schema/model for input parameters to the list_state_versions tool, defining validation for organization/workspace filters, pagination, and status filtering.
    class StateVersionListRequest(APIRequest):
        """Request parameters for listing state versions.
    
        Defines the parameters for the state version listing API including pagination
        and filtering options.
    
        Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/state-versions#list-state-versions
    
        See:
            docs/models/state_versions.md for reference
        """
    
        filter_workspace_name: Optional[str] = Field(
            None,
            description="Filter by workspace name",
        )
        filter_organization_name: Optional[str] = Field(
            None,
            description="Filter by organization name",
        )
        filter_status: Optional[StateVersionStatus] = Field(
            None,
            description="Filter state versions by status",
        )
        page_number: Optional[int] = Field(
            1,
            ge=1,
            description="Page number to fetch",
        )
        page_size: Optional[int] = Field(
            20,
            ge=1,
            le=100,
            description="Number of results per page",
        )
  • Registration of the list_state_versions tool in the MCP server using the FastMCP decorator.
    mcp.tool()(state_versions.list_state_versions)
  • Enum schema defining possible status values for filtering state versions in the list_state_versions tool.
    class StateVersionStatus(str, Enum):
        """Status options for state versions in Terraform Cloud.
    
        Defines the various states a state version can be in during its lifecycle:
        - PENDING: State version has been created but state data is not encoded within the request
        - FINALIZED: State version has been successfully uploaded or created with valid state attribute
        - DISCARDED: State version was discarded because it was superseded by a newer version
        - BACKING_DATA_SOFT_DELETED: Enterprise only - backing files are marked for garbage collection
        - BACKING_DATA_PERMANENTLY_DELETED: Enterprise only - backing files have been permanently deleted
    
        Reference: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/state-versions#state-version-status
    
        See:
            docs/models/state_versions.md for reference
        """
    
        PENDING = "pending"
        FINALIZED = "finalized"
        DISCARDED = "discarded"
        BACKING_DATA_SOFT_DELETED = "backing_data_soft_deleted"
        BACKING_DATA_PERMANENTLY_DELETED = "backing_data_permanently_deleted"
  • Import of the state_versions module containing the list_state_versions handler for registration.
    from terraform_cloud_mcp.tools import state_versions
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: pagination behavior, filtering capability, and the fact it retrieves configuration settings and metadata. However, it doesn't mention authentication requirements, rate limits, error conditions, or whether this is a read-only operation (though 'List' implies it).

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?

Well-structured with purpose statement, behavioral details, parameter explanations, and return value description in logical sections. The 'See' reference could be omitted for pure conciseness, but overall it's efficiently organized with minimal fluff.

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

Completeness4/5

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

For a 5-parameter list tool with no annotations and no output schema, the description provides good coverage: purpose, behavior, all parameters with semantics, and return format. It could improve by mentioning authentication or linking to sibling tools more explicitly, but it's largely complete for the agent's needs.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by explaining all 5 parameters in the 'Args' section with clear semantics: what each parameter represents, defaults for page_number and page_size, constraints (max: 100), and valid values for filter_status. This adds significant value beyond the bare schema.

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

Purpose5/5

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

The description clearly states the specific action ('List state versions'), resource ('in a workspace'), and scope ('Retrieves a paginated list of all state versions in a Terraform Cloud workspace'). It distinguishes from sibling tools like 'get_state_version' (singular) and 'get_current_state_version' (specific version).

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('to find specific state versions' via filtering) and mentions the API endpoint. However, it doesn't explicitly state when NOT to use it or name specific alternatives among sibling tools like 'get_state_version' for retrieving a single version.

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