get-cost-forecast
Forecast Google Cloud Platform project costs for upcoming months to help with budget planning and resource management.
Instructions
Get cost forecast for the current project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | No | Project ID to get forecast for (defaults to selected project) | |
| months | No | Number of months to forecast (default: 3) |
Implementation Reference
- index.ts:455-495 (handler)Executes the get-cost-forecast tool by retrieving billing account information for the project (note: does not actually compute a forecast, returns basic billing status).} 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}`); }
- index.ts:139-156 (registration)Registers the 'get-cost-forecast' tool in the list of available tools, including its 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: [], }, },
- 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(), });