Skip to main content
Glama

infracost_output

Combine and format Infracost cost estimation files to merge multiple estimates or convert between formats like JSON, HTML, and PR comments.

Instructions

Combine and format Infracost JSON files. Useful for merging multiple cost estimates or converting formats. Requires infracost CLI to be installed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to Infracost JSON file(s) - supports glob patterns
formatNoOutput format
outFileNoSave output to a file
fieldsNoFields to include in output (e.g., ["price", "monthlyQuantity"])
showSkippedNoShow skipped resources in output

Implementation Reference

  • Core handler function that executes the 'infracost output' CLI command with the provided options, handles output parsing for JSON, and returns success/error with stdout/stderr.
    export async function executeOutput(options: OutputOptions): Promise<CommandResult> { try { const args = ['output', '--path', resolve(options.path)]; if (options.format) { args.push('--format', options.format); } if (options.outFile) { args.push('--out-file', resolve(options.outFile)); } if (options.fields && options.fields.length > 0) { args.push('--fields', options.fields.join(',')); } if (options.showSkipped) { args.push('--show-skipped'); } 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', }; } }
  • MCP tool handler method in InfracostTools class. Checks if infracost CLI is installed, calls executeOutput, and formats the response as MCP content.
    async handleOutput(args: z.infer<typeof OutputSchema>) { 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 executeOutput(args); if (!result.success) { throw new Error(result.error || 'Output command failed'); } return { content: [ { type: 'text', text: result.output || 'Output generated successfully', }, ], }; }
  • Zod schema for validating input arguments to the infracost_output tool.
    export const OutputSchema = z.object({ path: z.string().describe('Path to Infracost JSON file(s)'), format: z .enum([ 'json', 'table', 'html', 'diff', 'github-comment', 'gitlab-comment', 'azure-repos-comment', 'bitbucket-comment', ]) .optional() .describe('Output format'), outFile: z.string().optional().describe('Save output to file'), fields: z.array(z.string()).optional().describe('Fields to include in output'), showSkipped: z.boolean().optional().describe('Show skipped resources'), });
  • src/index.ts:714-717 (registration)
    Switch case in CallToolRequestHandler that routes 'infracost_output' calls to tools.handleOutput after schema validation.
    case 'infracost_output': { const validatedArgs = OutputSchema.parse(args); return await tools.handleOutput(validatedArgs); }
  • src/index.ts:134-175 (registration)
    Tool registration in ListToolsRequestHandler, including name, description, and input schema mirroring OutputSchema.
    { name: 'infracost_output', description: 'Combine and format Infracost JSON files. Useful for merging multiple cost estimates or converting formats. Requires infracost CLI to be installed.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to Infracost JSON file(s) - supports glob patterns', }, format: { type: 'string', enum: [ 'json', 'table', 'html', 'diff', 'github-comment', 'gitlab-comment', 'azure-repos-comment', 'bitbucket-comment', ], description: 'Output format', }, outFile: { type: 'string', description: 'Save output to a file', }, fields: { type: 'array', items: { type: 'string' }, description: 'Fields to include in output (e.g., ["price", "monthlyQuantity"])', }, showSkipped: { type: 'boolean', description: 'Show skipped resources in output', }, }, required: ['path'], }, },

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