MCP server project (TypeScript) · 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 a booking only after the member said yes in the Parda 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
- TypeScript
- In the all labs plan
The first 2 chapters of MCP server project (TypeScript) are free. This one comes with the all labs plan.
Why you need this
Neha made a read-only token in chapter 7 for the assistant on her office laptop: it may look at showtimes, never book. Today that token books. The scopes are stored, and the SDK checks parda.read, but no tool looks at the others. With chapter 7's code and pmcp_lab_neha_readonly_2026:
{"result":{"content":[...],"structuredContent":{"showtime_id":18,"seats":["E1","E2"],"held_until":"Sat 24 Oct, 5:43 pm"}},"jsonrpc":"2.0","id":1}
{"result":{"content":[...],"structuredContent":{"booking_id":2,"status":"pending","seats":"E1, E2","total":400,"showtime_id":18,"name":"Ghar Wapsi Express, Sat 7 Nov, 6:45 pm"}},"jsonrpc":"2.0","id":1}
A real hold and a real booking, ₹400. Paying is next. This chapter adds pay_booking, which takes the money from the member's Parda wallet. Datta's rule is that every rupee an assistant moves has the member's own yes behind it, and one yes pays once. On the website a member once pressed Pay twice and paid twice, and Datta 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.ts: what a token may do
Write isReadOnly, check and annotationsFor in src/mcp/permissions.ts. isReadOnly(tool) is true when SCOPE_OF[tool] is parda.read. check(member, tool) returns when the member's scopes include the tool's scope, and otherwise throws ToolError("This token may not use <tool>: it needs the <scope> scope. The member can make a token with it in the Parda app."), or ToolError("<tool> has no scope: nobody may call it") for a tool not in SCOPE_OF. annotationsFor(tool) returns { readOnlyHint, destructiveHint, idempotentHint, openWorldHint }: read-only and idempotent for read-only tools, destructive only for pay_booking, never open world.
The Check calls check and annotationsFor for every tool, reads the annotations in tools/list, then sends POST /mcp with Neha's read-only lab token: find_showtimes works, hold_seats comes back as a tool error with your sentence.
- Task 2
approvals.ts: asking, and the member's answer
Write ask and decide in src/mcp/approvals.ts. ask(userId, bookingId, amount) returns the member's open approval (pending or approved) for that booking and amount, or inserts and returns a new pending one. decide(userId, approvalId, approve), in a transaction, selects the member's own approval .for('update'), throws notFound for anyone else's or a missing one and conflict not_pending once it is decided, and otherwise sets status approved or declined and decidedAt, returning the row.
The Check asks twice for Neha's booking (the same approval), once for another amount (a new one), approves and declines as Neha, approves twice (409), decides Neha's as Pranav (404), and approves through POST /mcp/approvals/<id>/approve.
- Task 3 · interview question
Interview: approvals.ts, taken once
Write take(userId, bookingId, amount) in src/mcp/approvals.ts. In a transaction, it selects the member's approved approval for that booking and amount .for('update'), marks it used with usedAt and returns it; with none it returns null.
The Check holds a lock on an approved approval in a transaction of its own and uses it while your take waits (take must wait, then find nothing), takes an approval twice (the second gives null), then pays a booking end to end through MCP as Neha: approval_needed, the yes in the app, paid, and a third pay_booking that finds nothing to pay.
Nikhil will ask: why can't pay_booking 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_booking asks, the member decides in the app, pay_booking takes the approval and pays.
- A row lock: SELECT ... FOR UPDATE, Drizzle's .for('update'), and the real race it stops.
More in One member at a time
Build "Permissions and approval" yourself
Parda wants AI assistants like Claude Desktop to book seats 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 (TypeScript) are free. This one comes with the all labs plan.