infracost_cloud_upload_custom_properties
Upload CSV data to Infracost Cloud for custom resource property classification and cloud governance. Enables cost estimation and management through structured property values.
Instructions
Upload custom property values to Infracost Cloud via CSV for resource classification. 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) | |
| csvData | Yes | CSV data containing custom properties |
Implementation Reference
- src/tools.ts:505-530 (handler)Handler method in InfracostTools class that executes the tool: validates args with schema, checks auth/org, calls API client to upload CSV data, returns success/error response.async handleUploadCustomProperties(args: z.infer<typeof UploadCustomPropertiesSchema>) { 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 { csvData } = args; const result = await this.cloudApiClient.uploadCustomProperties(orgSlug, { csvData }); if (!result.success) { throw new Error(result.error || 'Upload custom properties request failed'); } return { content: [ { type: 'text', text: result.output || 'Custom properties uploaded successfully', }, ], }; }
- src/tools.ts:153-156 (schema)Zod schema defining input for the tool: optional orgSlug and required csvData string.export const UploadCustomPropertiesSchema = z.object({ orgSlug: z.string().optional().describe('Organization slug from Infracost Cloud (defaults to INFRACOST_ORG env var)'), csvData: z.string().describe('CSV data containing custom properties'), });
- src/index.ts:676-694 (registration)Tool registration in ListToolsRequestHandler: defines name, description, and inputSchema matching the Zod schema.{ name: 'infracost_cloud_upload_custom_properties', description: 'Upload custom property values to Infracost Cloud via CSV for resource classification. 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)', }, csvData: { type: 'string', description: 'CSV data containing custom properties', }, }, required: ['csvData'], }, },
- src/api.ts:387-442 (handler)Core API client method that performs the HTTP POST to upload CSV custom properties to Infracost Cloud API.async uploadCustomProperties( orgSlug: string, request: UploadCustomPropertiesRequest ): Promise<CommandResult> { try { const response = await fetch( `${INFRACOST_CLOUD_API_BASE}/orgs/${orgSlug}/custom-properties`, { method: 'POST', headers: { 'Content-Type': 'text/csv', Authorization: `Bearer ${this.serviceToken}`, }, body: request.csvData, } ); if (!response.ok) { const errorText = await response.text(); return { success: false, error: `API request failed with status ${response.status}: ${errorText}`, }; } // Handle 204 No Content response (common for uploads) if (response.status === 204) { return { success: true, output: 'Custom properties uploaded successfully', }; } // Try to parse JSON response if there is content const contentType = response.headers.get('content-type'); if (contentType && contentType.includes('application/json')) { const data = await response.json(); return { success: true, output: JSON.stringify(data, null, 2), data, }; } // Fallback for non-JSON responses return { success: true, output: 'Custom properties uploaded successfully', }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Unknown error occurred', }; } }
- src/index.ts:779-782 (registration)Dispatch case in CallToolRequestHandler that routes the tool call to the handler method.case 'infracost_cloud_upload_custom_properties': { const validatedArgs = UploadCustomPropertiesSchema.parse(args); return await tools.handleUploadCustomProperties(validatedArgs); }