Skip to main content
Glama

checkout

Preview or complete Costco orders with browser automation. Use confirm=false to preview before finalizing purchases.

Instructions

Preview or complete a Costco order. Use confirm=false to preview first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
confirmNoSet true to actually place the order. Default false (preview only).

Implementation Reference

  • The handleCheckout function implements the checkout tool logic. It validates user login status, retrieves cart contents from Costco, displays an order summary with items, subtotal, tax, and total. When confirm=true, it navigates to checkout and attempts to place the order, returning order confirmation details.
    async function handleCheckout(confirm: boolean) {
      if (!isLoggedIn()) {
        return err("Not logged in. Use the `login` tool first.");
      }
    
      return withPage(async (page: Page) => {
        await page.goto("https://www.costco.com/CheckoutCartDisplayView", {
          waitUntil: "domcontentloaded",
          timeout: 30000,
        });
        await page.waitForTimeout(2000);
    
        const cartSummary = await page.evaluate(() => {
          const items = Array.from(
            document.querySelectorAll('.cart-item, [automation-id="cart-item"], [class*="cart-item"]')
          ).map((item) => {
            const title =
              item.querySelector('[automation-id="cart-item-name"], .item-name')?.textContent?.trim() ?? "";
            const price =
              item.querySelector('[automation-id="cart-item-price"], .price')?.textContent?.trim() ?? "";
            const qty =
              (item.querySelector('[automation-id="cart-item-qty"], input[name*="qty"]') as HTMLInputElement | null)
                ?.value?.trim() ?? "1";
            return `${title} (x${qty}) — ${price}`;
          });
    
          const subtotal =
            document.querySelector('[automation-id="order-subtotal"], .subtotal')?.textContent?.trim() ?? "";
          const tax =
            document.querySelector('[automation-id="order-tax"], .tax')?.textContent?.trim() ?? "";
          const total =
            document.querySelector('[automation-id="order-total"], .order-total')?.textContent?.trim() ?? "";
    
          return { items, subtotal, tax, total };
        });
    
        if (cartSummary.items.length === 0) {
          return err("Cart is empty. Add items before checking out.");
        }
    
        const summary = [
          `**Order Summary (${cartSummary.items.length} item${cartSummary.items.length !== 1 ? "s" : ""})**\n`,
          ...cartSummary.items.map((item, i) => `${i + 1}. ${item}`),
          "",
          cartSummary.subtotal ? `Subtotal: ${cartSummary.subtotal}` : "",
          cartSummary.tax ? `Tax: ${cartSummary.tax}` : "",
          cartSummary.total ? `Total: ${cartSummary.total}` : "",
        ].filter(Boolean);
    
        if (!confirm) {
          return ok(
            summary.join("\n") +
            "\n\n⚠️  This is a preview. Call `checkout` with `confirm: true` to place the order."
          );
        }
    
        // Proceed to checkout
        const checkoutBtn = await page.waitForSelector(
          '[automation-id="checkout-btn"], button[class*="checkout"], a[href*="checkout" i]',
          { timeout: 10000 }
        );
        await checkoutBtn.click();
        await page.waitForTimeout(3000);
    
        const currentUrl = page.url();
        if (!currentUrl.toLowerCase().includes("checkout")) {
          return err(
            "Failed to navigate to checkout. May require additional verification."
          );
        }
    
        // Try to place order
        const placeOrderBtn = await page.$(
          '[automation-id="place-order-btn"], button[class*="place-order"], button[id*="placeOrder"]'
        );
        if (!placeOrderBtn) {
          return ok(
            summary.join("\n") +
            "\n\n⚠️  Reached checkout page but could not auto-submit. Please complete manually at: " +
            currentUrl
          );
        }
    
        await placeOrderBtn.click();
        await page.waitForTimeout(5000);
    
        const confirmationUrl = page.url();
        const orderConfirmation = await page.evaluate(() => {
          const orderNum = document.querySelector(
            '[automation-id="order-number"], [class*="order-number"], [class*="orderNumber"]'
          )?.textContent?.trim();
          return { orderNum };
        });
    
        return ok(
          summary.join("\n") +
          "\n\n✅ Order placed successfully!\n" +
          (orderConfirmation.orderNum ? `Order #: ${orderConfirmation.orderNum}\n` : "") +
          `Confirmation URL: ${confirmationUrl}`
        );
      });
    }
  • src/index.ts:188-201 (registration)
    Registration of the 'checkout' tool in the MCP server's ListToolsRequestSchema handler. Defines the tool name, description, and inputSchema with a 'confirm' boolean parameter to control whether to preview or place the order.
      name: "checkout",
      description: "Preview or complete a Costco order. Use confirm=false to preview first.",
      inputSchema: {
        type: "object",
        properties: {
          confirm: {
            type: "boolean",
            description:
              "Set true to actually place the order. Default false (preview only).",
          },
        },
        required: [],
      },
    },
  • src/index.ts:336-337 (registration)
    Routing logic in the CallToolRequestSchema handler that maps the 'checkout' tool name to the handleCheckout function, passing the confirm parameter.
    case "checkout":
      return await handleCheckout(a.confirm === true);
  • The withPage helper function manages Playwright browser context and page lifecycle. It creates a new page, adds stealth scripts to avoid bot detection, executes the provided function, saves session cookies, and ensures proper cleanup.
    export async function withPage<T>(
      fn: (page: Page) => Promise<T>,
      headless = true
    ): Promise<T> {
      const ctx = await getBrowserContext(headless);
      const page = await ctx.newPage();
      await page.addInitScript(STEALTH_INIT_SCRIPT);
      try {
        const result = await fn(page);
        await saveSessionCookies();
        return result;
      } finally {
        await page.close();
      }
    }
  • The isLoggedIn helper function checks if the user is authenticated by verifying that both cookies.json and auth.json files exist in the session directory.
    export function isLoggedIn(): boolean {
      return fs.existsSync(COOKIES_FILE) && fs.existsSync(AUTH_FILE);
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the preview/completion behavior and the confirm parameter's effect, which is useful. However, it lacks critical details: whether this requires authentication (vs. 'login'), what happens on completion (e.g., payment, confirmation), error conditions, or side effects. For a mutation tool with zero annotation coverage, this is insufficient.

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?

The description is extremely concise and front-loaded: two sentences that directly state the purpose and key usage guideline. Every word earns its place, with no redundancy or fluff, making it efficient for an AI agent to parse quickly.

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

Completeness3/5

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

Given the tool's complexity (order processing with potential mutations), lack of annotations, and no output schema, the description is minimally adequate. It covers the core action and parameter guidance but omits details on authentication needs, return values, error handling, or integration with siblings like 'view_cart'. This leaves gaps for safe and effective use.

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 the parameter 'confirm' fully documented in the schema. The description adds minimal value beyond the schema by reiterating the preview/completion logic ('Use confirm=false to preview first'), but doesn't provide additional syntax, format, or contextual nuances. This meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Preview or complete a Costco order.' It specifies the verb ('preview or complete') and resource ('Costco order'), making the action unambiguous. However, it doesn't explicitly differentiate from siblings like 'add_to_cart' or 'update_cart' in terms of order lifecycle stage, which prevents a perfect score.

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

Usage Guidelines4/5

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

The description provides clear context for when to use the tool: 'Use confirm=false to preview first.' This implies a two-step workflow (preview then complete) and suggests default behavior. However, it doesn't explicitly state when NOT to use it or name alternatives among siblings (e.g., vs. 'add_to_cart' for earlier stages), missing full differentiation.

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

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