budget
Manage execution budgets to control API costs, preventing unexpected charges by setting limits and monitoring usage.
Instructions
Check or set your execution budget. Without action param, returns current status. Use action='set' with budget_usd to create/update. Budget is enforced pre-execution — you get 402 (not a surprise bill) when over limit.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | No | Action: 'get' to check budget, 'set' to create/update | |
| budget_usd | No | Budget amount in USD (required for set) | |
| period | No | Budget period: daily, weekly, monthly, total (default: monthly) | |
| hard_limit | No | If true, reject executions over budget (default: true) |
Implementation Reference
- packages/mcp/src/tools/budget.ts:12-41 (handler)The handleBudget function processes the 'budget' tool logic, supporting 'get' and 'set' actions by delegating to the client.
export async function handleBudget( input: BudgetInput, client: RhumbApiClient ): Promise<BudgetOutput> { const action = input.action || "get"; if (action === "set") { if (!input.budget_usd || input.budget_usd <= 0) { return { agent_id: "", budget_usd: null, spent_usd: null, remaining_usd: null, period: null, hard_limit: null, unlimited: false, }; } const result = await client.setBudget( input.budget_usd, input.period, input.hard_limit ); return result as unknown as BudgetOutput; } // Default: get const result = await client.getBudget(); return result as unknown as BudgetOutput; } - packages/mcp/src/server.ts:226-242 (registration)The tool 'budget' is registered here using the server.tool method, binding the tool definition to the handleBudget handler.
// -- budget ----------------------------------------------------------- server.tool( "budget", "Check or set your call spending limit. Budgets are enforced BEFORE a call — you get HTTP 402 (not a surprise bill) when you'd exceed your limit. Call with no params to check current budget and remaining balance.", { action: z.string().optional().describe(BudgetInputSchema.properties.action.description), budget_usd: z.number().optional().describe(BudgetInputSchema.properties.budget_usd.description), period: z.string().optional().describe(BudgetInputSchema.properties.period.description), hard_limit: z.boolean().optional().describe(BudgetInputSchema.properties.hard_limit.description) }, async ({ action, budget_usd, period, hard_limit }) => { const result = await handleBudget({ action, budget_usd, period, hard_limit }, client); return { content: [{ type: "text" as const, text: JSON.stringify(result) }] }; } );