Skip to main content
Glama

search_flights

Search for available flights with real-time pricing and AI-powered price predictions. Get flight options with buy/wait/watch recommendations to optimize travel decisions.

Instructions

Search for available flights on Hopper with real-time pricing and AI-powered price predictions. Returns flight options with buy/wait/watch recommendations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originYesIATA airport code (e.g. JFK, LAX, LHR)
destinationYesIATA airport code (e.g. CDG, NRT, SYD)
departure_dateYesDeparture date in YYYY-MM-DD format
return_dateNoReturn date for round trips (YYYY-MM-DD). Omit for one-way.
passengersNoNumber of adult passengers (default: 1)
cabin_classNoCabin class (default: economy)

Implementation Reference

  • The searchFlights function implementation, which navigates to Hopper, extracts flight data from the page, and formats it.
    async function searchFlights(params: FlightSearchParams): Promise<string> {
      const page = await session.newPage();
      try {
        const tripType = params.return_date ? "round" : "one-way";
        const pax = params.passengers ?? 1;
        const cabin = params.cabin_class ?? "economy";
    
        const url =
          `https://www.hopper.com/flights/${params.origin}/${params.destination}` +
          `?departure=${params.departure_date}` +
          (params.return_date ? `&return=${params.return_date}` : "") +
          `&adults=${pax}&cabin=${cabin}&tripType=${tripType}`;
    
        await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 });
        await page.waitForTimeout(3000);
    
        // Extract flight data from rendered page
        const flights = await page.evaluate(() => {
          const results: Array<{
            id: string;
            airline: string;
            departure: string;
            arrival: string;
            duration: string;
            stops: number;
            price: number;
            currency: string;
            prediction: string;
          }> = [];
    
          // Hopper renders flight cards — extract visible data
          const cards = document.querySelectorAll("[data-testid*='flight'], .flight-card, [class*='FlightResult']");
          cards.forEach((card, i) => {
            const text = card.textContent ?? "";
            const priceMatch = text.match(/\$(\d[\d,]*)/);
            results.push({
              id: `flight_${i + 1}`,
              airline: card.querySelector("[class*='airline'], [class*='carrier']")?.textContent?.trim() ?? "Unknown",
              departure: card.querySelector("[class*='depart'], [class*='origin']")?.textContent?.trim() ?? "",
              arrival: card.querySelector("[class*='arriv'], [class*='dest']")?.textContent?.trim() ?? "",
              duration: card.querySelector("[class*='duration']")?.textContent?.trim() ?? "",
              stops: (text.match(/nonstop/i) ? 0 : (text.match(/(\d+)\s*stop/)?.[1] ? parseInt(text.match(/(\d+)\s*stop/)![1]) : 1)),
              price: priceMatch ? parseInt(priceMatch[1].replace(",", "")) : 0,
              currency: "USD",
              prediction: text.match(/buy|wait|watch/i)?.[0]?.toLowerCase() ?? "watch",
            });
          });
    
          return results.slice(0, 10);
        });
    
        // Augment with Hopper's price prediction metadata
  • src/index.ts:585-615 (registration)
    The TOOLS array definition where 'search_flights' is registered with its inputSchema.
    const TOOLS: Tool[] = [
      {
        name: "search_flights",
        description:
          "Search for available flights on Hopper with real-time pricing and AI-powered price predictions. Returns flight options with buy/wait/watch recommendations.",
        inputSchema: {
          type: "object",
          properties: {
            origin: { type: "string", description: "IATA airport code (e.g. JFK, LAX, LHR)" },
            destination: { type: "string", description: "IATA airport code (e.g. CDG, NRT, SYD)" },
            departure_date: { type: "string", description: "Departure date in YYYY-MM-DD format" },
            return_date: { type: "string", description: "Return date for round trips (YYYY-MM-DD). Omit for one-way." },
            passengers: { type: "number", description: "Number of adult passengers (default: 1)" },
            cabin_class: {
              type: "string",
              enum: ["economy", "premium_economy", "business", "first"],
              description: "Cabin class (default: economy)",
            },
          },
          required: ["origin", "destination", "departure_date"],
        },
      },
      {
        name: "search_hotels",
        description:
          "Search for hotels on Hopper with price predictions. Returns hotel options with ratings, amenities, and Hopper's buy/wait recommendation.",
        inputSchema: {
          type: "object",
          properties: {
            destination: { type: "string", description: "City name or destination (e.g. Paris, New York, Tokyo)" },
            check_in: { type: "string", description: "Check-in date in YYYY-MM-DD format" },
Behavior4/5

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

With no annotations provided, the description carries full disclosure burden. It successfully conveys behavioral traits: 'real-time pricing' indicates live data, 'AI-powered price predictions' discloses algorithmic processing, and 'buy/wait/watch recommendations' explains the decision-support output format. Missing only operational details like rate limits or no-results behavior.

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 sentences with zero waste. First sentence front-loads core function and unique differentiators (AI predictions). Second sentence compensates for missing output schema by describing return structure. Every clause 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?

Given no output schema exists, the description appropriately describes return values ('flight options with buy/wait/watch recommendations'). With 6 well-documented parameters and high complexity, the description provides sufficient context for agent selection, though could mention one-way vs round-trip handling implied by optional return_date.

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 description coverage is 100%, with all 6 parameters fully documented (IATA formats, date syntax, enum values). The description correctly does not duplicate this information, maintaining baseline score. No additional semantic constraints (e.g., date range limits) are provided in description, but none are required given schema completeness.

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?

The description uses specific verb 'Search' with clear resource 'flights' and platform 'Hopper'. It distinguishes from sibling 'book_flight' by emphasizing this returns options rather than completing a transaction, and differs from 'search_hotels' via the flight-specific context.

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?

The description implies workflow by stating it 'Returns flight options', suggesting this precedes booking, but lacks explicit when-to-use guidance versus 'get_price_forecast' or 'set_price_alert'. It establishes unique value (AI predictions, buy/wait/watch recommendations) but doesn't state exclusions or prerequisites.

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