Skip to main content
Glama

infracost_comment

Posts infrastructure cost estimates to pull requests on GitHub, GitLab, Azure Repos, or Bitbucket. Updates existing comments automatically to keep cost discussions current.

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 constructs and executes the 'infracost comment' CLI command using child_process.execFile with the provided options.
    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',
        };
      }
    }
  • Zod schema defining and validating the input parameters for the infracost_comment tool.
    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'),
    });
  • Wrapper handler in InfracostTools class that checks for infracost 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/index.ts:191-231 (registration)
    Tool registration in the ListTools response, defining name, description, and input schema for MCP server.
    {
      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)
    Dispatch case in CallToolRequest handler that routes infracost_comment calls to tools.handleComment after schema validation.
    case 'infracost_comment': {
      const validatedArgs = CommentSchema.parse(args);
      return await tools.handleComment(validatedArgs);
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it posts comments to pull requests, automatically updates existing ones (implying mutation), and requires external dependencies (infracost CLI and credentials). However, it doesn't mention rate limits, error handling, or what happens on failure, leaving some gaps for a mutation tool.

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 appropriately sized and front-loaded: the first sentence states the core purpose, the second adds critical behavioral detail (updates), and the third covers prerequisites. Every sentence earns its place with no wasted words, making it efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with 7 parameters, no annotations, no output schema), the description is mostly complete: it covers purpose, behavior, and prerequisites. However, it lacks details on return values or error cases, which would be helpful for a mutation tool. It compensates well with clear context but has minor gaps.

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 adds no additional parameter semantics beyond what's in the schema, such as explaining the 'path' parameter's relation to Infracost JSON or the 'behavior' enum implications. Baseline 3 is appropriate when schema does the heavy lifting.

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 specific action ('Post cost estimate comments'), the target resources ('pull requests on GitHub, GitLab, Azure Repos, or Bitbucket'), and distinguishes from siblings by focusing on commenting functionality rather than breakdown, diff, or cloud management tools. It explicitly mentions 'Automatically updates existing comments' which further clarifies its unique behavior.

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: for posting cost estimates to pull requests on specific platforms. It mentions prerequisites ('Requires infracost CLI to be installed and appropriate platform credentials') but does not explicitly state when NOT to use it or name alternatives among siblings, though the sibling tools are clearly for different purposes (e.g., infracost_breakdown for analysis, infracost_diff for comparisons).

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