MCP server project · Chapter 8 of 12
Permissions and approval
By the end of this chapter a token does only what its scopes allow, and says so in a sentence the assistant can pass on; every tool tells the host whether it only reads or can do harm; and an assistant can pay for an order only after the member said yes in the DabbaDrop app, once, even when two payments arrive at the same moment. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: One member at a time
- 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
Tara made a read-only token in chapter 7 for the assistant on her office laptop: it may look at menus, never book. Today that token books. The scopes are stored, and the SDK checks dabba.read, but no tool looks at the others: place_order with dmcp_lab_tara_readonly_2026 places a real order.
Paying is next. This chapter adds pay_order, which takes the money from the member's DabbaDrop wallet. Rafiq's rule is that every rupee an assistant moves has the member's own yes behind it, and one yes pays once. In the WhatsApp pilot a member pressed Pay twice and paid twice, and Rafiq refunded it by hand. With assistants it is more likely: an assistant that does not get an answer quickly will often simply call the tool again.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
permissions.py: what a token may do
Write is_read_only, check and annotations_for in mcp_server/permissions.py. is_read_only(tool) is True when SCOPE_OF[tool] is dabba.read. check(member, tool) returns when the member's scopes include the tool's scope, and otherwise raises ToolError("This token may not use <tool>: it needs the <scope> scope. The member can make a token with it in the DabbaDrop app."), or ToolError("<tool> has no scope: nobody may call it") for a tool not in SCOPE_OF. annotations_for(tool) returns ToolAnnotations with read_only_hint and idempotent_hint for read-only tools, destructive_hint only for pay_order, and open_world_hint False.
The Check calls check and annotations_for for every tool, reads the annotations in tools/list, then sends POST /mcp with Tara's read-only lab token: find_slots works, place_order and pay_order come back as tool errors with your sentence.
- Task 2
approvals.py: asking, and the member's answer
Write ask and decide in mcp_server/approvals.py. ask(db, user_id, order_id, amount) returns the member's open approval (pending or approved) for that order and amount, or adds and commits a new pending one. decide(db, user_id, approval_id, approve) locks the member's own approval, raises not_found for anyone else's or a missing one and conflict not_pending once it is decided, and otherwise sets status approved or declined and decided_at, and commits.
The Check asks twice for Tara's order (the same approval), once for another amount (a new one), approves and declines as Tara, approves twice (409), and approves Tara's as Advait (404).
- Task 3 · interview question
Interview: approvals.py, taken once
Write take(db, user_id, order_id, amount) in mcp_server/approvals.py. It locks the member's approved approval for that order and amount (with_for_update), marks it used with used_at and commits, and returns it; with none it rolls back and returns None.
The Check holds a lock on an approved approval in a transaction of its own while your take runs in a thread (take must wait for it), then pays an order end to end through MCP as Tara: approval_needed, the yes in the app (POST /mcp/approvals/<id>/approve), paid, and a second pay_order that finds nothing to pay.
Kunal will ask: why can't pay_order take an argument approved=true, which the assistant sets once the member says yes in the chat?
What you will learn
- Scopes per tool: one scope for each tool, and refusing with a sentence instead of hiding the tool.
- Tool annotations: hints a host reads (read only, idempotent, destructive), and what they are not.
- The member's yes: why it must come from a screen the model cannot write to, not from the chat.
- The approval flow: pay_order asks, the member decides in the app, pay_order takes the approval and pays.
- A row lock: SELECT ... FOR UPDATE and the real race it stops.
More in One member at a time
Build "Permissions and approval" 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.