Skip to main content
Glama
matchs

Terraform Cloud MCP Server

by matchs

Get Run Status

get_run_status

Check the current status of Terraform Cloud workspace runs to monitor infrastructure deployment progress and identify issues.

Instructions

Get the current run status for a Terraform Cloud workspace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspaceNameYesWorkspace name
organizationNoOrganization nameurbanmedia

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
recentRunsYes
workspaceIdYes
currentRunIdNo
workspaceNameYes
currentRunStatusNo

Implementation Reference

  • The handler function that implements the logic for the 'get_run_status' tool, fetching workspace details, current run status, and recent runs from the Terraform Cloud API.
    async ({ workspaceName, organization }) => {
      try {
        // Get workspace details
        const workspaceData = await tfCloudRequest(`/organizations/${organization}/workspaces/${workspaceName}`);
        const workspaceId = workspaceData.data.id;
        
        // Get current run if exists
        const currentRunData = workspaceData.data.relationships['current-run']?.data;
        let currentRunId: string | undefined;
        let currentRunStatus: string | undefined;
    
        if (currentRunData?.id) {
          currentRunId = currentRunData.id;
          const runData = await tfCloudRequest(`/runs/${currentRunId}`);
          currentRunStatus = runData.data.attributes.status;
        }
    
        // Get recent runs
        const runsData = await tfCloudRequest(`/workspaces/${workspaceId}/runs?page[size]=5`);
        const recentRuns = runsData.data.map((run: any) => ({
          id: run.id,
          status: run.attributes.status,
          createdAt: run.attributes['created-at'],
          message: run.attributes.message || 'No message'
        }));
    
        const output = {
          workspaceId,
          workspaceName,
          currentRunId,
          currentRunStatus,
          recentRuns
        };
    
        return {
          content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
          structuredContent: output
        };
      } catch (error) {
        const errorMsg = error instanceof Error ? error.message : String(error);
        return {
          content: [{ type: 'text', text: `Error: ${errorMsg}` }],
          isError: true
        };
      }
    }
  • Input and output schema definitions, including Zod validators, for the 'get_run_status' tool.
      title: 'Get Run Status',
      description: 'Get the current run status for a Terraform Cloud workspace',
      inputSchema: {
        workspaceName: z.string().describe('Workspace name'),
        organization: z.string().default('urbanmedia').describe('Organization name')
      },
      outputSchema: {
        workspaceId: z.string(),
        workspaceName: z.string(),
        currentRunId: z.string().optional(),
        currentRunStatus: z.string().optional(),
        recentRuns: z.array(z.object({
          id: z.string(),
          status: z.string(),
          createdAt: z.string(),
          message: z.string()
        }))
      }
    },
  • src/index.ts:48-116 (registration)
    Registration of the 'get_run_status' tool using server.registerTool, including name, schema, and handler function.
    server.registerTool(
      'get_run_status',
      {
        title: 'Get Run Status',
        description: 'Get the current run status for a Terraform Cloud workspace',
        inputSchema: {
          workspaceName: z.string().describe('Workspace name'),
          organization: z.string().default('urbanmedia').describe('Organization name')
        },
        outputSchema: {
          workspaceId: z.string(),
          workspaceName: z.string(),
          currentRunId: z.string().optional(),
          currentRunStatus: z.string().optional(),
          recentRuns: z.array(z.object({
            id: z.string(),
            status: z.string(),
            createdAt: z.string(),
            message: z.string()
          }))
        }
      },
      async ({ workspaceName, organization }) => {
        try {
          // Get workspace details
          const workspaceData = await tfCloudRequest(`/organizations/${organization}/workspaces/${workspaceName}`);
          const workspaceId = workspaceData.data.id;
          
          // Get current run if exists
          const currentRunData = workspaceData.data.relationships['current-run']?.data;
          let currentRunId: string | undefined;
          let currentRunStatus: string | undefined;
    
          if (currentRunData?.id) {
            currentRunId = currentRunData.id;
            const runData = await tfCloudRequest(`/runs/${currentRunId}`);
            currentRunStatus = runData.data.attributes.status;
          }
    
          // Get recent runs
          const runsData = await tfCloudRequest(`/workspaces/${workspaceId}/runs?page[size]=5`);
          const recentRuns = runsData.data.map((run: any) => ({
            id: run.id,
            status: run.attributes.status,
            createdAt: run.attributes['created-at'],
            message: run.attributes.message || 'No message'
          }));
    
          const output = {
            workspaceId,
            workspaceName,
            currentRunId,
            currentRunStatus,
            recentRuns
          };
    
          return {
            content: [{ type: 'text', text: JSON.stringify(output, null, 2) }],
            structuredContent: output
          };
        } catch (error) {
          const errorMsg = error instanceof Error ? error.message : String(error);
          return {
            content: [{ type: 'text', text: `Error: ${errorMsg}` }],
            isError: true
          };
        }
      }
    );
  • Helper function to make authenticated API requests to Terraform Cloud, heavily used in the tool handler.
    async function tfCloudRequest(endpoint: string): Promise<any> {
      const token = getTerraformToken();
      const response = await fetch(`${TF_API_BASE}${endpoint}`, {
        headers: {
          'Authorization': `Bearer ${token}`,
          'Content-Type': 'application/vnd.api+json'
        }
      });
    
      if (!response.ok) {
        throw new Error(`Terraform Cloud API error: ${response.statusText}`);
      }
    
      return response.json();
    }
  • Helper function to retrieve the Terraform Cloud API token from the user's credentials file, used by tfCloudRequest.
    function getTerraformToken(): string {
      const credentialsPath = join(homedir(), '.terraform.d', 'credentials.tfrc.json');
      try {
        const credentials = JSON.parse(readFileSync(credentialsPath, 'utf-8'));
        return credentials.credentials['app.terraform.io'].token;
      } catch (error) {
        throw new Error('Failed to read Terraform Cloud token from ~/.terraform.d/credentials.tfrc.json');
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states it's a read operation ('Get'), implying it's non-destructive, but doesn't mention any behavioral traits like authentication requirements, rate limits, error handling, or what 'status' entails (e.g., pending, running, failed). This leaves significant gaps for an agent to understand how to interact with it effectively.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without any wasted words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 the tool's moderate complexity (a read operation with 2 parameters) and the presence of an output schema (which handles return values), the description is minimally adequate. However, it lacks context about behavioral aspects and usage guidelines, which are important for an agent to operate correctly, especially with sibling tools available.

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

Parameters3/5

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

The input schema has 100% description coverage, clearly documenting both parameters ('workspaceName' and 'organization' with a default). The description adds no additional meaning beyond this, such as explaining parameter relationships or usage context. This meets the baseline of 3 since the schema does the heavy lifting.

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 action ('Get') and resource ('current run status for a Terraform Cloud workspace'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_run_details' or 'get_workspace_details', which likely provide related but different information.

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 like 'get_run_details' or 'get_workspace_details'. It lacks context about prerequisites, such as needing an existing run or workspace, or any exclusions for when not to use it.

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/matchs/tf-cloud-mcp-server'

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