update_cart
Modify item quantities in your shopping cart or remove products entirely by setting quantity to zero.
Instructions
Update the quantity of an item in the cart or remove it (set quantity to 0)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productId | Yes | Product ID to update | |
| quantity | Yes | New quantity (set to 0 to remove from cart) |
Implementation Reference
- src/index.ts:457-474 (handler)The handler for the 'update_cart' tool. It parses input parameters using UpdateCartSchema, calls drizly.updateCart() to perform the update, and returns a message indicating whether the product was updated or removed from the cart.
case "update_cart": { const params = UpdateCartSchema.parse(args); const cart = drizly.updateCart(params.productId, params.quantity); const message = params.quantity === 0 ? `Removed product ${params.productId} from cart` : `Updated product ${params.productId} quantity to ${params.quantity}`; return { content: [ { type: "text", text: JSON.stringify({ message, cart }, null, 2), }, ], }; } - src/index.ts:64-67 (schema)Zod schema definition for the update_cart tool input parameters. Validates productId (string) and quantity (non-negative integer).
const UpdateCartSchema = z.object({ productId: z.string().describe("Product ID to update"), quantity: z.number().int().min(0).describe("New quantity (0 to remove)"), }); - src/index.ts:198-215 (registration)Registration of the 'update_cart' tool with its name, description, and JSON Schema input specification defining productId and quantity properties.
{ name: "update_cart", description: "Update the quantity of an item in the cart or remove it (set quantity to 0)", inputSchema: { type: "object", properties: { productId: { type: "string", description: "Product ID to update", }, quantity: { type: "number", description: "New quantity (set to 0 to remove from cart)", }, }, required: ["productId", "quantity"], }, }, - src/browser.ts:418-430 (helper)The updateCart method in the Drizly class that performs the actual cart update logic. Removes item if quantity is 0, otherwise updates the quantity and recalculates cart totals.
updateCart(productId: string, quantity: number): DrizlyCart { if (quantity <= 0) { this.cart.items = this.cart.items.filter((i) => i.productId !== productId); } else { const item = this.cart.items.find((i) => i.productId === productId); if (item) { item.quantity = quantity; } } this.recalculateCart(); return this.cart; }