update_budget
Modify an existing budget rule in Kubecost to adjust spending limits, notification settings, and resource allocations for cost management.
Instructions
Update an existing budget rule in Kubecost
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| actions | Yes | ||
| budgetId | Yes | ||
| interval | Yes | ||
| intervalDay | Yes | ||
| kind | Yes | ||
| name | Yes | ||
| spendLimit | Yes | ||
| values | Yes |
Implementation Reference
- src/index.ts:112-151 (registration)Registration of the 'update_budget' tool on the MCP server, including inline schema and handler function.this.tool( 'update_budget', 'Update an existing budget rule in Kubecost', { budgetId: z.string(), name: z.string(), values: z.object({ cluster: z.array(z.string()).optional(), namespace: z.array(z.string()).optional(), label: z.record(z.array(z.string())).optional(), }), kind: z.enum(['soft', 'hard']), interval: z.enum(['weekly', 'monthly']), intervalDay: z.number(), spendLimit: z.number(), actions: z.array(z.object({ percentage: z.number(), emails: z.array(z.string()).optional(), slackWebhooks: z.array(z.string()).optional(), msTeamsWebhooks: z.array(z.string()).optional(), })), }, async ({ budgetId, ...budgetData }) => { try { const result = await this.kubecostClient.createOrUpdateBudget({ ...budgetData, id: budgetId, }); return { isError: false, content: [{ type: 'text', text: `Budget updated successfully: ${JSON.stringify(result, null, 2)}` }] }; } catch (error) { return { isError: true, content: [{ type: 'text', text: error instanceof Error ? error.message : String(error) }] }; } } );
- src/index.ts:134-150 (handler)Handler function for 'update_budget' tool that constructs the budget object with ID and calls KubecostClient.createOrUpdateBudget.async ({ budgetId, ...budgetData }) => { try { const result = await this.kubecostClient.createOrUpdateBudget({ ...budgetData, id: budgetId, }); return { isError: false, content: [{ type: 'text', text: `Budget updated successfully: ${JSON.stringify(result, null, 2)}` }] }; } catch (error) { return { isError: true, content: [{ type: 'text', text: error instanceof Error ? error.message : String(error) }] }; } }
- src/index.ts:116-133 (schema)Zod input schema for validating parameters of the 'update_budget' tool.budgetId: z.string(), name: z.string(), values: z.object({ cluster: z.array(z.string()).optional(), namespace: z.array(z.string()).optional(), label: z.record(z.array(z.string())).optional(), }), kind: z.enum(['soft', 'hard']), interval: z.enum(['weekly', 'monthly']), intervalDay: z.number(), spendLimit: z.number(), actions: z.array(z.object({ percentage: z.number(), emails: z.array(z.string()).optional(), slackWebhooks: z.array(z.string()).optional(), msTeamsWebhooks: z.array(z.string()).optional(), })), },
- src/client/kubecost-client.ts:43-46 (helper)KubecostClient method that performs the HTTP POST to create or update a budget rule, called by the tool handler.async createOrUpdateBudget(budget: BudgetRule): Promise<BudgetResponse> { const response = await this.client.post('/model/budget', budget); return response.data; }