Skip to main content
Glama

check_warehouse_stock

Check product availability at specific Costco warehouses using item numbers or URLs and ZIP codes to find nearby locations.

Instructions

Check in-warehouse availability of a product at a specific Costco location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
item_numberNoCostco item number
urlNoProduct URL (alternative to item_number)
zip_codeNoZIP code to find nearby warehouses

Implementation Reference

  • The handleCheckWarehouseStock function implements the tool logic. It navigates to a Costco product page, optionally sets a ZIP code location, scrapes warehouse availability information from the page, and returns stock status with details about which warehouses have the item in stock.
    async function handleCheckWarehouseStock(
      itemNumber?: string,
      url?: string,
      zipCode?: string
    ) {
      if (!itemNumber && !url) {
        return err("Provide either item_number or url");
      }
    
      return withPage(async (page: Page) => {
        const productUrl = url ?? `https://www.costco.com/p.${itemNumber}.product.html`;
    
        await page.goto(productUrl, {
          waitUntil: "domcontentloaded",
          timeout: 30000,
        });
        await page.waitForTimeout(2000);
    
        // Try to set location if zip code provided
        if (zipCode) {
          try {
            const locationBtn = await page.$(
              '[class*="warehouse-picker"], [automation-id="warehouse-picker-btn"], button[aria-label*="warehouse" i]'
            );
            if (locationBtn) {
              await locationBtn.click();
              await page.waitForTimeout(1000);
    
              const zipInput = await page.waitForSelector(
                'input[placeholder*="ZIP" i], input[name*="zip" i]',
                { timeout: 5000 }
              );
              await zipInput.fill(zipCode);
              await zipInput.press("Enter");
              await page.waitForTimeout(2000);
            }
          } catch {
            // Continue without location update
          }
        }
    
        const stockInfo = await page.evaluate(() => {
          // Check for warehouse availability section
          const warehouseSection = document.querySelector(
            '[class*="warehouse-availability"], [automation-id="warehouse-availability"], [class*="in-warehouse"]'
          );
    
          if (!warehouseSection) {
            // Check if item is online-only
            const onlineOnly = document.querySelector(
              '[class*="online-only"], [automation-id="online-only"]'
            );
    
            const availabilityText =
              document.querySelector('[class*="availability"], [automation-id*="availability"]')
                ?.textContent?.trim()?.slice(0, 300) ?? "";
    
            return {
              available: false,
              onlineOnly: !!onlineOnly,
              details: availabilityText || "Warehouse availability information not found on this page.",
              warehouses: [],
            };
          }
    
          const isAvailable =
            !warehouseSection.textContent?.toLowerCase().includes("not available") &&
            !warehouseSection.textContent?.toLowerCase().includes("out of stock");
    
          const warehouseEls = Array.from(
            document.querySelectorAll('[class*="warehouse-name"], [automation-id="warehouse-name"]')
          );
          const warehouses = warehouseEls
            .map((el) => el.textContent?.trim() ?? "")
            .filter(Boolean)
            .slice(0, 5);
    
          return {
            available: isAvailable,
            onlineOnly: false,
            details: warehouseSection.textContent?.trim()?.slice(0, 300) ?? "",
            warehouses,
          };
        });
    
        const lines = [
          `**Warehouse Stock Check — Item #${itemNumber ?? "from URL"}**\n`,
        ];
    
        if (stockInfo.onlineOnly) {
          lines.push("Status: Online-only item — not available in warehouses");
        } else {
          lines.push(
            `Status: ${stockInfo.available ? "Available in warehouse" : "Not available in warehouse"}`
          );
        }
    
        if (zipCode) lines.push(`ZIP: ${zipCode}`);
    
        if (stockInfo.warehouses.length > 0) {
          lines.push(`\nWarehouses with stock:`);
          stockInfo.warehouses.forEach((w) => lines.push(`  - ${w}`));
        }
    
        if (stockInfo.details) {
          lines.push(`\nDetails: ${stockInfo.details}`);
        }
    
        lines.push(`\nURL: ${page.url()}`);
    
        return ok(lines.join("\n"));
      });
    }
  • src/index.ts:257-276 (registration)
    Tool registration (schema definition) for 'check_warehouse_stock'. Defines the tool name, description, and inputSchema with properties for item_number, url, and zip_code parameters.
      name: "check_warehouse_stock",
      description: "Check in-warehouse availability of a product at a specific Costco location",
      inputSchema: {
        type: "object",
        properties: {
          item_number: {
            type: "string",
            description: "Costco item number",
          },
          url: {
            type: "string",
            description: "Product URL (alternative to item_number)",
          },
          zip_code: {
            type: "string",
            description: "ZIP code to find nearby warehouses",
          },
        },
      },
    },
  • src/index.ts:353-358 (registration)
    Handler dispatch in the CallToolRequestSchema switch statement. Routes incoming 'check_warehouse_stock' tool calls to the handleCheckWarehouseStock function with extracted arguments.
    case "check_warehouse_stock":
      return await handleCheckWarehouseStock(
        a.item_number as string | undefined,
        a.url as string | undefined,
        a.zip_code as string | undefined
      );
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral context. It doesn't disclose whether this is a read-only operation, requires authentication, has rate limits, returns structured data, or handles errors. 'Check' suggests a query, but lacks details on what 'availability' means (e.g., binary yes/no, quantity levels).

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 a single, efficient sentence with zero wasted words. It front-loads the core purpose ('Check in-warehouse availability') and specifies the resource and context directly. Every element earns its place.

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

Completeness2/5

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

For a tool with 3 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what 'availability' returns (e.g., stock status, quantities), whether authentication is needed, or how to interpret results. The lack of behavioral context leaves significant gaps for an agent.

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 parameters are documented in the schema. The description adds no additional meaning beyond implying 'zip_code' identifies the 'specific Costco location', which is already clear from schema descriptions. Baseline 3 is appropriate as the schema handles parameter documentation.

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 ('Check in-warehouse availability') and resource ('product at a specific Costco location'), distinguishing it from siblings like 'get_product_details' (general info) or 'get_warehouse_locations' (location data). It precisely defines the tool's scope as inventory checking for physical stores.

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

Usage Guidelines3/5

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

The description implies usage for checking product stock at warehouses, but provides no explicit guidance on when to use this versus alternatives like 'get_delivery_options' or 'search_products'. It doesn't mention prerequisites (e.g., needing a location) or exclusions (e.g., not for online stock).

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