Skip to main content
Glama

get_delivery_options

Check delivery and warehouse pickup availability for Costco items by entering your ZIP code. Optionally specify an item number to verify availability for specific products.

Instructions

Check delivery and warehouse pickup availability for cart items or a specific product

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
zip_codeYesZIP code to check delivery options
item_numberNoCostco item number to check availability for (optional, checks cart if omitted)

Implementation Reference

  • The handleGetDeliveryOptions function implements the tool logic. It navigates to a product page (if itemNumber provided) or the cart page, enters the ZIP code, and scrapes delivery options including warehouse pickup availability and online delivery information.
    async function handleGetDeliveryOptions(zipCode: string, itemNumber?: string) {
      return withPage(async (page: Page) => {
        // If itemNumber provided, check product page; otherwise check cart
        if (itemNumber) {
          await page.goto(`https://www.costco.com/p.${itemNumber}.product.html`, {
            waitUntil: "domcontentloaded",
            timeout: 30000,
          });
        } else {
          await page.goto("https://www.costco.com/CheckoutCartDisplayView", {
            waitUntil: "domcontentloaded",
            timeout: 30000,
          });
        }
        await page.waitForTimeout(2000);
    
        // Try to enter zip code for delivery estimate
        try {
          const zipInputEl = await page.$(
            'input[placeholder*="ZIP" i], input[name*="zip" i], input[id*="zip" i]'
          );
          if (zipInputEl) {
            await zipInputEl.fill(zipCode);
            await zipInputEl.press("Enter");
            await page.waitForTimeout(2000);
          }
        } catch {
          // Continue without zip entry
        }
    
        const deliveryInfo = await page.evaluate(() => {
          const deliveryEls = Array.from(
            document.querySelectorAll(
              '[class*="delivery"], [class*="shipping"], [automation-id*="delivery"], [automation-id*="shipping"]'
            )
          );
    
          const options: string[] = [];
          for (const el of deliveryEls) {
            const text = el.textContent?.trim();
            if (text && text.length > 5 && text.length < 300) {
              options.push(text);
            }
          }
    
          // Check for warehouse pickup availability
          const warehouseEl = document.querySelector(
            '[class*="warehouse-pickup"], [class*="in-warehouse"], [automation-id*="warehouse"]'
          );
          const warehouseText = warehouseEl?.textContent?.trim() ?? "";
    
          // Check online delivery
          const onlineDeliveryEl = document.querySelector(
            '[class*="online-only"], [class*="delivery-available"], [automation-id*="online-delivery"]'
          );
          const onlineDeliveryText = onlineDeliveryEl?.textContent?.trim() ?? "";
    
          return { options: options.slice(0, 5), warehouseText, onlineDeliveryText };
        });
    
        const lines = [`**Delivery Options for ZIP: ${zipCode}**\n`];
    
        if (deliveryInfo.warehouseText) {
          lines.push(`Warehouse Pickup: ${deliveryInfo.warehouseText}`);
        }
        if (deliveryInfo.onlineDeliveryText) {
          lines.push(`Online Delivery: ${deliveryInfo.onlineDeliveryText}`);
        }
        if (deliveryInfo.options.length > 0) {
          lines.push(`\nDelivery details:`);
          deliveryInfo.options.forEach((opt) => lines.push(`  - ${opt}`));
        }
    
        if (lines.length === 1) {
          lines.push("No delivery options found. Please check the Costco website directly.");
        }
    
        return ok(lines.join("\n"));
      });
    }
  • Tool schema definition for 'get_delivery_options' with inputSchema specifying zip_code (required) and item_number (optional) parameters, along with the tool description.
      name: "get_delivery_options",
      description: "Check delivery and warehouse pickup availability for cart items or a specific product",
      inputSchema: {
        type: "object",
        properties: {
          zip_code: {
            type: "string",
            description: "ZIP code to check delivery options",
          },
          item_number: {
            type: "string",
            description: "Costco item number to check availability for (optional, checks cart if omitted)",
          },
        },
        required: ["zip_code"],
      },
    },
  • src/index.ts:325-329 (registration)
    The tool call routing in the CallToolRequestSchema handler that maps 'get_delivery_options' to the handleGetDeliveryOptions function with zip_code and item_number arguments.
    case "get_delivery_options":
      return await handleGetDeliveryOptions(
        a.zip_code as string,
        a.item_number as string | undefined
      );
  • Helper functions ok() and err() used by handleGetDeliveryOptions to format successful responses and error messages.
    function ok(text: string) {
      return { content: [{ type: "text" as const, text }] };
    }
    
    function err(text: string) {
      return { content: [{ type: "text" as const, text: `Error: ${text}` }], isError: true };
    }
  • The withPage helper function used by handleGetDeliveryOptions to execute browser automation in a managed context with stealth scripting and session cookie handling.
    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();
      }
    }

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