infracost_cloud_upload_custom_properties
Upload CSV data to Infracost Cloud for custom property classification of cloud resources. Enables resource categorization and governance through property mapping.
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)The primary handler function that executes the tool logic: validates arguments using the schema, resolves organization slug, calls the API client to upload CSV data, and returns the result.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 the input parameters 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 the ListTools handler, providing name, description, and input 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/index.ts:779-782 (handler)Dispatch handler in the main CallToolRequest switch statement that parses args and delegates to the tools handler.case 'infracost_cloud_upload_custom_properties': { const validatedArgs = UploadCustomPropertiesSchema.parse(args); return await tools.handleUploadCustomProperties(validatedArgs); }
- src/api.ts:387-442 (helper)Supporting API client method that performs the HTTP POST request to Infracost Cloud API endpoint /orgs/{orgSlug}/custom-properties with CSV body to upload custom properties.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', }; } }