Skip to main content
Glama

checkout

Complete flight bookings or preview details before purchase. Use confirm=true only with explicit user approval to finalize transactions.

Instructions

Complete the flight booking. IMPORTANT: Set confirm=true only when you have explicit user confirmation to purchase. Without confirm=true, returns a preview of the booking details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
confirmNoSet to true to actually complete the purchase. If false or omitted, returns a preview only. NEVER set to true without explicit user confirmation.

Implementation Reference

  • The checkout tool handler function that executes the booking logic. It supports two modes: preview mode (confirm=false) which returns booking details without purchasing, and confirmation mode (confirm=true) which completes the purchase by clicking the purchase button and extracting the confirmation number.
    export async function checkout(params: { confirm: boolean }): Promise<
      | BookingResult
      | {
          requiresConfirmation: true;
          preview: BookingPreview;
        }
    > {
      const { page } = await initBrowser();
    
      if (!params.confirm) {
        // Return a preview without actually booking
        const preview = await page.evaluate(() => {
          const passengers: string[] = [];
          const passengerEls = document.querySelectorAll(
            '[class*="passenger"], [data-testid*="passenger"]'
          );
          passengerEls.forEach((el) =>
            passengers.push(el.textContent?.trim() || "")
          );
    
          const totalPriceEl = document.querySelector(
            '[class*="total"], [data-testid*="total-price"], .trip-total'
          );
          const totalPrice = totalPriceEl?.textContent?.trim();
    
          return {
            passengers: passengers.filter(Boolean),
            totalPrice,
          };
        });
    
        return {
          requiresConfirmation: true,
          preview: {
            ...preview,
            flights: cachedFlightResults.slice(0, 2).map((f) => ({
              flightNumber: f.flightNumber,
              route: `${f.origin} → ${f.destination}`,
              date: f.departureTime,
              cabin: f.cabinClass || "Main Cabin",
            })),
          },
        };
      }
    
      // Attempt to complete booking
      try {
        // Look for "Purchase" or "Book" button
        const purchaseBtn = await page.$(
          'button:has-text("Purchase"), button:has-text("Book Now"), button:has-text("Complete Purchase"), [data-testid="purchase-btn"]'
        );
    
        if (!purchaseBtn) {
          throw new Error(
            "Could not find purchase button. You may need to complete all booking steps first."
          );
        }
    
        await purchaseBtn.click();
        await randomDelay(3000, 6000);
    
        // Wait for confirmation page
        await page
          .waitForSelector('[class*="confirmation"], [data-testid*="confirmation"]', {
            timeout: 30000,
          })
          .catch(() => {});
    
        // Extract confirmation number
        const confirmationNumber = await page.evaluate(() => {
          const confEl = document.querySelector(
            '[class*="confirmation-number"], [data-testid*="confirmation"], .booking-ref'
          );
          return confEl?.textContent?.trim();
        });
    
        // Save updated cookies after booking
        const { context } = await initBrowser();
        await saveCookies(context);
    
        return {
          success: true,
          confirmationNumber: confirmationNumber || "See your email for confirmation",
          message: "Booking completed successfully! Check your email for details.",
        };
      } catch (error) {
        const msg = error instanceof Error ? error.message : String(error);
        return {
          success: false,
          message: `Booking failed: ${msg}`,
        };
      }
    }
  • Type definitions for the checkout tool's return types. BookingResult defines the success/failure response with confirmation details, and BookingPreview defines the preview information shown before confirming purchase.
    export interface BookingResult {
      confirmationNumber?: string;
      success: boolean;
      message: string;
      totalPrice?: string;
      requiresConfirmation?: boolean;
      preview?: BookingPreview;
    }
    
    export interface BookingPreview {
      passengers?: string[];
      flights?: Array<{
        flightNumber: string;
        route: string;
        date: string;
        cabin: string;
      }>;
      seats?: string[];
      bags?: string;
      extras?: string[];
      totalPrice?: string;
    }
  • src/index.ts:249-262 (registration)
    Tool registration defining the checkout tool's name, description, and input schema. The schema specifies a 'confirm' boolean parameter that controls whether to preview or complete the booking.
      name: "checkout",
      description:
        "Complete the flight booking. IMPORTANT: Set confirm=true only when you have explicit user confirmation to purchase. Without confirm=true, returns a preview of the booking details.",
      inputSchema: {
        type: "object",
        properties: {
          confirm: {
            type: "boolean",
            description:
              "Set to true to actually complete the purchase. If false or omitted, returns a preview only. NEVER set to true without explicit user confirmation.",
          },
        },
      },
    },
  • The request handler that routes checkout tool calls to the checkout function. It extracts the confirm parameter, calls the handler, and formats the response based on whether confirmation is required.
    case "checkout": {
      const { confirm = false } = (args as { confirm?: boolean }) || {};
    
      const result = await checkout({ confirm });
    
      if ("requiresConfirmation" in result) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  success: true,
                  requiresConfirmation: result.requiresConfirmation,
                  preview: result.preview,
                  note: "Call checkout with confirm=true to complete the purchase. IMPORTANT: Only do this after getting explicit user confirmation.",
                },
                null,
                2
              ),
            },
          ],
        };
      }
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                success: result.success,
                confirmationNumber: result.confirmationNumber,
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It clearly explains the dual behavior (purchase vs preview) and the critical safety requirement for user confirmation before purchase. However, it doesn't mention error conditions, response format, or what happens after purchase completion.

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. The first states the purpose, the second provides critical usage guidance. Every word earns its place, and the structure is front-loaded with the most important information.

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 single-parameter tool with 100% schema coverage but no annotations or output schema, the description provides excellent context about the tool's dual behavior and safety requirements. The main gap is lack of information about return values or error conditions, but given the simplicity of the tool, this is a minor omission.

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%, so the schema already fully documents the single 'confirm' parameter. The description reinforces the parameter's purpose but doesn't add meaningful semantic information beyond what's in the schema description. Baseline 3 is appropriate when schema does the heavy lifting.

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 clearly states the specific action ('Complete the flight booking') and distinguishes it from siblings like 'search_flights' or 'select_seat' by focusing on the final purchase step. It explicitly mentions both the purchase action and preview functionality.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use the tool: 'Set confirm=true only when you have explicit user confirmation to purchase' and clarifies the alternative behavior: 'Without confirm=true, returns a preview.' This directly addresses when to use each mode of the tool.

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-delta'

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