Skip to main content
Glama

get_bookings

Retrieve flight and hotel booking history from a Hopper account to view current and past itineraries, status details, and pricing information.

Instructions

View current and past bookings from a Hopper account. Returns flight and hotel booking history with status, itinerary details, and pricing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
emailYesEmail address associated with the Hopper account
booking_typeNoFilter by booking type (default: all)

Implementation Reference

  • The 'getBookings' function implements the logic to retrieve booking information from the Hopper website. It navigates to the trips page, checks for authentication, and extracts booking data.
    async function getBookings(params: GetBookingsParams): Promise<string> {
      const page = await session.newPage();
      try {
        await page.goto("https://www.hopper.com/trips", { waitUntil: "domcontentloaded", timeout: 30000 });
        await page.waitForTimeout(2000);
    
        const requiresAuth = await page.evaluate(() =>
          !!document.querySelector("[class*='login'], [class*='signin'], [href*='/login'], [data-testid*='login']")
        );
    
        if (requiresAuth) {
          return JSON.stringify({
            status: "authentication_required",
            email: params.email,
            booking_type: params.booking_type ?? "all",
            message: "Viewing bookings requires signing in to your Hopper account.",
            next_steps: [
              "1. Sign in at https://www.hopper.com/login with your email",
              "2. Navigate to 'Trips' to see all current and past bookings",
              "3. Each booking shows status, itinerary details, and any applicable credits",
            ],
            hopper_trips_url: "https://www.hopper.com/trips",
          }, null, 2);
        }
    
        const bookings = await page.evaluate((bookingType: string) => {
          const items: Array<{
            id: string;
            type: string;
            status: string;
            summary: string;
            date: string;
            price: string;
          }> = [];
    
          document.querySelectorAll("[class*='trip'], [class*='booking'], [class*='itinerary']").forEach((el, i) => {
            const text = el.textContent ?? "";
            if (!text.trim()) return;
    
            const isFlight = text.match(/flight|airline|airport/i);
            const isHotel = text.match(/hotel|check-in|check-out/i);
    
            if (bookingType === "flight" && !isFlight) return;
            if (bookingType === "hotel" && !isHotel) return;
    
            items.push({
              id: `booking_${i + 1}`,
              type: isFlight ? "flight" : isHotel ? "hotel" : "other",
              status: text.match(/cancelled|canceled/i) ? "cancelled"
                : text.match(/upcoming|confirmed/i) ? "confirmed"
                : text.match(/completed|past/i) ? "completed"
                : "unknown",
              summary: text.slice(0, 150).trim(),
              date: el.querySelector("[class*='date'], time")?.textContent?.trim() ?? "",
              price: text.match(/\$[\d,]+/)?.[0] ?? "",
            });
          });
    
          return items;
        }, params.booking_type ?? "all");
    
        return JSON.stringify({
          email: params.email,
          booking_type: params.booking_type ?? "all",
          bookings,
          total_found: bookings.length,
          source_url: page.url(),
          retrieved_at: new Date().toISOString(),
        }, null, 2);
      } finally {
        await page.close();
      }
    }
    
    // ── Helpers ──────────────────────────────────────────────────────────────────
    
    function deriveRecommendation(prices: number[]): string {
      if (prices.length === 0) return "watch";
      const avg = prices.reduce((a, b) => a + b, 0) / prices.length;
      const min = Math.min(...prices);
      return min < avg * 0.9 ? "buy now" : min > avg * 1.1 ? "wait" : "watch";
    }
    
    function buildAnalysis(params: PriceForecastParams, avgPrice: number | null, recommendation: string | null): string {
      const rec = recommendation ?? "watch";
      const price = avgPrice ? `$${avgPrice}` : "current market rates";
      if (rec.includes("buy")) {
        return `Prices for ${params.trip_type === "flight" ? `flights to ${params.destination}` : `hotels in ${params.destination}`} on ${params.travel_date} are currently at ${price}, which is below average. Hopper recommends booking now.`;
      }
      if (rec.includes("wait")) {
        return `Prices at ${price} are elevated. Hopper's AI predicts they may drop closer to the travel date. Consider watching for a few more days.`;
      }
      return `Prices at ${price} are near average. Monitor daily — Hopper will alert you when the optimal booking window opens.`;
    }
    
    function generateMockFlights(params: FlightSearchParams) {
      const airlines = ["United", "Delta", "American", "Southwest", "JetBlue"];
      return airlines.slice(0, 3).map((airline, i) => ({
  • src/index.ts:708-724 (registration)
    Tool definition and registration for 'get_bookings' in the 'TOOLS' array.
    {
      name: "get_bookings",
      description:
        "View current and past bookings from a Hopper account. Returns flight and hotel booking history with status, itinerary details, and pricing.",
      inputSchema: {
        type: "object",
        properties: {
          email: { type: "string", description: "Email address associated with the Hopper account" },
          booking_type: {
            type: "string",
            enum: ["flight", "hotel", "all"],
            description: "Filter by booking type (default: all)",
          },
        },
        required: ["email"],
      },
    },
  • Type definition for 'GetBookingsParams'.
    interface GetBookingsParams {
      email: string;
      booking_type?: "flight" | "hotel" | "all";
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Without annotations, description carries burden of disclosing return structure—succeeds by specifying 'flight and hotel booking history with status, itinerary details, and pricing'. However, omits safety indicators (read-only/idempotent), rate limits, or authentication requirements beyond the email parameter.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two efficiently structured sentences: first states purpose, second discloses return payload. Zero redundancy despite lack of output schema—every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 2-parameter retrieval tool without output schema, description adequately compensates by describing return contents (status, itinerary, pricing). Could improve by noting error conditions (e.g., invalid email) or pagination behavior, but sufficient for agent invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with clear descriptions for both 'email' and 'booking_type'. Description adds no parameter-specific guidance, but baseline 3 is appropriate since schema fully documents inputs without need for elaboration.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description uses specific verb 'View' with clear resource 'bookings from a Hopper account'. Distinctly positions this as a retrieval tool versus sibling actions like 'book_flight', 'book_hotel' (creation) and 'search_flights', 'search_hotels' (discovery).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage through 'current and past bookings' (history retrieval) versus booking new travel, but lacks explicit when-to-use guidance or prerequisites (e.g., 'use after booking confirmation' or 'requires active account').

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/markswendsen-code/mcp-hopper'

If you have feedback or need assistance with the MCP directory API, please join our Discord server