Skip to main content
Glama

woolworths_add_to_cart

Add products to your Woolworths shopping cart using product stockcodes. Specify quantity to manage your online grocery items for checkout.

Instructions

Add a product to the shopping cart/trolley

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stockcodeYesThe product stockcode/ID to add
quantityNoQuantity to add (default: 1)

Implementation Reference

  • The handler function that executes the tool logic: adds the specified product (by stockcode) and quantity to the Woolworths shopping cart by posting to the trolley update API endpoint.
    async function handleAddToCart(args: any): Promise<any> {
      const stockcode = args.stockcode;
      const quantity = args.quantity ?? 1;
    
      const url = `https://www.woolworths.com.au/api/v3/ui/trolley/update`;
    
      try {
        const data = await makeWoolworthsRequest(url, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            items: [
              {
                stockcode,
                quantity,
                source: "ProductDetail",
                diagnostics: "0",
                searchTerm: null,
                evaluateRewardPoints: false,
                offerId: null,
                profileId: null,
                priceLevel: null,
              },
            ],
          }),
        });
        return {
          success: true,
          cart: data,
        };
      } catch (error: any) {
        return {
          success: false,
          error: error.message,
        };
      }
    }
  • src/index.ts:144-161 (registration)
    Registration of the tool in the TOOLS array used for listing tools, including name, description, and input schema.
      name: "woolworths_add_to_cart",
      description: "Add a product to the shopping cart/trolley",
      inputSchema: {
        type: "object",
        properties: {
          stockcode: {
            type: "number",
            description: "The product stockcode/ID to add",
          },
          quantity: {
            type: "number",
            description: "Quantity to add (default: 1)",
            default: 1,
          },
        },
        required: ["stockcode"],
      },
    },
  • src/index.ts:655-657 (registration)
    Registration/dispatch of the tool handler in the main switch statement for tool calls.
    case "woolworths_add_to_cart":
      result = await handleAddToCart(args || {});
      break;
  • Supporting utility function to perform authenticated fetch requests to Woolworths APIs, using session cookies; called by the add-to-cart handler.
    async function makeWoolworthsRequest(
      url: string,
      options: any = {}
    ): Promise<any> {
      if (sessionCookies.length === 0) {
        throw new Error(
          "No session cookies available. Please use woolworths_get_cookies first."
        );
      }
    
      const headers = {
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
        Accept: "*/*",
        "Accept-Language": "en-US,en;q=0.9",
        Origin: "https://www.woolworths.com.au",
        Referer: "https://www.woolworths.com.au/",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        Priority: "u=1, i",
        Cookie: getCookieHeader(),
        ...options.headers,
      };
    
      const response = await fetch(url, {
        ...options,
        headers,
      });
    
      if (!response.ok) {
        const errorText = await response.text();
        throw new Error(
          `API request failed: ${response.status} ${response.statusText}. ${errorText}`
        );
      }
    
      return response.json();
    }
Behavior2/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 states the action but fails to mention critical details such as whether this requires authentication, if it modifies server-side state, potential error conditions (e.g., invalid stockcode), or side effects. This leaves the agent with insufficient information to predict tool behavior safely.

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, direct sentence that efficiently conveys the core functionality without unnecessary words. It is front-loaded with the essential action, making it easy for an agent to parse quickly. Every word earns its place, achieving optimal conciseness.

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?

Given the lack of annotations and output schema, the description is incomplete for a mutation tool. It does not cover behavioral aspects like authentication needs, error handling, or response format, which are crucial for an agent to use the tool effectively. The high schema coverage mitigates some gaps but not enough for a complex operation like adding to a cart.

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 clear documentation for both parameters (stockcode and quantity). The description adds no additional semantic context beyond what the schema provides, such as examples of valid stockcodes or constraints on quantity. This meets the baseline for adequate parameter documentation but does not enhance understanding.

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 action ('Add') and the target ('product to the shopping cart/trolley'), making the purpose immediately understandable. However, it does not differentiate this tool from its sibling 'woolworths_update_cart_quantity', which could also modify cart contents, leaving room for ambiguity in tool selection.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'woolworths_update_cart_quantity' or 'woolworths_remove_from_cart'. It lacks context about prerequisites (e.g., needing an active session) or typical workflows, leaving the agent to infer usage from the tool name alone.

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/elijah-g/Woolworths-mcp'

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