get_cost_forecast
Predict AWS costs for specified time ranges to plan budgets and manage cloud spending effectively.
Instructions
Predicts future costs for a specified time range.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | Yes | Start date (YYYY-MM-DD). | |
| end_date | Yes | End date (YYYY-MM-DD). | |
| granularity | No | Granularity (default: DAILY). | |
| prediction_interval_level | No | Prediction interval confidence (51-99, default: 80). |
Implementation Reference
- src/index.ts:1043-1059 (handler)Handler function that calls AWS CostExplorer GetCostForecastCommand with provided parameters, processes the forecast results by time, and returns formatted JSON response including total and daily forecasts with prediction intervals.if (name === "get_cost_forecast") { const command = new GetCostForecastCommand({ TimePeriod: { Start: (args as any).start_date, End: (args as any).end_date }, Granularity: (args as any)?.granularity || "DAILY", Metric: "UNBLENDED_COST", PredictionIntervalLevel: (args as any)?.prediction_interval_level || 80 }); const response = await costExplorerClient.send(command); const forecast = response.ForecastResultsByTime?.map(f => ({ Date: f.TimePeriod?.Start, MeanValue: f.MeanValue, PredictionIntervalLower: f.PredictionIntervalLowerBound, PredictionIntervalUpper: f.PredictionIntervalUpperBound })) || []; return { content: [{ type: "text", text: JSON.stringify({ Total: response.Total, Forecast: forecast }, null, 2) }] };
- src/index.ts:221-232 (schema)Tool definition in ListTools response, including name, description, and Zod-like input schema defining required start_date/end_date and optional granularity/prediction_interval_level.name: "get_cost_forecast", description: "Predicts future costs for a specified time range.", inputSchema: { type: "object", properties: { start_date: { type: "string", description: "Start date (YYYY-MM-DD)." }, end_date: { type: "string", description: "End date (YYYY-MM-DD)." }, granularity: { type: "string", enum: ["DAILY", "MONTHLY", "HOURLY"], description: "Granularity (default: DAILY)." }, prediction_interval_level: { type: "number", description: "Prediction interval confidence (51-99, default: 80)." } }, required: ["start_date", "end_date"] }
- src/index.ts:221-232 (registration)Registration of the tool in the list of available tools returned by ListToolsRequestHandler, which defines its metadata and input schema.name: "get_cost_forecast", description: "Predicts future costs for a specified time range.", inputSchema: { type: "object", properties: { start_date: { type: "string", description: "Start date (YYYY-MM-DD)." }, end_date: { type: "string", description: "End date (YYYY-MM-DD)." }, granularity: { type: "string", enum: ["DAILY", "MONTHLY", "HOURLY"], description: "Granularity (default: DAILY)." }, prediction_interval_level: { type: "number", description: "Prediction interval confidence (51-99, default: 80)." } }, required: ["start_date", "end_date"] }
- src/index.ts:24-24 (helper)Import of GetCostForecastCommand and CostExplorerClient from AWS SDK.import { CostExplorerClient, GetCostAndUsageCommand, GetCostForecastCommand, GetAnomaliesCommand, GetSavingsPlansUtilizationCommand, GetReservationUtilizationCommand } from "@aws-sdk/client-cost-explorer";
- src/index.ts:58-58 (helper)Initialization of the CostExplorerClient used by the get_cost_forecast handler.const costExplorerClient = new CostExplorerClient({});