billing_get_account_summary
Retrieve a billing summary for your IBM Cloud account for a specified month to track costs.
Instructions
Get account billing summary for a given month
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | No | ||
| month | Yes | Billing month (YYYY-MM) |
Implementation Reference
- src/tools/billing/index.ts:10-15 (handler)The tool handler for 'billing_get_account_summary'. It registers an MCP tool that takes optional account_id and required month (YYYY-MM), resolves the account ID (from param or auth), then calls the IBM Cloud Billing API at GET /v4/accounts/{id}/summary/{month} via the client.
server.tool("billing_get_account_summary", "Get account billing summary for a given month", { account_id: z.string().optional(), month: z.string().describe("Billing month (YYYY-MM)"), }, async (p) => safeTool(async () => { const acctId = p.account_id || await client.getAuth().getAccountId(); return client.get(`${base}/accounts/${acctId}/summary/${p.month}`); })); - src/tools/billing/index.ts:10-15 (schema)Input schema for 'billing_get_account_summary': account_id (optional string) and month (string with YYYY-MM description).
server.tool("billing_get_account_summary", "Get account billing summary for a given month", { account_id: z.string().optional(), month: z.string().describe("Billing month (YYYY-MM)"), }, async (p) => safeTool(async () => { const acctId = p.account_id || await client.getAuth().getAccountId(); return client.get(`${base}/accounts/${acctId}/summary/${p.month}`); })); - src/config.ts:71-71 (helper)The IBM_ENDPOINTS.BILLING constant that provides the base URL (https://billing.cloud.ibm.com/v4) used in the tool's API call.
BILLING: "https://billing.cloud.ibm.com/v4", - src/server.ts:17-17 (registration)Import of registerBillingTools from the billing module, and call on line 80 to register all billing tools (including billing_get_account_summary) into the MCP server.
import { registerBillingTools } from "./tools/billing/index.js"; - src/lib/utils.ts:70-77 (helper)The safeTool helper that wraps the tool handler, catching errors and returning success/error MCP responses.
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); } }