billing_get_resource_usage
Retrieve billing usage for a specific resource group by providing the resource group ID and month.
Instructions
Get usage for a specific resource group
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | No | ||
| resource_group_id | Yes | ||
| month | Yes |
Implementation Reference
- src/tools/billing/index.ts:24-29 (handler)The handler for billing_get_resource_usage. It calls the IBM Cloud Billing API v4 endpoint to get usage for a specific resource group. Accepts optional account_id, required resource_group_id, and month (YYYY-MM). Delegates to IBMCloudAPIClient.get() wrapped in safeTool().
server.tool("billing_get_resource_usage", "Get usage for a specific resource group", { account_id: z.string().optional(), resource_group_id: z.string(), month: z.string(), }, async (p) => safeTool(async () => { const acctId = p.account_id || await client.getAuth().getAccountId(); return client.get(`${base}/accounts/${acctId}/resource_groups/${p.resource_group_id}/usage/${p.month}`); })); - src/tools/billing/index.ts:25-25 (schema)Zod schema defining inputs for billing_get_resource_usage: account_id (optional string), resource_group_id (required string), month (required string in YYYY-MM format).
account_id: z.string().optional(), resource_group_id: z.string(), month: z.string(), - src/tools/billing/index.ts:24-29 (registration)Registration of the billing_get_resource_usage tool on the MCP server via server.tool() within the registerBillingTools function.
server.tool("billing_get_resource_usage", "Get usage for a specific resource group", { account_id: z.string().optional(), resource_group_id: z.string(), month: z.string(), }, async (p) => safeTool(async () => { const acctId = p.account_id || await client.getAuth().getAccountId(); return client.get(`${base}/accounts/${acctId}/resource_groups/${p.resource_group_id}/usage/${p.month}`); })); - src/lib/utils.ts:70-77 (helper)The safeTool helper wraps the handler to catch errors and return proper MCP responses (successContent or errorContent).
export async function safeTool<T>(fn: () => Promise<T>): Promise<ReturnType<typeof successContent> | ReturnType<typeof errorContent>> { try { const result = await fn(); return successContent(result); } catch (error) { return errorContent(error); } } - src/lib/api-client.ts:128-130 (helper)The IBMCloudAPIClient.get() method used by the handler to make the authenticated GET request to the Billing API endpoint.
async get<T = unknown>(url: string, queryParams?: Record<string, string | number | boolean | undefined>): Promise<T> { return this.request<T>(url, { method: "GET", queryParams }); }