Skip to main content
Glama

infracost_comment

Post cost estimate comments to pull requests on GitHub, GitLab, Azure Repos, or Bitbucket. Automatically updates existing comments to provide infrastructure cost visibility during code review.

Instructions

Post cost estimate comments to pull requests on GitHub, GitLab, Azure Repos, or Bitbucket. Automatically updates existing comments. Requires infracost CLI to be installed and appropriate platform credentials.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to Infracost JSON file
platformYesGit platform
repoNoRepository in format owner/repo
pullRequestNoPull request number
commitNoCommit SHA to associate comment with
tagNoTag for comment identification
behaviorNoHow to handle existing comments (default: update)

Implementation Reference

  • Core handler function that executes the 'infracost comment' CLI command by building arguments and running it via child_process.execFile.
    export async function executeComment(options: CommentOptions): Promise<CommandResult> { try { const args = ['comment', options.platform, '--path', resolve(options.path)]; if (options.repo) { args.push('--repo', options.repo); } if (options.pullRequest) { args.push('--pull-request', options.pullRequest); } if (options.commit) { args.push('--commit', options.commit); } if (options.tag) { args.push('--tag', options.tag); } if (options.behavior) { args.push('--behavior', options.behavior); } const { stdout, stderr } = await execFileAsync('infracost', args, { maxBuffer: 10 * 1024 * 1024, }); return { success: true, output: stdout, error: stderr || undefined, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Unknown error occurred', }; } }
  • Wrapper handler in InfracostTools class that checks CLI installation, calls executeComment, and formats MCP response.
    async handleComment(args: z.infer<typeof CommentSchema>) { 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 executeComment(args); if (!result.success) { throw new Error(result.error || 'Comment command failed'); } return { content: [ { type: 'text', text: result.output || 'Comment posted successfully', }, ], }; }
  • Zod input schema defining parameters for the infracost_comment tool, used for validation.
    export const CommentSchema = z.object({ path: z.string().describe('Path to Infracost JSON file'), platform: z.enum(['github', 'gitlab', 'azure-repos', 'bitbucket']).describe('Git platform'), repo: z.string().optional().describe('Repository in format owner/repo'), pullRequest: z.string().optional().describe('Pull request number'), commit: z.string().optional().describe('Commit SHA'), tag: z.string().optional().describe('Tag for comment identification'), behavior: z .enum(['update', 'new', 'delete-and-new']) .optional() .describe('Comment behavior'), });
  • src/index.ts:191-231 (registration)
    Tool registration in ListTools response, including name, description, and input schema.
    { name: 'infracost_comment', description: 'Post cost estimate comments to pull requests on GitHub, GitLab, Azure Repos, or Bitbucket. Automatically updates existing comments. Requires infracost CLI to be installed and appropriate platform credentials.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to Infracost JSON file', }, platform: { type: 'string', enum: ['github', 'gitlab', 'azure-repos', 'bitbucket'], description: 'Git platform', }, repo: { type: 'string', description: 'Repository in format owner/repo', }, pullRequest: { type: 'string', description: 'Pull request number', }, commit: { type: 'string', description: 'Commit SHA to associate comment with', }, tag: { type: 'string', description: 'Tag for comment identification', }, behavior: { type: 'string', enum: ['update', 'new', 'delete-and-new'], description: 'How to handle existing comments (default: update)', }, }, required: ['path', 'platform'], }, },
  • src/index.ts:724-727 (registration)
    Registration of the tool handler in the CallToolRequestSchema switch statement.
    case 'infracost_comment': { const validatedArgs = CommentSchema.parse(args); return await tools.handleComment(validatedArgs); }

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