gcp-billing-get-account-details
Retrieve detailed information about a specific Google Cloud billing account by providing the billing account name. Use this tool to access billing data for management and analysis purposes.
Instructions
Retrieve detailed information about a specific Google Cloud billing account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| billingAccountName | Yes | Billing account name (e.g., 'billingAccounts/123456-789ABC-DEF012') |
Implementation Reference
- src/services/billing/tools.ts:146-195 (handler)The handler function that executes the tool logic: fetches billing account details using Google Cloud Billing API client, formats the response using formatBillingAccount, and returns markdown-formatted text.async ({ billingAccountName }) => { try { const billingClient = getBillingClient(); logger.debug( `Getting billing account details for: ${billingAccountName}`, ); const [account] = await billingClient.getBillingAccount({ name: billingAccountName, }); if (!account) { return { content: [ { type: "text", text: `Billing account not found: ${billingAccountName}`, }, ], }; } const billingAccount: BillingAccount = { name: account.name || "", displayName: account.displayName || "Unknown", open: account.open || false, masterBillingAccount: account.masterBillingAccount, parent: account.parent, }; const response = formatBillingAccount(billingAccount); return { content: [ { type: "text", text: response, }, ], }; } catch (error: any) { logger.error(`Error getting billing account details: ${error.message}`); throw new GcpMcpError( `Failed to get billing account details: ${error.message}`, error.code || "UNKNOWN", error.status || 500, ); } },
- src/services/billing/tools.ts:132-196 (registration)The MCP tool registration call that defines the tool name, title, description, input schema, and associates the handler function.server.registerTool( "gcp-billing-get-account-details", { title: "Get Billing Account Details", description: "Retrieve detailed information about a specific Google Cloud billing account", inputSchema: { billingAccountName: z .string() .describe( "Billing account name (e.g., 'billingAccounts/123456-789ABC-DEF012')", ), }, }, async ({ billingAccountName }) => { try { const billingClient = getBillingClient(); logger.debug( `Getting billing account details for: ${billingAccountName}`, ); const [account] = await billingClient.getBillingAccount({ name: billingAccountName, }); if (!account) { return { content: [ { type: "text", text: `Billing account not found: ${billingAccountName}`, }, ], }; } const billingAccount: BillingAccount = { name: account.name || "", displayName: account.displayName || "Unknown", open: account.open || false, masterBillingAccount: account.masterBillingAccount, parent: account.parent, }; const response = formatBillingAccount(billingAccount); return { content: [ { type: "text", text: response, }, ], }; } catch (error: any) { logger.error(`Error getting billing account details: ${error.message}`); throw new GcpMcpError( `Failed to get billing account details: ${error.message}`, error.code || "UNKNOWN", error.status || 500, ); } }, );
- Zod input schema defining the required 'billingAccountName' parameter.billingAccountName: z .string() .describe( "Billing account name (e.g., 'billingAccounts/123456-789ABC-DEF012')", ), },
- Helper function to format BillingAccount object into a readable markdown string, used in the tool response.export function formatBillingAccount(account: BillingAccount): string { let result = `## ${account.displayName}\n\n`; result += `**Account Name:** ${account.name}\n`; result += `**Status:** ${account.open ? "✅ Active" : "❌ Closed"}\n`; if (account.masterBillingAccount) { result += `**Master Account:** ${account.masterBillingAccount}\n`; } if (account.parent) { result += `**Parent:** ${account.parent}\n`; } return result; }
- Helper function to initialize and return the Google Cloud Billing client instance, used in the handler.export function getBillingClient(): CloudBillingClient { return new CloudBillingClient({ projectId: process.env.GOOGLE_CLOUD_PROJECT, }); }