Skip to main content
Glama

search_flights

Search for flights by specifying origin, destination, dates, cabin class, and passenger count to find available travel options.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesType of flight
originYesOrigin airport or city IATA code (e.g., SFO, NYC)
destinationYesDestination airport or city IATA code (e.g., LAX, LHR)
departureDateYesDeparture date in YYYY-MM-DD format
returnDateNoReturn date in YYYY-MM-DD format (required for round-trip)
departureTimeNoPreferred departure time window
arrivalTimeNoPreferred arrival time window
cabinClassYesCabin class
adultsNoNumber of adult passengers
maxConnectionsNoMaximum number of connections
additionalStopsNoAdditional stops for multi-city flights

Implementation Reference

  • The asynchronous handler function that executes the search_flights tool logic. Constructs flight slices depending on trip type (one-way, round-trip, or multi-city) and sends an offer request to the Duffel flight client.
    async (params: FlightSearch) => { try { const slices = []; // Build slices based on flight type if (params.type === 'one_way') { slices.push(flightClient.createSlice( params.origin, params.destination, params.departureDate, params.departureTime, params.arrivalTime )); } else if (params.type === 'round_trip') { if (!params.returnDate) { throw new Error('Return date required for round-trip flights'); } slices.push(flightClient.createSlice( params.origin, params.destination, params.departureDate, params.departureTime, params.arrivalTime )); slices.push(flightClient.createSlice( params.destination, params.origin, params.returnDate, params.departureTime, params.arrivalTime )); } else if (params.type === 'multi_city') { if (!params.additionalStops || params.additionalStops.length === 0) { throw new Error('Additional stops required for multi-city flights'); } // First leg slices.push(flightClient.createSlice( params.origin, params.destination, params.departureDate )); // Additional legs for (const stop of params.additionalStops) { slices.push(flightClient.createSlice( stop.origin, stop.destination, stop.departureDate )); } } // Create the offer request const response = await flightClient.createOfferRequest({ slices, cabin_class: params.cabinClass, adult_count: params.adults, max_connections: params.maxConnections, return_offers: true, supplier_timeout: 15000 // 15 seconds }); // Return formatted response return { content: [ { type: 'text', text: JSON.stringify(response, null, 2) } ] }; } catch (error) { console.error(`Error searching flights: ${error}`); throw error; } }
  • Zod schema defining the input parameters for the search_flights tool, validated before passing to the handler.
    export const flightSearchSchema = z.object({ type: z.enum(['one_way', 'round_trip', 'multi_city']).describe('Type of flight'), origin: z.string().describe('Origin airport or city IATA code (e.g., SFO, NYC)'), destination: z.string().describe('Destination airport or city IATA code (e.g., LAX, LHR)'), departureDate: z.string().describe('Departure date in YYYY-MM-DD format'), returnDate: z.string().optional().describe('Return date in YYYY-MM-DD format (required for round-trip)'), departureTime: timeSpecSchema.optional().describe('Preferred departure time window'), arrivalTime: timeSpecSchema.optional().describe('Preferred arrival time window'), cabinClass: z.enum(['economy', 'premium_economy', 'business', 'first']).describe('Cabin class'), adults: z.number().min(1).default(1).describe('Number of adult passengers'), maxConnections: z.number().optional().describe('Maximum number of connections'), additionalStops: z.array(flightSegmentSchema).optional().describe('Additional stops for multi-city flights') });
  • src/server.ts:30-113 (registration)
    Registers the search_flights tool with the MCP server, associating the tool name, input schema, and handler function.
    server.tool( 'search_flights', flightSearchSchema.shape, async (params: FlightSearch) => { try { const slices = []; // Build slices based on flight type if (params.type === 'one_way') { slices.push(flightClient.createSlice( params.origin, params.destination, params.departureDate, params.departureTime, params.arrivalTime )); } else if (params.type === 'round_trip') { if (!params.returnDate) { throw new Error('Return date required for round-trip flights'); } slices.push(flightClient.createSlice( params.origin, params.destination, params.departureDate, params.departureTime, params.arrivalTime )); slices.push(flightClient.createSlice( params.destination, params.origin, params.returnDate, params.departureTime, params.arrivalTime )); } else if (params.type === 'multi_city') { if (!params.additionalStops || params.additionalStops.length === 0) { throw new Error('Additional stops required for multi-city flights'); } // First leg slices.push(flightClient.createSlice( params.origin, params.destination, params.departureDate )); // Additional legs for (const stop of params.additionalStops) { slices.push(flightClient.createSlice( stop.origin, stop.destination, stop.departureDate )); } } // Create the offer request const response = await flightClient.createOfferRequest({ slices, cabin_class: params.cabinClass, adult_count: params.adults, max_connections: params.maxConnections, return_offers: true, supplier_timeout: 15000 // 15 seconds }); // Return formatted response return { content: [ { type: 'text', text: JSON.stringify(response, null, 2) } ] }; } catch (error) { console.error(`Error searching flights: ${error}`); throw error; } } );

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/AkekaratP/flights-mcp-ts'

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