Skip to main content
Glama

infracost_breakdown

Analyze Terraform infrastructure configurations to generate detailed cost estimates and breakdowns for cloud resources.

Instructions

Generate a cost breakdown for Terraform infrastructure. Analyzes Terraform configuration and provides detailed cost estimates for resources. Requires infracost CLI to be installed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to Terraform directory or plan JSON file
formatNoOutput format (default: table)
outFileNoSave output to a file
terraformVarFileNoTerraform variable file paths
terraformVarNoTerraform variables as key-value pairs

Implementation Reference

  • Core implementation of the infracost_breakdown tool: executes the infracost CLI 'breakdown' command with resolved paths and options, captures output, parses JSON if applicable, and returns result.
    export async function executeBreakdown(options: BreakdownOptions): Promise<CommandResult> {
      try {
        const args = ['breakdown', '--path', resolve(options.path)];
    
        if (options.format) {
          args.push('--format', options.format);
        }
    
        if (options.outFile) {
          args.push('--out-file', resolve(options.outFile));
        }
    
        if (options.terraformVarFile) {
          options.terraformVarFile.forEach((file) => {
            args.push('--terraform-var-file', resolve(file));
          });
        }
    
        if (options.terraformVar) {
          Object.entries(options.terraformVar).forEach(([key, value]) => {
            args.push('--terraform-var', `${key}=${value}`);
          });
        }
    
        const { stdout, stderr } = await execFileAsync('infracost', args, {
          maxBuffer: 10 * 1024 * 1024,
        });
    
        let parsedData;
        if (options.format === 'json' && !options.outFile && stdout.trim()) {
          try {
            parsedData = JSON.parse(stdout);
          } catch (e) {
            // If parsing fails, leave data undefined
          }
        }
    
        return {
          success: true,
          output: options.outFile ? `Output saved to ${options.outFile}` : stdout,
          error: stderr || undefined,
          data: parsedData,
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error occurred',
        };
      }
    }
  • Zod schema defining the input parameters for the infracost_breakdown tool, used for validation.
    export const BreakdownSchema = z.object({
      path: z.string().describe('Path to Terraform directory or plan JSON file'),
      format: z.enum(['json', 'table', 'html']).optional().describe('Output format'),
      outFile: z.string().optional().describe('Save output to file'),
      terraformVarFile: z.array(z.string()).optional().describe('Terraform var file paths'),
      terraformVar: z.record(z.string()).optional().describe('Terraform variables as key-value pairs'),
    });
  • Handler method in InfracostTools class: checks CLI installation, calls executeBreakdown, and formats MCP response.
    async handleBreakdown(args: z.infer<typeof BreakdownSchema>) {
      const isInstalled = await checkInfracostInstalled();
      if (!isInstalled) {
        throw new Error(
          'Infracost CLI is not installed. Please install it from https://www.infracost.io/docs/'
        );
      }
    
      const result = await executeBreakdown(args);
    
      if (!result.success) {
        throw new Error(result.error || 'Breakdown command failed');
      }
    
      return {
        content: [
          {
            type: 'text',
            text: result.output || 'Breakdown completed successfully',
          },
        ],
      };
    }
  • src/index.ts:73-105 (registration)
    Tool registration in ListToolsRequestSchema handler: defines name, description, and input schema for discovery.
    {
      name: 'infracost_breakdown',
      description:
        'Generate a cost breakdown for Terraform infrastructure. Analyzes Terraform configuration and provides detailed cost estimates for resources. Requires infracost CLI to be installed.',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to Terraform directory or plan JSON file',
          },
          format: {
            type: 'string',
            enum: ['json', 'table', 'html'],
            description: 'Output format (default: table)',
          },
          outFile: {
            type: 'string',
            description: 'Save output to a file',
          },
          terraformVarFile: {
            type: 'array',
            items: { type: 'string' },
            description: 'Terraform variable file paths',
          },
          terraformVar: {
            type: 'object',
            description: 'Terraform variables as key-value pairs',
          },
        },
        required: ['path'],
      },
    },
  • src/index.ts:704-707 (registration)
    Dispatch/registration in CallToolRequestSchema switch: parses args with schema and delegates to tool handler.
    case 'infracost_breakdown': {
      const validatedArgs = BreakdownSchema.parse(args);
      return await tools.handleBreakdown(validatedArgs);
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the requirement for infracost CLI installation, which is useful context. However, it doesn't describe key behavioral traits such as whether this is a read-only operation, potential rate limits, authentication needs, or what happens if the path is invalid. For a tool with 5 parameters and no annotations, this leaves significant gaps in understanding its behavior.

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 concise with three sentences that efficiently convey the tool's purpose and a key requirement. It's front-loaded with the main function, and each sentence adds value without redundancy. However, it could be slightly more structured by explicitly separating purpose from prerequisites.

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 complexity (5 parameters, no output schema, and no annotations), the description is moderately complete. It covers the core purpose and a prerequisite but lacks details on behavioral aspects, output format implications beyond the 'format' parameter, and how it integrates with sibling tools. For a tool without annotations or output schema, more context on what to expect from the operation would improve completeness.

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, providing clear documentation for all 5 parameters. The description adds minimal value beyond the schema, only implying that the tool analyzes Terraform configuration, which relates to the 'path' parameter. Since schema coverage is high, the baseline score of 3 is appropriate, as the description doesn't significantly enhance parameter understanding beyond what the schema already provides.

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: 'Generate a cost breakdown for Terraform infrastructure' with the verb 'generate' and resource 'cost breakdown'. It specifies it analyzes Terraform configuration and provides cost estimates. However, it doesn't explicitly distinguish this from sibling tools like infracost_diff or infracost_output, which also relate to cost analysis.

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

Usage Guidelines3/5

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

The description provides some usage context by stating it 'Requires infracost CLI to be installed', which is a prerequisite. However, it doesn't offer explicit guidance on when to use this tool versus alternatives like infracost_diff (for comparing costs) or infracost_output (for formatting output), nor does it specify scenarios where this tool is preferred over others.

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/phildougherty/infracost_mcp'

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