MCP server project (TypeScript) · Chapter 5 of 12
Prompts
By the end of this chapter your server offers two ready-made requests a member picks in their assistant: plan_outing, which asks for a weekend show with the day's real programme in it, and book_again, which books an earlier booking again. Both refuse bad arguments with a sentence the member can act on, never a bare internal error. 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
- 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
On Friday and Saturday evenings in October, members asked their assistants to find a show for the weekend, each in their own words. Datta counted 31 such outings booked through an assistant, and 11 went wrong: two seats far apart (E7 and E12) for a couple, a Hindi show for a family that wanted Marathi, prices from a programme pasted in September, a booking made before the member had chosen, and one assistant that tried to pay. The words were different every time, and each assistant guessed the programme.
Sayali wants one request, written once by Parda: "plan an outing", with the day's programme inside it and the rules spelled out (suggest first, seats side by side, never pay). Neha should pick it from a list, fill in how many people and which day, and send it.
Tools and resources cannot do that. A tool is chosen by the model and a resource by the app. Nobody asks the member. MCP's third kind of thing, the prompt, is the one the member chooses.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
prompts.ts: plan_outing
Register the prompt plan_outing in addPrompts (title Plan an outing, argsSchema people as z.string(), day and language as optional strings, defaulting to saturday and any). It returns one user message: "Plan an outing for <n> on <Sat 7 Nov>: one show, <n> seats side by side." with " We would like a <Language> show." added unless the language is any, an empty line, the day's programme from programmeMarkdown, an empty line, then "First suggest two or three showtimes with their prices. When I choose one, use see_seats to find <n> free seats side by side, then hold_seats and book_seats. Never pay: I approve payments in the Parda app." The date is nextDay(today(), the day): the next one after the server's today.
The Check lists the prompts through an MCP client (plan_outing with people required, day and language optional) and gets plan_outing for 2 people in Marathi (Sat 7 Nov, with Saturday's programme), for 4 with no other argument, and for 3 on " Friday " in HINDI.
- Task 2
prompts.ts: book_again
Register the prompt book_again(booking_id) in addPrompts (title Book this again). From the member's bookings (GET /bookings/me) and the names of the showtimes (showtimeNames), it returns a user message "Book my booking <id> again: <title>, <n> seats (<seats>). Ask me which day and time I want." and an assistant message "Happy to. Booking <id> was <title>, <n> seats (<seats>) on <startsAt>. Which day would you like, and what time of day?"
The Check gets book_again for Pranav's booking 1 as Pranav (Ghar Wapsi Express, E7 and E8, Fri 6 Nov, 12:15 pm) through an MCP client.
- Task 3 · interview question
Interview: prompts.ts, arguments are text
In both prompts, refuse bad arguments first with throw badArgument(sentence): plan_outing's day not in DAYS ("day must be one of: friday, saturday, sunday"), people not a whole number from 1 to 6 ("people must be a whole number from 1 to 6"), language not in LANGUAGES ("language must be one of: Marathi, Hindi, English, any"); book_again's booking_id not digits ("booking_id must be a number, like 1") or not the member's ("You have no booking <id>").
The Check gets the prompts with a day of monday, people of "two", "0", "9" and "2.5", a language of tamil, a booking_id of "one", and Pranav's booking 1 asked for as Neha: each must be error -32602 with your sentence.
Nikhil will ask: who picks a prompt, the model, the app or the member? And why does people arrive as "2", not 2?
What you will learn
- Prompts and who picks them: the member, from a list (often a slash command).
- prompts/list and prompts/get on the wire: arguments, required or not, and the messages that come back.
- registerPrompt and its argsSchema, with .optional() for an argument that may be left out.
- User and assistant messages, and why a prompt may return both.
- Arguments are always text: what the protocol allows, and what z.number() and z.coerce.number() do with what a member types.
- badArgument: error -32602 with your sentence, against a bare internal error.
More in What the server offers
Build "Prompts" 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.