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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to Infracost JSON file | |
| platform | Yes | Git platform | |
| repo | No | Repository in format owner/repo | |
| pullRequest | No | Pull request number | |
| commit | No | Commit SHA to associate comment with | |
| tag | No | Tag for comment identification | |
| behavior | No | How to handle existing comments (default: update) |
Implementation Reference
- src/cli.ts:178-217 (handler)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', }; } }
- src/tools.ts:382-404 (handler)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', }, ], }; }
- src/tools.ts:52-63 (schema)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); }