get_price_forecast
Predict flight and hotel price trends to determine optimal booking timing. Analyzes historical data to recommend whether to buy now or wait for better rates.
Instructions
Get Hopper's AI price forecast for a flight or hotel. Returns whether to buy now, wait for lower prices, or watch for changes — with confidence percentage and reasoning.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| trip_type | Yes | Type of travel to forecast | |
| origin | No | IATA airport code for flight origin (required for flights) | |
| destination | Yes | Destination city or IATA code | |
| travel_date | Yes | Travel/check-in date in YYYY-MM-DD format | |
| return_date | No | Return/check-out date for round trips or hotel stays (YYYY-MM-DD) |
Implementation Reference
- src/index.ts:248-303 (handler)The handler function 'getPriceForecast' which scrapes price forecast information from hopper.com.
async function getPriceForecast(params: PriceForecastParams): Promise<string> { const page = await session.newPage(); try { let url: string; if (params.trip_type === "flight" && params.origin) { url = `https://www.hopper.com/flights/${params.origin}/${params.destination}` + `?departure=${params.travel_date}` + (params.return_date ? `&return=${params.return_date}` : ""); } else { url = `https://www.hopper.com/hotels/${encodeURIComponent(params.destination)}` + `?checkin=${params.travel_date}` + (params.return_date ? `&checkout=${params.return_date}` : ""); } await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 }); await page.waitForTimeout(3000); const forecast = await page.evaluate(() => { const body = document.body.textContent ?? ""; const recommendation = body.match(/\b(buy now|wait|watch prices|prices are low|prices are high)\b/gi)?.[0] ?? null; const confidence = body.match(/(\d+)%\s*confidence/i)?.[1] ?? null; const priceHistory = body.match(/was\s*\$(\d[\d,]*)/i)?.[1] ?? null; const forecastedPrice = body.match(/forecast[^\$]*\$(\d[\d,]*)/i)?.[1] ?? null; return { recommendation, confidence, priceHistory, forecastedPrice }; }); const currentPrices = await page.evaluate(() => { const prices: number[] = []; document.querySelectorAll("[class*='price'], [class*='Price']").forEach((el) => { const m = el.textContent?.match(/\$(\d[\d,]*)/); if (m) prices.push(parseInt(m[1].replace(",", ""))); }); return prices.filter((p) => p > 0).slice(0, 5); }); const avgPrice = currentPrices.length > 0 ? Math.round(currentPrices.reduce((a, b) => a + b, 0) / currentPrices.length) : null; const result = { trip_type: params.trip_type, destination: params.destination, origin: params.origin, travel_date: params.travel_date, return_date: params.return_date, recommendation: forecast.recommendation ?? deriveRecommendation(currentPrices), confidence_pct: forecast.confidence ? parseInt(forecast.confidence) : null, current_avg_price_usd: avgPrice, historical_avg_usd: forecast.priceHistory ? parseInt(forecast.priceHistory.replace(",", "")) : null, forecasted_price_usd: forecast.forecastedPrice ? parseInt(forecast.forecastedPrice.replace(",", "")) : null, analysis: buildAnalysis(params, avgPrice, forecast.recommendation), source_url: page.url(), retrieved_at: new Date().toISOString(), }; - src/index.ts:626-642 (registration)Tool registration for 'get_price_forecast'.
name: "get_price_forecast", description: "Get Hopper's AI price forecast for a flight or hotel. Returns whether to buy now, wait for lower prices, or watch for changes — with confidence percentage and reasoning.", inputSchema: { type: "object", properties: { trip_type: { type: "string", enum: ["flight", "hotel"], description: "Type of travel to forecast" }, origin: { type: "string", description: "IATA airport code for flight origin (required for flights)" }, destination: { type: "string", description: "Destination city or IATA code" }, travel_date: { type: "string", description: "Travel/check-in date in YYYY-MM-DD format" }, return_date: { type: "string", description: "Return/check-out date for round trips or hotel stays (YYYY-MM-DD)" }, }, required: ["trip_type", "destination", "travel_date"], }, }, { name: "set_price_alert",