Skip to main content
Glama

infracost_diff

Compare Terraform configurations to identify cost changes between baseline and current infrastructure, helping teams manage cloud spending effectively.

Instructions

Show cost differences between two Terraform configurations. Compares baseline and current infrastructure to identify cost changes. Requires infracost CLI to be installed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to current Terraform directory or plan JSON file
compareToYesPath to baseline Terraform directory or plan JSON file
formatNoOutput format (default: diff)
outFileNoSave output to a file

Implementation Reference

  • Main handler for 'infracost_diff' tool. Validates args, checks Infracost CLI installation, executes the diff command via executeDiff, and returns the output as MCP content.
    async handleDiff(args: z.infer<typeof DiffSchema>) {
      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 executeDiff(args);
    
      if (!result.success) {
        throw new Error(result.error || 'Diff command failed');
      }
    
      return {
        content: [
          {
            type: 'text',
            text: result.output || 'Diff completed successfully',
          },
        ],
      };
    }
  • Core helper function that executes the 'infracost diff' CLI command with resolved paths and options, captures stdout/stderr/JSON, and returns structured result.
    export async function executeDiff(options: DiffOptions): Promise<CommandResult> {
      try {
        const args = ['diff', '--path', resolve(options.path), '--compare-to', resolve(options.compareTo)];
    
        if (options.format) {
          args.push('--format', options.format);
        }
    
        if (options.outFile) {
          args.push('--out-file', resolve(options.outFile));
        }
    
        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) {}
        }
    
        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_diff tool, used for validation.
    export const DiffSchema = z.object({
      path: z.string().describe('Path to Terraform directory or plan JSON file'),
      compareTo: z.string().describe('Path to baseline Terraform directory or plan JSON file'),
      format: z.enum(['json', 'diff']).optional().describe('Output format'),
      outFile: z.string().optional().describe('Save output to file'),
    });
  • src/index.ts:106-133 (registration)
    Tool registration in ListTools handler, including name, description, and input schema (mirroring DiffSchema).
    {
      name: 'infracost_diff',
      description:
        'Show cost differences between two Terraform configurations. Compares baseline and current infrastructure to identify cost changes. Requires infracost CLI to be installed.',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to current Terraform directory or plan JSON file',
          },
          compareTo: {
            type: 'string',
            description: 'Path to baseline Terraform directory or plan JSON file',
          },
          format: {
            type: 'string',
            enum: ['json', 'diff'],
            description: 'Output format (default: diff)',
          },
          outFile: {
            type: 'string',
            description: 'Save output to a file',
          },
        },
        required: ['path', 'compareTo'],
      },
    },
  • Dispatch case in main CallToolRequestHandler that parses args with DiffSchema and delegates to InfracostTools.handleDiff.
    case 'infracost_diff': {
      const validatedArgs = DiffSchema.parse(args);
      return await tools.handleDiff(validatedArgs);
    }
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 of behavioral disclosure. It mentions the prerequisite (infracost CLI installation) and the comparison function, but lacks details on permissions, rate limits, error handling, or output behavior. This is a moderate gap for a tool with no annotation coverage.

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 front-loaded with the core purpose, followed by additional context and prerequisites in just three concise sentences, with no wasted words or redundancy.

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 no annotations and no output schema, the description is moderately complete for a tool with 4 parameters and 100% schema coverage. It covers the purpose and prerequisites but lacks details on behavioral traits like output format implications or error scenarios, which could be helpful for an agent.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description does not add any parameter-specific details beyond what the schema provides, such as examples or constraints, meeting the baseline for high schema coverage.

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 tool's purpose with specific verbs ('show cost differences', 'compares') and resources ('two Terraform configurations', 'baseline and current infrastructure'), and distinguishes it from siblings like infracost_breakdown by focusing on comparison rather than analysis.

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 (comparing configurations for cost changes) and mentions a prerequisite (infracost CLI installation), but does not explicitly state when not to use it or name specific alternatives among the sibling tools.

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