infracost_cloud_get_guardrail
Retrieve specific cost guardrail details from Infracost Cloud to monitor and enforce cloud spending policies for Terraform infrastructure.
Instructions
Get a specific guardrail from 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 |
Implementation Reference
- src/tools.ts:665-690 (handler)Main handler for the 'infracost_cloud_get_guardrail' tool. Validates arguments using GetGuardrailSchema, calls the API client to fetch the guardrail, and formats the response as MCP content.async handleGetGuardrail(args: z.infer<typeof GetGuardrailSchema>) { 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 { guardrailId } = args; const result = await this.cloudApiClient.getGuardrail(orgSlug, guardrailId); if (!result.success) { throw new Error(result.error || 'Get guardrail request failed'); } return { content: [ { type: 'text', text: result.output || 'Guardrail retrieved successfully', }, ], }; }
- src/tools.ts:218-221 (schema)Zod schema for input validation of the tool, defining orgSlug (optional) and required guardrailId.export const GetGuardrailSchema = z.object({ orgSlug: z.string().optional().describe('Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)'), guardrailId: z.string().describe('Guardrail ID'), });
- src/api.ts:242-275 (helper)Core API client method that performs the GET request to retrieve the specific guardrail from Infracost Cloud API.async getGuardrail(orgSlug: string, guardrailId: string): Promise<CommandResult> { try { const response = await fetch( `${INFRACOST_CLOUD_API_BASE}/orgs/${orgSlug}/guardrails/${guardrailId}`, { method: 'GET', headers: { Authorization: `Bearer ${this.serviceToken}`, }, } ); 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()) as { data: Guardrail }; 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:502-520 (registration)Tool registration in the ListTools handler, including name, description, and input schema (derived from GetGuardrailSchema).{ name: 'infracost_cloud_get_guardrail', description: 'Get a specific guardrail from 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', }, }, required: ['guardrailId'], }, },
- src/index.ts:759-762 (registration)Registration in the CallTool switch statement, parsing args with schema and delegating to tools.handleGetGuardrail.case 'infracost_cloud_get_guardrail': { const validatedArgs = GetGuardrailSchema.parse(args); return await tools.handleGetGuardrail(validatedArgs); }