Order food end-to-end
The canonical 7-tool Food journey - from address to placed order to delivery tracking.
The full food-ordering journey across Swiggy's Food MCP server. Pays by COD; to take payment with UPI instead, see Pay with UPI. ₹1000 cart cap. Pseudo-code in TypeScript; the same sequence works in any framework. Each step reads the tool's data with readToolData from Read tool results, which returns structuredContent and throws on a failed call.
The flow
get_addresses
│
▼
search_restaurants ──► get_restaurant_menu
│
▼
update_food_cart ◄── fetch_food_coupons
│ │
▼ │
get_food_cart ◄── apply_food_coupon
│
▼
place_food_order
│
▼
track_food_order
Step 1 - Resolve the delivery address
const { addresses, resolution } = readToolData(
await client.callTool({ name: "get_addresses", arguments: {} }),
);
const home =
addresses.find((a) => a.id === resolution.defaultAddressId) ??
addresses.find((a) => a.addressCategory === "Home") ??
addresses[0];
if (!home) throw new Error("User has no saved addresses; prompt them to add one.");
If the user has no saved addresses, walk them through create_address — coordinates are optional; the server geocodes from the address.
get_addresses returns each address's id, addressLine, and addressCategory (Home, Work, ...), plus a resolution.defaultAddressId suggestion - never raw coordinates.
Step 2 - Find restaurants
const { restaurants } = readToolData(
await client.callTool({
name: "search_restaurants",
arguments: { addressId: home.id, query: "biryani" },
}),
);
const restaurant = restaurants.find((r) => r.availabilityStatus === "OPEN");
if (!restaurant) throw new Error("No open restaurants match; try another query.");
Check availabilityStatus for each result - only recommend those marked "OPEN". Sort by a mix of distance and rating; always surface distance when picking far restaurants so the user isn't surprised.
Step 3 - Browse the menu
const menu = readToolData(
await client.callTool({
name: "get_restaurant_menu",
arguments: { addressId: home.id, restaurantId: restaurant.id },
}),
);
// Categories are either flat ({ items }) or nested ({ subcategories: [{ items }] })
const items = menu.categories.flatMap((c) => c.items ?? c.subcategories.flatMap((s) => s.items));
const dish = items.find((i) => i.inStock);
Menus are paginated by category (hasMore, page) and have items, variants, and add-ons. Use search_menu for keyword search within (or across) restaurants.
Step 4 - Build the cart
readToolData(
await client.callTool({
name: "update_food_cart",
arguments: {
addressId: home.id,
restaurantId: restaurant.id,
restaurantName: restaurant.name,
cartItems: [{ menu_item_id: dish.id, quantity: 1 }],
},
}),
);
Cart is tied to a single restaurant. Changing restaurant flushes the cart. Use flush_food_cart explicitly when the user starts over.
Step 5 - Apply a coupon (optional)
// fetch_food_coupons already returns only coupons valid for COD, which this recipe pays by
const { coupon_sections } = readToolData(
await client.callTool({
name: "fetch_food_coupons",
arguments: { restaurantId: restaurant.id, addressId: home.id },
}),
);
const coupon = coupon_sections.flatMap((s) => s.coupons).find((c) => c.applicable);
if (coupon) {
// The coupon's `id` is its code
readToolData(
await client.callTool({
name: "apply_food_coupon",
arguments: { couponCode: coupon.id, addressId: home.id },
}),
);
}
Step 6 - Confirm and place the order
const cart = readToolData(
await client.callTool({
name: "get_food_cart",
arguments: { addressId: home.id, restaurantName: restaurant.name },
}),
);
// Swiggy v1: hard ₹1000 cap on Builders Club orders
if (cart.data.pricing.to_pay > 1000) {
throw new Error("Cart exceeds ₹1000 cap - ask user to reduce items.");
}
// Surface to the user before placing
// "Your order is: <items>. Total ₹<total>. Place now? (yes / no)"
const order = readToolData(
await client.callTool({
name: "place_food_order",
arguments: { addressId: home.id, paymentMethod: "Cash" }, // Cash = COD
}),
);
Critical: place_food_order is not idempotent. If it fails with 5xx, call get_food_orders to check if the order actually placed before retrying. See ship to production.
Step 7 - Track the order
const { orders } = readToolData(
await client.callTool({
name: "track_food_order",
arguments: { orderId: order.orderId },
}),
);
// orders[0].orderStatus, orders[0].etaText
// Poll no faster than every 10 seconds; delivery-partner ETA updates arrive at that cadence
Full agent prompt
Good system prompt for the agent driving this flow:
What can go wrong
Until the symbolic error-code registry ships (see errors), classify by error.message text and HTTP status. Expect:
- Restaurant closed between search and order → re-run
search_restaurants. - Coupon requires online payment → not usable on the COD path; filter upstream, or pay with UPI.
- Minimum order not met → prompt user to add items.
- Upstream shedding / timeout → exponential backoff; capacity questions go to rate-limits.