get-billing-info
Retrieve billing details for Google Cloud Platform projects to monitor costs and manage cloud spending.
Instructions
Get billing information for the current project
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get-billing-info"
}
}Input 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)Handler function that executes the 'get-billing-info' tool: parses input, checks selected project, uses CloudBillingClient to fetch project billing info and account details, handles errors, 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:125-138 (registration)Registration of the 'get-billing-info' tool in the list-tools handler, defining its 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:228-230 (schema)Zod validation schema for the input arguments of the 'get-billing-info' tool.
const GetBillingInfoSchema = z.object({ projectId: z.string().optional(), }); - index.ts:18-18 (helper)Import of CloudBillingClient used in the get-billing-info handler.
import { CloudBillingClient } from '@google-cloud/billing';