MCP server project · Chapter 3 of 12
Tools with schemas
By the end of this chapter DabbaDrop's server offers four tools: find_dish, find_slots, place_order and list_my_orders. Each argument has a type, a description and limits that the assistant reads in tools/list and that the SDK checks before your code runs, and each result has a shape of its own. An assistant can find Tara's Jain Thali, book 2 for Tuesday 12:30 in Thane (order 2, ₹550), and cannot order 50. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: What the server offers
- 3 tasks
- Python
- In the all labs plan
The first 2 chapters of MCP server project are free. This one comes with the all labs plan.
Why you need this
The October integrations went wrong in small ways that cost real money. The office script once sent "zone": "Thane West", a zone DabbaDrop does not have. Another asked for dabbas at "12:45", between two slots. And when a member wrote "dabbas for the whole team", an integration asked for 50 Jain Thali in one order, ₹13,030 with delivery, and Rafiq had to cancel and refund it by hand.
Chapter 1's find_slots cannot prevent any of that. Look at what an assistant reads about it in tools/list today: {"title": "Zone", "type": "string"}. Any string at all. The assistant has to guess the six zones, guess the slot times, and nothing says how many dabbas is too many. Farah wants the server to say the rules, so a model can follow them, and to keep them, so a model that does not follow them is stopped before anything is held or ordered.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
models.py: the arguments' types and the results' shapes
Write the types and models in mcp_server/models.py. Zone is a Literal of the six zones, Day a date, Time a Literal of 12:00, 12:30 and 13:00 or None, Diet a Literal of veg, jain and non-veg or None, DishName a str of at most 40 characters or None, SlotId, DishId and OrderId ints greater than 0, Quantity an int from 1 to 10, each Annotated with a Field description. Dish has dish_id, price, category and name; Slot has slot_id, starts_at, ends_at and places_left; Order has order_id, name, status, total, delivery_fee and slot_id, in those orders.
The Check reads the input schemas the SDK writes from your types in tools/list (find_slots' zone is an enum of the six zones, with a description; place_order's quantity has a minimum of 1 and a maximum of 10), checks values against each type, and reads find_slots' output schema.
- Task 2
tools/menu.py: find_dish
Write find_dish(zone, dish_name=None, diet=None) in mcp_server/tools/menu.py. As the member (member_api), it finds the zone's kitchen with zone_named, gets GET /dishes with kitchen_id, limit 50, and q and category only when dish_name and diet are given, and returns a Dish for each item (dish_id from id).
The Check calls find_dish through an MCP client: the Jain dishes in Thane (23, 24 and 25), the thalis in Goregaon, everything in Dadar (a limit of 50 gets all 9), and Powai, which the schema refuses.
- Task 3 · interview question
Interview: tools/orders.py, place_order and list_my_orders
Write place_order(slot_id, dish_id, quantity) and list_my_orders() in mcp_server/tools/orders.py. place_order holds a place (POST /holds) and then orders (POST /orders with the slot and one item), letting go of the hold (DELETE /holds/{slot_id}) and raising the ApiError again when the order is refused; it returns order_of(the order). list_my_orders returns order_of each order of GET /orders/me.
The Check books 2 Jain Thali in slot 80 through an MCP client (order 2, ₹550 with ₹30 delivery), lists Tara's orders, sends quantity 50 (refused before your code runs) and Dal Tadka from Andheri Kitchen in Thane's slot (the API refuses it), and wants no hold left behind.
Kunal will ask: an assistant sent quantity 50. Which code stopped it, and what did the assistant read back?
What you will learn
- JSON schema: the part of tools/list that describes a tool's arguments, and what a model learns from it.
- Schemas from type hints: Literal, date, int with limits, str | None, and Annotated with Field for descriptions and limits.
- What the SDK checks before a tool runs: Pydantic validates every call's arguments, and a bad one never reaches your function.
- Result models: Pydantic models as a tool's return type, and the output schema the SDK writes from them.
- A tool that changes something: place_order holds a place, then orders, and gives the place back when the order is refused.
More in What the server offers
Build "Tools with schemas" yourself
DabbaDrop wants AI assistants like Claude Desktop to order for its members, safely. You build the MCP server that lets them, and only as the member who allowed it. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of MCP server project are free. This one comes with the all labs plan.