get-billing-info
Retrieve billing details for a specific Google Cloud Platform project by providing the project ID, defaulting to the currently selected project if none is specified.
Instructions
Get billing information for the current project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | No | Project ID to get billing info for (defaults to selected project) |
Implementation Reference
- index.ts:413-454 (handler)The handler function that executes the get-billing-info tool. It parses input, checks project, uses CloudBillingClient to fetch project billing info and account details, returns JSON response.} else if (name === "get-billing-info") { const { projectId } = GetBillingInfoSchema.parse(args); const targetProject = projectId || selectedProject; if (!targetProject) { return createTextResponse("No project selected. Please select a project first."); } try { const billingClient = new CloudBillingClient(); const [billingInfo] = await billingClient.getProjectBillingInfo({ name: `projects/${targetProject}` }); if (!billingInfo.billingEnabled) { return createTextResponse("Billing is not enabled for this project."); } const billingAccount = billingInfo.billingAccountName; if (!billingAccount) { return createTextResponse("No billing account associated with this project."); } // Get billing account details const [account] = await billingClient.getBillingAccount({ name: billingAccount }); return createTextResponse(JSON.stringify({ projectId: targetProject, billingEnabled: billingInfo.billingEnabled, billingAccountName: billingAccount, displayName: account.displayName, open: account.open }, null, 2)); } catch (error: any) { console.error('Error getting billing info:', error); if (error.code === 7) { return createTextResponse("Error: Cloud Billing API is not enabled. Please enable it in the Google Cloud Console."); } return createTextResponse(`Error getting billing info: ${error.message}`); }
- index.ts:228-230 (schema)Zod schema used for input validation in the get-billing-info handler.const GetBillingInfoSchema = z.object({ projectId: z.string().optional(), });
- index.ts:125-138 (registration)Tool registration in the list-tools response, including name, description, and input schema.{ name: "get-billing-info", description: "Get billing information for the current project", inputSchema: { type: "object", properties: { projectId: { type: "string", description: "Project ID to get billing info for (defaults to selected project)", }, }, required: [], }, },
- index.ts:128-137 (schema)Input schema defined in the tool registration for get-billing-info.inputSchema: { type: "object", properties: { projectId: { type: "string", description: "Project ID to get billing info for (defaults to selected project)", }, }, required: [], },
- index.ts:18-18 (helper)Import of CloudBillingClient used by the get-billing-info handler.import { CloudBillingClient } from '@google-cloud/billing';