Skip to main content
Glama

infracost_cloud_create_tagging_policy

Create tagging policies in Infracost Cloud to validate resource tags in pull requests, ensuring compliance and preventing untagged deployments.

Instructions

Create a new tagging policy in Infracost Cloud for tag validation in pull requests. Requires INFRACOST_SERVICE_TOKEN environment variable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orgSlugNoOrganization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)
nameYesName for the tagging policy
messageNoThe message to display in the PR comment
prCommentNoWhether to add a comment to the PR
blockPrNoWhether to block the PR
tagsYesArray of tag definitions
filtersNoFilters to limit scope of the policy

Implementation Reference

  • Handler function in InfracostTools class that validates input, checks configuration, delegates to the API client for creating the tagging policy, and formats the response.
    async handleCreateTaggingPolicy(args: z.infer<typeof CreateTaggingPolicySchema>) {
      if (!this.cloudApiClient) {
        throw new Error('INFRACOST_SERVICE_TOKEN is not configured for Infracost Cloud API operations');
      }
    
      const orgSlug = args.orgSlug || this.config.orgSlug;
      if (!orgSlug) {
        throw new Error('Organization slug is required. Provide it via orgSlug parameter or set INFRACOST_ORG environment variable');
      }
    
      const { orgSlug: _, ...policyData } = args;
      const result = await this.cloudApiClient.createTaggingPolicy(orgSlug, policyData);
    
      if (!result.success) {
        throw new Error(result.error || 'Create tagging policy request failed');
      }
    
      return {
        content: [
          {
            type: 'text',
            text: result.output || 'Tagging policy created successfully',
          },
        ],
      };
    }
  • Zod input schema defining parameters for creating a tagging policy, including name, tags, filters, and optional orgSlug.
    export const CreateTaggingPolicySchema = z.object({
      orgSlug: z.string().optional().describe('Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)'),
      name: z.string().describe('Name for the tagging policy'),
      message: z.string().optional().describe('The message to display in the PR comment'),
      prComment: z.boolean().optional().describe('Whether to add a comment to the PR'),
      blockPr: z.boolean().optional().describe('Whether to block the PR'),
      tags: z
        .array(
          z.object({
            key: z.string().describe('Tag key name'),
            mandatory: z.boolean().describe('Whether the tag is required'),
            valueType: z.enum(['ANY', 'LIST', 'REGEX']).describe('Value type: ANY (any value), LIST (predefined values), or REGEX (regex pattern)'),
            allowedValues: z.array(z.string()).optional().describe('List of allowed values (for LIST type)'),
            allowedRegex: z.string().optional().describe('Regex pattern for allowed values (for REGEX type)'),
            message: z.string().optional().describe('Optional message to display if the tag is missing/invalid'),
          })
        )
        .describe('Array of tag definitions'),
      filters: z
        .object({
          repos: z.object({
            include: z.array(z.string()).optional(),
            exclude: z.array(z.string()).optional(),
          }).optional().describe('Repository filters'),
          projects: z.object({
            include: z.array(z.string()).optional(),
            exclude: z.array(z.string()).optional(),
          }).optional().describe('Project filters'),
          baseBranches: z.object({
            include: z.array(z.string()).optional(),
            exclude: z.array(z.string()).optional(),
          }).optional().describe('Base branch filters'),
          resources: z.object({
            include: z.array(z.string()).optional(),
            exclude: z.array(z.string()).optional(),
          }).optional().describe('Resource filters'),
        })
        .optional()
        .describe('Filters to limit scope of the policy'),
    });
  • Core API client method that performs the HTTP POST request to the Infracost Cloud API endpoint to create a new tagging policy.
    async createTaggingPolicy(
      orgSlug: string,
      request: CreateTaggingPolicyRequest
    ): Promise<CommandResult> {
      try {
        const response = await fetch(
          `${INFRACOST_CLOUD_API_BASE}/orgs/${orgSlug}/tagging-policies`,
          {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json',
              Authorization: `Bearer ${this.serviceToken}`,
            },
            body: JSON.stringify({ data: { type: 'tagging-policies', attributes: request } }),
          }
        );
    
        if (!response.ok) {
          const errorText = await response.text();
          return {
            success: false,
            error: `API request failed with status ${response.status}: ${errorText}`,
          };
        }
    
        const data = await response.json();
    
        return {
          success: true,
          output: JSON.stringify(data, null, 2),
          data,
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error occurred',
        };
      }
    }
  • src/index.ts:739-742 (registration)
    Registration and dispatching of the tool in the MCP server's CallToolRequestHandler switch statement.
    case 'infracost_cloud_create_tagging_policy': {
      const validatedArgs = CreateTaggingPolicySchema.parse(args);
      return await tools.handleCreateTaggingPolicy(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