Skip to main content
Glama

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
NameRequiredDescriptionDefault
storeIdYesStore ID
menuIdYesMenu ID
itemIdYesItem ID from the menu
itemNameYesItem name
unitPriceYesPrice in cents (e.g. 1540 for $15.40)
quantityNoQuantity to add
currencyNoCurrency code (e.g. USD, CAD)USD

Implementation Reference

  • 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),
          }],
        };
      }
    );
  • 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),
          }],
        };
      }
    );
  • 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 }
          }
        }
      }
    }`;
  • 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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Add an item' implies a write/mutation operation, it doesn't disclose important behavioral traits: whether this requires authentication, if it modifies existing cart state, what happens on duplicate items, error conditions, or what the response looks like. For a mutation tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero wasted words. It's appropriately sized for this tool and front-loads the essential information. Every word earns its place in conveying the core purpose efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 7 parameters, no annotations, and no output schema, the description is incomplete. It doesn't address authentication requirements, error handling, response format, or how this integrates with the cart management workflow involving sibling tools. The agent lacks sufficient context to use this tool effectively in real scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 7 parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema. It doesn't explain relationships between parameters (e.g., that storeId, menuId, and itemId should be consistent) or provide usage examples. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add an item') and target ('to your DoorDash cart'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'remove_from_cart' or explain how it relates to 'list_carts' in terms of cart management workflow.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (like needing to be logged in via 'login_check'), how it interacts with 'list_carts' for viewing cart contents, or when to use 'remove_from_cart' instead. There's no context about when this operation is appropriate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SpunkySarb/doordash-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server