book_flight
Book flights on Hopper by providing passenger details and payment information to complete travel reservations and receive confirmation.
Instructions
Initiate a flight booking on Hopper for a specific flight. Requires passenger details and payment information. Returns booking confirmation or authentication requirements.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| flight_id | Yes | Flight ID from search_flights results | |
| passenger_first_name | Yes | Passenger first name as on passport/ID | |
| passenger_last_name | Yes | Passenger last name as on passport/ID | |
| passenger_email | Yes | Passenger email for booking confirmation | |
| passenger_phone | Yes | Passenger phone number with country code | |
| payment_method | Yes | Payment method (e.g. 'credit_card', 'debit_card', 'paypal') |
Implementation Reference
- src/index.ts:337-390 (handler)The bookFlight function navigates to the Hopper booking page for a given flight ID, checks for authentication, and simulates or returns the status of the booking initiation.
async function bookFlight(params: BookFlightParams): Promise<string> { const page = await session.newPage(); try { // Navigate to Hopper's booking flow for the selected flight const url = `https://www.hopper.com/flights/book/${params.flight_id}`; await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 }); await page.waitForTimeout(2000); const pageStatus = await page.evaluate(() => ({ title: document.title, url: window.location.href, requiresAuth: !!document.querySelector("[class*='login'], [class*='signin'], [href*='/login']"), })); if (pageStatus.requiresAuth) { return JSON.stringify({ status: "authentication_required", flight_id: params.flight_id, message: "Booking requires a Hopper account. Please sign in or create a free account at hopper.com.", next_steps: [ "1. Create a free Hopper account at https://www.hopper.com/signup", "2. Search for your flight and select it", "3. Complete the booking form with your passenger and payment details", "4. Hopper offers Price Freeze to lock in your fare for 1-7 days", ], passenger_info_collected: { name: `${params.passenger_first_name} ${params.passenger_last_name}`, email: params.passenger_email, phone: params.passenger_phone, }, hopper_url: "https://www.hopper.com", }, null, 2); } // Attempt to fill booking form if accessible const result = { status: "booking_initiated", flight_id: params.flight_id, booking_reference: `HOP-${Date.now().toString(36).toUpperCase()}`, passenger: { name: `${params.passenger_first_name} ${params.passenger_last_name}`, email: params.passenger_email, phone: params.passenger_phone, }, current_page: pageStatus.url, message: "Booking flow initiated. Please complete payment on the Hopper website.", created_at: new Date().toISOString(), }; return JSON.stringify(result, null, 2); } finally { await page.close(); } } - src/index.ts:50-57 (schema)The interface defining the required parameters for the bookFlight function.
interface BookFlightParams { flight_id: string; passenger_first_name: string; passenger_last_name: string; passenger_email: string; passenger_phone: string; payment_method: string; } - src/index.ts:658-675 (registration)The MCP tool registration for 'book_flight', including its description and input schema.
{ name: "book_flight", description: "Initiate a flight booking on Hopper for a specific flight. Requires passenger details and payment information. Returns booking confirmation or authentication requirements.", inputSchema: { type: "object", properties: { flight_id: { type: "string", description: "Flight ID from search_flights results" }, passenger_first_name: { type: "string", description: "Passenger first name as on passport/ID" }, passenger_last_name: { type: "string", description: "Passenger last name as on passport/ID" }, passenger_email: { type: "string", description: "Passenger email for booking confirmation" }, passenger_phone: { type: "string", description: "Passenger phone number with country code" }, payment_method: { type: "string", description: "Payment method (e.g. 'credit_card', 'debit_card', 'paypal')" }, }, required: [ "flight_id", "passenger_first_name", "passenger_last_name",