doordash_add_to_cart
Add menu items to your DoorDash cart for restaurants using item names or convenience store products using item IDs, with options for customizing quantities and selections.
Instructions
Add an item to your DoorDash cart. For restaurants, pass item_name. For convenience stores, pass item_id directly.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| store_id | Yes | DoorDash store ID | |
| item_name | Yes | Item name (used for restaurant menu lookup) | |
| item_id | No | Item ID for convenience store items | |
| quantity | No | Quantity (default 1) | |
| options | No | JSON array of selected options. Flat: [{"id":"123","name":"Chicken"}]. Nested (for items like burritos where toppings go inside the filling): [{"id":"123","name":"Chicken","children":[{"id":"456","name":"Brown Rice"},{"id":"789","name":"Sour Cream"}]}] | |
| unit_price | No | Price in cents (for convenience store items) | |
| cart_id | No | Cart ID to add to | |
| external_user_id | No | External user ID for group order guest session (e.g. Slack user ID). Must call doordash_join_group_order first. |
Implementation Reference
- src/tools/index.ts:297-432 (handler)Handler implementation for doordash_add_to_cart, which handles both restaurant and convenience store add-to-cart logic.
server.registerTool( "doordash_add_to_cart", { description: "Add an item to your DoorDash cart. For restaurants, pass item_name. For convenience stores, pass item_id directly.", inputSchema: { store_id: z.string().describe("DoorDash store ID"), item_name: z .string() .describe("Item name (used for restaurant menu lookup)"), item_id: z .string() .optional() .describe("Item ID for convenience store items"), quantity: z .number() .optional() .default(1) .describe("Quantity (default 1)"), options: z .string() .optional() .describe( 'JSON array of selected options. Flat: [{"id":"123","name":"Chicken"}]. Nested (for items like burritos where toppings go inside the filling): [{"id":"123","name":"Chicken","children":[{"id":"456","name":"Brown Rice"},{"id":"789","name":"Sour Cream"}]}]', ), unit_price: z .number() .optional() .describe("Price in cents (for convenience store items)"), cart_id: z.string().optional().describe("Cart ID to add to"), external_user_id: z .string() .optional() .describe( "External user ID for group order guest session (e.g. Slack user ID). Must call doordash_join_group_order first.", ), }, }, ({ store_id, item_name, item_id, quantity, options, unit_price, cart_id, external_user_id, }) => wrap(async () => { const guest = external_user_id ? api.guests.getSession(external_user_id) : undefined; if (external_user_id && !guest) { return err( `No guest session for user "${external_user_id}". Call doordash_join_group_order first.`, ); } const cartApi = guest?.cart ?? api.cart; let resolvedId = item_id ?? ""; let resolvedName = item_name; let resolvedPrice = unit_price ?? 0; let menuId = ""; let nestedOpts = "[]"; if (!resolvedId) { // Restaurant flow: look up item from menu const menu = await api.menu.getStoreMenu(store_id); let found: any = null; const nameLower = item_name.toLowerCase(); // Prefer exact match, then substring match for (const cat of menu.categories) { for (const item of cat.items) { if (item.name.toLowerCase() === nameLower) { found = item; break; } } if (found) break; } if (!found) { for (const cat of menu.categories) { for (const item of cat.items) { if (item.name.toLowerCase().includes(nameLower)) { found = item; break; } } if (found) break; } } if (!found) { const names = menu.categories .flatMap((c) => c.items.map((i) => i.name)) .slice(0, 10); return err( `Item "${item_name}" not found. Try: ${names.join(", ")}`, ); } resolvedId = found.id; resolvedName = found.name; resolvedPrice = found.quickAddPrice; menuId = menu.menuId; nestedOpts = found.quickAddNestedOptions; } if (options) { nestedOpts = JSON.stringify( JSON.parse(options).map((o: any) => buildNestedOption(o)), ); } const result = await cartApi.addToCart({ storeId: store_id, itemId: resolvedId, itemName: resolvedName, menuId, quantity, nestedOptions: nestedOpts, unitPrice: resolvedPrice, cartId: cart_id, isGroupGuest: !!guest, }); const subtotal = `$${(result.subtotal / 100).toFixed(2)}`; const qtyNote = result.itemQuantity > quantity ? ` (cart now has ${result.itemQuantity}x total)` : ""; return ok( `Added ${quantity}x **${resolvedName}**${qtyNote}. Subtotal: ${subtotal}. Cart ID: ${result.cartId}`, ); }), );