infracost_cloud_update_guardrail
Modify cost guardrail thresholds and settings in Infracost Cloud to control infrastructure spending by setting budget limits, configuring notifications, and managing pull request actions.
Instructions
Update an existing guardrail in Infracost Cloud. Requires INFRACOST_SERVICE_TOKEN environment variable.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| orgSlug | No | Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var) | |
| guardrailId | Yes | Guardrail ID | |
| name | No | Name for the guardrail | |
| filters | No | Filters to limit scope of the guardrail | |
| increaseThreshold | No | Threshold for cost increases (monthly dollar amount) | |
| increasePercentThreshold | No | Threshold for cost increases (percentage) | |
| totalThreshold | No | Threshold for total cost (monthly dollar amount) | |
| message | No | Custom message to display when threshold is exceeded | |
| webhookUrl | No | Webhook URL to notify when threshold is exceeded | |
| blockPullRequest | No | Whether to block PR when threshold is exceeded | |
| commentOnPullRequest | No | Whether to comment on PR when threshold is exceeded |
Implementation Reference
- src/index.ts:590-655 (registration)Tool registration in the ListTools handler, including name, description, and input schema definition.{ name: 'infracost_cloud_update_guardrail', description: 'Update an existing guardrail in Infracost Cloud. Requires INFRACOST_SERVICE_TOKEN environment variable.', inputSchema: { type: 'object', properties: { orgSlug: { type: 'string', description: 'Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)', }, guardrailId: { type: 'string', description: 'Guardrail ID', }, name: { type: 'string', description: 'Name for the guardrail', }, filters: { type: 'array', description: 'Filters to limit scope of the guardrail', items: { type: 'object', properties: { type: { type: 'string', enum: ['project', 'repository'], description: 'Filter type', }, value: { type: 'string', description: 'Filter value' }, }, required: ['type', 'value'], }, }, increaseThreshold: { type: 'number', description: 'Threshold for cost increases (monthly dollar amount)', }, increasePercentThreshold: { type: 'number', description: 'Threshold for cost increases (percentage)', }, totalThreshold: { type: 'number', description: 'Threshold for total cost (monthly dollar amount)', }, message: { type: 'string', description: 'Custom message to display when threshold is exceeded', }, webhookUrl: { type: 'string', description: 'Webhook URL to notify when threshold is exceeded', }, blockPullRequest: { type: 'boolean', description: 'Whether to block PR when threshold is exceeded', }, commentOnPullRequest: { type: 'boolean', description: 'Whether to comment on PR when threshold is exceeded', }, }, required: ['guardrailId'], },
- src/index.ts:769-772 (handler)Dispatch in CallToolRequest handler that validates arguments and delegates to InfracostTools.handleUpdateGuardrailcase 'infracost_cloud_update_guardrail': { const validatedArgs = UpdateGuardrailSchema.parse(args); return await tools.handleUpdateGuardrail(validatedArgs); }
- src/tools.ts:223-268 (schema)Zod schema for input validation of the tool arguments.export const UpdateGuardrailSchema = z.object({ orgSlug: z.string().optional().describe('Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)'), guardrailId: z.string().describe('Guardrail ID'), name: z.string().optional().describe('Name for the guardrail'), scope: z .object({ type: z .enum(['ALL_PROJECTS', 'REPO', 'PROJECT']) .describe('Scope type for the guardrail'), repositories: z.array(z.string()).optional().describe('Repository names (for REPO scope)'), projects: z.array(z.string()).optional().describe('Project names (for PROJECT scope)'), }) .optional() .describe('Scope configuration'), increaseThreshold: z .number() .optional() .describe('Threshold for cost increases (monthly dollar amount)'), increasePercentThreshold: z .number() .optional() .describe('Threshold for cost increases (percentage)'), totalThreshold: z .number() .optional() .describe('Threshold for total cost (monthly dollar amount)'), message: z.string().optional().describe('Custom message to display when threshold is exceeded'), webhookUrl: z.string().default('').describe('Webhook URL to notify when threshold is exceeded (defaults to empty string if not needed)'), blockPullRequest: z.boolean().optional().describe('Whether to block PR when threshold is exceeded'), commentOnPullRequest: z .boolean() .optional() .describe('Whether to comment on PR when threshold is exceeded'), emailRecipientOrgMemberIds: z .array(z.string()) .optional() .describe('Array of organization member IDs to email'), mailingListEmails: z .array(z.string()) .optional() .describe('Array of email addresses to notify'), msTeamsEmails: z .array(z.string()) .optional() .describe('Array of MS Teams email addresses to notify'), });
- src/tools.ts:692-768 (handler)Primary handler function in InfracostTools class that processes arguments, maps scope to API format, and invokes the cloud API client to update the guardrail.async handleUpdateGuardrail(args: z.infer<typeof UpdateGuardrailSchema>) { 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: _, guardrailId, scope, blockPullRequest, commentOnPullRequest, emailRecipientOrgMemberIds, mailingListEmails, msTeamsEmails, ...rest } = args; const apiRequest: any = { ...rest, }; if (scope) { if (scope.type === 'ALL_PROJECTS' || scope.type === 'REPO') { apiRequest.scope = 'REPO'; } else { apiRequest.scope = 'PROJECT'; } const filters: any = {}; if (scope.repositories && scope.repositories.length > 0) { filters.repos = { include: scope.repositories }; } if (scope.projects && scope.projects.length > 0) { filters.projects = { include: scope.projects }; } if (Object.keys(filters).length > 0) { apiRequest.filters = filters; } } if (commentOnPullRequest !== undefined) { apiRequest.prComment = commentOnPullRequest; } if (blockPullRequest !== undefined) { apiRequest.blockPr = blockPullRequest; } if (emailRecipientOrgMemberIds !== undefined) { apiRequest.emailRecipientOrgMemberIds = emailRecipientOrgMemberIds; } if (mailingListEmails !== undefined) { apiRequest.mailingListEmails = mailingListEmails; } if (msTeamsEmails !== undefined) { apiRequest.msTeamsEmails = msTeamsEmails; } const result = await this.cloudApiClient.updateGuardrail(orgSlug, guardrailId, apiRequest); if (!result.success) { throw new Error(result.error || 'Update guardrail request failed'); } return { content: [ { type: 'text', text: result.output || 'Guardrail updated successfully', }, ], }; }
- src/api.ts:314-353 (helper)API client method that performs the HTTP PATCH request to update a guardrail in Infracost Cloud.async updateGuardrail( orgSlug: string, guardrailId: string, request: UpdateGuardrailRequest ): Promise<CommandResult> { try { const response = await fetch( `${INFRACOST_CLOUD_API_BASE}/orgs/${orgSlug}/guardrails/${guardrailId}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${this.serviceToken}`, }, body: JSON.stringify({ data: { type: 'guardrails', 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', }; } }