get_cost_allocation
Retrieve detailed cost allocation data from Kubecost to analyze and distribute cloud infrastructure expenses across teams, projects, or resources based on time windows and filtering criteria.
Instructions
Get cost allocation data from Kubecost
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accumulate | No | ||
| aggregate | No | ||
| filters | No | ||
| window | Yes |
Implementation Reference
- src/index.ts:174-197 (registration)Registers the MCP tool 'get_cost_allocation' including input schema, description, and the handler function that invokes the Kubecost client.this.tool( 'get_cost_allocation', 'Get cost allocation data from Kubecost', { window: z.string(), aggregate: z.string().optional(), accumulate: z.boolean().optional(), filters: z.record(z.string()).optional(), }, async (params) => { try { const result = await this.kubecostClient.getCostAllocation(params); return { isError: false, content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { isError: true, content: [{ type: 'text', text: error instanceof Error ? error.message : String(error) }] }; } } );
- src/index.ts:183-196 (handler)The handler function for the 'get_cost_allocation' tool that calls the Kubecost client and formats the response.async (params) => { try { const result = await this.kubecostClient.getCostAllocation(params); return { isError: false, content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { isError: true, content: [{ type: 'text', text: error instanceof Error ? error.message : String(error) }] }; } }
- src/index.ts:177-182 (schema)Input schema for the 'get_cost_allocation' tool defined using Zod for validation.{ window: z.string(), aggregate: z.string().optional(), accumulate: z.boolean().optional(), filters: z.record(z.string()).optional(), },
- src/client/kubecost-client.ts:63-71 (helper)Core helper method in KubecostClient that performs the actual API call to retrieve cost allocation data from the Kubecost server.async getCostAllocation(params: { window: string; aggregate?: string; accumulate?: boolean; filters?: Record<string, string>; }): Promise<CostAllocationResponse> { const response = await this.client.get('/model/allocation', { params }); return response.data; }