Skip to main content
Glama

infracost_output

Combine and format Infracost JSON files to merge multiple cost estimates or convert between different output formats for cloud infrastructure cost analysis.

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 resolved paths and options, captures stdout/stderr/JSON, handles errors.
    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 in InfracostTools class: validates input, checks CLI installation, delegates to executeOutput, formats MCP response.
    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', }, ], }; }
  • Server request handler dispatch for CallToolRequest: parses arguments with OutputSchema and calls tools.handleOutput.
    case 'infracost_output': { const validatedArgs = OutputSchema.parse(args); return await tools.handleOutput(validatedArgs); }
  • Zod schema defining input parameters and validation for 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:134-175 (registration)
    Tool registration in ListToolsResponse: defines name, description, and input schema for discovery by MCP clients.
    { 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