add_to_cart
Add food items to your DoorDash cart for checkout by specifying store, menu, item details, and quantity.
Instructions
Add an item to your DoorDash cart
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| storeId | Yes | Store ID | |
| menuId | Yes | Menu ID | |
| itemId | Yes | Item ID from the menu | |
| itemName | Yes | Item name | |
| unitPrice | Yes | Price in cents (e.g. 1540 for $15.40) | |
| quantity | No | Quantity to add | |
| currency | No | Currency code (e.g. USD, CAD) | USD |
Implementation Reference
- mcp-server.js:152-193 (handler)Handler function that executes the add_to_cart tool logic. Calls the GraphQL mutation to add an item to the cart, processes the response, and returns formatted cart information including cartId, store name, subtotal, and items.
async ({ storeId, menuId, itemId, itemName, unitPrice, quantity, currency }) => { const result = await graphql("addCartItem", queries.ADD_CART_ITEM, { addCartItemInput: { storeId, menuId, itemId, itemName, quantity, nestedOptions: "[]", specialInstructions: null, substitutionPreference: "substitute", isBundle: false, bundleType: "BUNDLE_TYPE_UNSPECIFIED", unitPrice, cartId: "", currency, }, fulfillmentContext: { shouldUpdateFulfillment: false, fulfillmentType: null }, monitoringContext: { isGroup: false }, cartContext: {}, returnCartFromOrderService: false, shouldKeepOnlyOneActiveCart: false, }); const cart = result?.data?.addCartItemV2; if (!cart) return { content: [{ type: "text", text: "Failed to add item" }] }; const items = []; for (const order of cart.orders || []) { for (const oi of order.orderItems || []) { items.push({ name: oi.item?.name, quantity: oi.quantity, total: oi.priceOfTotalQuantity, totalDisplay: `$${(oi.priceOfTotalQuantity / 100).toFixed(2)}`, }); } } return { content: [{ type: "text", text: JSON.stringify({ cartId: cart.id, store: cart.restaurant?.name, subtotal: cart.subtotal, subtotalDisplay: `$${(cart.subtotal / 100).toFixed(2)}`, currency: cart.currencyCode, items, }, null, 2), }], }; } ); - mcp-server.js:143-151 (schema)Input schema definition using Zod for the add_to_cart tool. Defines parameters: storeId, menuId, itemId, itemName, unitPrice (in cents), quantity (defaults to 1), and currency (defaults to USD).
{ storeId: z.string().describe("Store ID"), menuId: z.string().describe("Menu ID"), itemId: z.string().describe("Item ID from the menu"), itemName: z.string().describe("Item name"), unitPrice: z.number().describe("Price in cents (e.g. 1540 for $15.40)"), quantity: z.number().default(1).describe("Quantity to add"), currency: z.string().default("USD").describe("Currency code (e.g. USD, CAD)"), }, - mcp-server.js:140-193 (registration)Tool registration with the MCP server using server.tool(). Registers 'add_to_cart' with description, input schema, and handler function.
server.tool( "add_to_cart", "Add an item to your DoorDash cart", { storeId: z.string().describe("Store ID"), menuId: z.string().describe("Menu ID"), itemId: z.string().describe("Item ID from the menu"), itemName: z.string().describe("Item name"), unitPrice: z.number().describe("Price in cents (e.g. 1540 for $15.40)"), quantity: z.number().default(1).describe("Quantity to add"), currency: z.string().default("USD").describe("Currency code (e.g. USD, CAD)"), }, async ({ storeId, menuId, itemId, itemName, unitPrice, quantity, currency }) => { const result = await graphql("addCartItem", queries.ADD_CART_ITEM, { addCartItemInput: { storeId, menuId, itemId, itemName, quantity, nestedOptions: "[]", specialInstructions: null, substitutionPreference: "substitute", isBundle: false, bundleType: "BUNDLE_TYPE_UNSPECIFIED", unitPrice, cartId: "", currency, }, fulfillmentContext: { shouldUpdateFulfillment: false, fulfillmentType: null }, monitoringContext: { isGroup: false }, cartContext: {}, returnCartFromOrderService: false, shouldKeepOnlyOneActiveCart: false, }); const cart = result?.data?.addCartItemV2; if (!cart) return { content: [{ type: "text", text: "Failed to add item" }] }; const items = []; for (const order of cart.orders || []) { for (const oi of order.orderItems || []) { items.push({ name: oi.item?.name, quantity: oi.quantity, total: oi.priceOfTotalQuantity, totalDisplay: `$${(oi.priceOfTotalQuantity / 100).toFixed(2)}`, }); } } return { content: [{ type: "text", text: JSON.stringify({ cartId: cart.id, store: cart.restaurant?.name, subtotal: cart.subtotal, subtotalDisplay: `$${(cart.subtotal / 100).toFixed(2)}`, currency: cart.currencyCode, items, }, null, 2), }], }; } ); - src/queries.js:64-83 (helper)GraphQL mutation query ADD_CART_ITEM that is used by the add_to_cart handler to add items to the DoorDash cart via the addCartItemV2 mutation.
const ADD_CART_ITEM = `mutation addCartItem($addCartItemInput: AddCartItemInput!, $fulfillmentContext: FulfillmentContextInput!, $cartContext: CartContextInput, $returnCartFromOrderService: Boolean, $monitoringContext: MonitoringContextInput, $shouldKeepOnlyOneActiveCart: Boolean) { addCartItemV2( addCartItemInput: $addCartItemInput fulfillmentContext: $fulfillmentContext cartContext: $cartContext returnCartFromOrderService: $returnCartFromOrderService monitoringContext: $monitoringContext shouldKeepOnlyOneActiveCart: $shouldKeepOnlyOneActiveCart ) { id subtotal currencyCode restaurant { id name slug } orders { orderItems { id quantity priceOfTotalQuantity item { id name price imageUrl } } } } }`; - src/browser.js:77-101 (helper)Helper function graphql() that executes GraphQL queries by making fetch requests to the DoorDash GraphQL endpoint. Used by add_to_cart handler to call the ADD_CART_ITEM mutation.
async function graphql(operationName, query, variables = {}) { const page = await ensureOnDoordash(); const result = await page.evaluate( async ({ operationName, query, variables }) => { const res = await fetch( `/graphql/${operationName}?operation=${operationName}`, { method: "POST", headers: { "content-type": "application/json" }, credentials: "include", body: JSON.stringify({ operationName, variables, query }), } ); return { status: res.status, body: await res.json() }; }, { operationName, query, variables } ); if (result.status !== 200) { throw new Error(`GraphQL ${operationName} failed: ${result.status}`); } return result.body; }