get-cost-forecast
Forecast your Google Cloud Platform project costs by specifying a project ID and the number of months for prediction. Helps in planning and managing cloud expenses effectively.
Instructions
Get cost forecast for the current project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| months | No | Number of months to forecast (default: 3) | |
| projectId | No | Project ID to get forecast for (defaults to selected project) |
Implementation Reference
- index.ts:455-496 (handler)Handler function that implements the get-cost-forecast tool by retrieving and returning project billing account information.} else if (name === "get-cost-forecast") { const { projectId, months = 3 } = GetCostForecastSchema.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 cost forecast using Cloud Billing API const [costInfo] = await billingClient.getProjectBillingInfo({ name: `projects/${targetProject}` }); return createTextResponse(JSON.stringify({ projectId: targetProject, billingAccount: billingAccount, billingEnabled: costInfo.billingEnabled, currency: 'USD' }, null, 2)); } catch (error: any) { console.error('Error getting cost forecast:', 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 cost forecast: ${error.message}`); } } else if (name === "get-billing-budget") {
- index.ts:232-235 (schema)Zod schema used for input validation in the get-cost-forecast handler.const GetCostForecastSchema = z.object({ projectId: z.string().optional(), months: z.number().optional(), });
- index.ts:139-156 (registration)Tool registration in the listTools response, including name, description, and input schema.{ name: "get-cost-forecast", description: "Get cost forecast for the current project", inputSchema: { type: "object", properties: { projectId: { type: "string", description: "Project ID to get forecast for (defaults to selected project)", }, months: { type: "number", description: "Number of months to forecast (default: 3)", }, }, required: [], }, },