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
| Name | Required | Description | Default |
|---|---|---|---|
| productId | Yes | Product ID to add | |
| name | Yes | Product name | |
| quantity | Yes | Quantity to add (minimum 1) | |
| price | Yes | Price per unit | |
| imageUrl | No | Product image URL (optional) |
Implementation Reference
- src/index.ts:409-435 (handler)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 ), }, ], }; } - src/browser.ts:401-412 (handler)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; } - src/index.ts:56-62 (schema)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"), }); - src/browser.ts:32-38 (schema)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"], }, },