doordash_modify_cart
Change item quantities or remove items from a DoorDash cart to update orders before checkout.
Instructions
Modify cart: change item quantity or remove items.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cart_id | Yes | Cart ID | |
| item_id | Yes | Item ID from doordash_cart | |
| action | Yes | Action to perform | |
| quantity | No | New quantity (for update_quantity) | |
| store_id | No | Store ID (auto-detected if not specified) | |
| external_user_id | No | External user ID for group order guest session |
Implementation Reference
- src/tools/index.ts:461-484 (registration)Registration of the 'doordash_modify_cart' tool, including its description and input schema.
server.registerTool( "doordash_modify_cart", { description: "Modify cart: change item quantity or remove items.", inputSchema: { cart_id: z.string().describe("Cart ID"), item_id: z.string().describe("Item ID from doordash_cart"), action: z .enum(["update_quantity", "remove"]) .describe("Action to perform"), quantity: z .number() .optional() .describe("New quantity (for update_quantity)"), store_id: z .string() .optional() .describe("Store ID (auto-detected if not specified)"), external_user_id: z .string() .optional() .describe("External user ID for group order guest session"), }, }, - src/tools/index.ts:485-549 (handler)The handler function implementation for 'doordash_modify_cart', which modifies the cart item quantity or removes items.
({ cart_id, item_id, action, quantity, store_id, external_user_id }) => wrap(async () => { const guest = external_user_id ? api.guests.getSession(external_user_id) : undefined; const cartApi = guest?.cart ?? api.cart; if (action === "remove") { await cartApi.removeItem(cart_id, item_id); const carts = await api.cart.listCarts(); const remaining = carts.find((c) => c.id === cart_id)?.items.length ?? 0; return ok(`Item removed. ${remaining} items remaining in cart.`); } if (action === "update_quantity") { if (!quantity || quantity < 1) return err("Quantity must be at least 1."); const carts = await api.cart.listCarts(); const targetCart = carts.find((c) => c.id === cart_id); const targetItem = targetCart?.items.find((i) => i.id === item_id); if (!targetItem) return err("Item not found in cart."); const sid = store_id ?? targetCart?.storeId ?? ""; // Remove then re-add (updateCartItemV2 is broken) await api.cart.removeItem(cart_id, item_id); try { const result = await api.cart.addToCart({ storeId: sid, itemId: targetItem.menuItemId, itemName: targetItem.name, quantity, nestedOptions: targetItem.nestedOptions ? JSON.stringify(targetItem.nestedOptions) : "[]", unitPrice: targetItem.price, cartId: cart_id, specialInstructions: targetItem.specialInstructions, }); return ok( `Updated **${targetItem.name}** to ${quantity}x. Subtotal: $${(result.subtotal / 100).toFixed(2)}. Cart ID: ${result.cartId}`, ); } catch { // Cart may have been deleted when last item removed — retry without cartId const result = await api.cart.addToCart({ storeId: sid, itemId: targetItem.menuItemId, itemName: targetItem.name, quantity, nestedOptions: targetItem.nestedOptions ? JSON.stringify(targetItem.nestedOptions) : "[]", unitPrice: targetItem.price, cartId: "", specialInstructions: targetItem.specialInstructions, }); return ok( `Updated **${targetItem.name}** to ${quantity}x. Subtotal: $${(result.subtotal / 100).toFixed(2)}. Cart ID: ${result.cartId}`, ); } } return err(`Unknown action: ${action}`);