Skip to main content
Glama

add_to_cart

Add alcohol products to your Drizly shopping cart by specifying product ID, name, quantity, and price for purchase preparation.

Instructions

Add a product to the shopping cart

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
productIdYesProduct ID to add
nameYesProduct name
quantityYesQuantity to add (minimum 1)
priceYesPrice per unit
imageUrlNoProduct image URL (optional)

Implementation Reference

  • MCP tool handler for 'add_to_cart' - validates input using AddToCartSchema, creates a DrizlyCartItem object, calls the addToCart method, and returns a JSON response with success message and updated cart
    case "add_to_cart": {
      const params = AddToCartSchema.parse(args);
      const cartItem: DrizlyCartItem = {
        productId: params.productId,
        name: params.name,
        quantity: params.quantity,
        price: params.price,
        imageUrl: params.imageUrl,
      };
      const cart = drizly.addToCart(cartItem);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                message: `Added ${params.quantity}x ${params.name} to cart`,
                cart,
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • Core business logic implementation - adds item to cart or increments quantity if already exists, recalculates cart totals, returns updated cart state
    addToCart(product: DrizlyCartItem): DrizlyCart {
      const existingIndex = this.cart.items.findIndex((i) => i.productId === product.productId);
    
      if (existingIndex >= 0) {
        this.cart.items[existingIndex].quantity += product.quantity;
      } else {
        this.cart.items.push({ ...product });
      }
    
      this.recalculateCart();
      return this.cart;
    }
  • Zod schema definition for validating add_to_cart tool input parameters - requires productId, name, quantity (min 1), and price; imageUrl is optional
    const AddToCartSchema = z.object({
      productId: z.string().describe("Product ID to add to cart"),
      name: z.string().describe("Product name"),
      quantity: z.number().int().min(1).describe("Quantity to add"),
      price: z.number().describe("Price per unit"),
      imageUrl: z.string().optional().describe("Product image URL"),
    });
  • TypeScript interface defining the structure of a cart item used by the addToCart implementation
    export interface DrizlyCartItem {
      productId: string;
      name: string;
      quantity: number;
      price: number;
      imageUrl?: string;
    }
  • src/index.ts:175-189 (registration)
    MCP tool registration - defines the tool name, description, and JSON Schema for input validation in the ListToolsRequestSchema handler
    {
      name: "add_to_cart",
      description: "Add a product to the shopping cart",
      inputSchema: {
        type: "object",
        properties: {
          productId: { type: "string", description: "Product ID to add" },
          name: { type: "string", description: "Product name" },
          quantity: { type: "number", description: "Quantity to add (minimum 1)" },
          price: { type: "number", description: "Price per unit" },
          imageUrl: { type: "string", description: "Product image URL (optional)" },
        },
        required: ["productId", "name", "quantity", "price"],
      },
    },
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 ('Add') but doesn't explain key behaviors: whether this requires authentication, if it modifies existing cart items or creates new ones, potential side effects (e.g., inventory updates), or error conditions. This is inadequate for a mutation tool with zero annotation coverage.

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 that directly states the tool's purpose without unnecessary words. It's front-loaded and wastes no space, making it easy to parse quickly.

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 mutation tool with no annotations and no output schema, the description is insufficient. It doesn't cover behavioral aspects like authentication needs, error handling, or what the tool returns (e.g., success confirmation or updated cart). Given the complexity of cart operations and lack of structured data, more context is needed.

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 input schema fully documents all parameters (productId, name, quantity, price, imageUrl). The description adds no additional meaning beyond what's in the schema, such as explaining relationships between parameters or usage examples. 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 action ('Add') and resource ('a product to the shopping cart'), making the purpose immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'update_cart' or 'place_order', which also involve cart modifications, leaving some ambiguity about when to use each.

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 'update_cart' or 'place_order'. It lacks context about prerequisites (e.g., whether the product must be available or in stock) or exclusions, leaving the agent to infer usage from the 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/markswendsen-code/mcp-drizly'

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