MCP server project (TypeScript) · Chapter 11 of 12
Testing the server
By the end of this chapter you can test Parda's MCP server the way an assistant uses it, with the SDK's client in memory and Vitest, read a tool's result in a test, check the database behind an answer, and tell a test that protects the server from one that only passes. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Ready for every assistant
- 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
Diwali week opens on Friday, and the server will keep changing after it: Datta wants refunds, Sayali wants more tools, Nikhil wants to tidy member.ts. Three promises must survive every change:
- Neha's evening is the evening. find_showtimes for the evening gives the evening's showtimes and no others.
- Each member sees only their own bookings. Pranav's paid booking 1 is never in Neha's list.
- No rupee moves without the member's yes. Datta answers for every rupee an assistant moves.
Chapter 10's eval guards none of them. It measures which tool a model chooses, not what the tool then does. On a copy of the server whose find_showtimes ignores part_of_day, the eval still says:
$ npm run evals
Passed 12 of 12 (100%)
Every assistant would then get all three Saturday showtimes of Pune 52 for "the evening", and the first one starts at 12:15 pm. Neha and her husband would book a lunch show. Only a test that calls the tool and reads the answer sees that. In this chapter you write three tests, one per promise.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
mcp.test.ts: find_showtimes keeps to the part of the day
Write the test "find_showtimes keeps to the part of the day" in tests/mcp.test.ts: through lab.connect('neha'), find_showtimes for 2026-11-07, title Pune 52, part_of_day evening must give only showtime 17.
The Check runs your tests on the server as it is (this one must pass), then on a server whose find_showtimes ignores part_of_day (this one must fail).
- Task 2
mcp.test.ts: only the member's own bookings
Write the test "list_my_bookings shows only the member's own bookings": as Pranav, list_my_bookings gives only booking 1; as Neha, booking 1 is not among hers.
The Check runs it on the server as it is (it must pass), then on a server where every call acts for Neha (it must fail).
- Task 3 · interview question
Interview: mcp.test.ts, payment waits for a yes
Write the test "pay_booking waits for the member's yes": as Neha, hold E1 and E2 of showtime 18 and book them; the first pay_booking answers status approval_needed and the booking is still pending in the bookings table; after lab.approve(2, the approval_id), pay_booking answers paid and the booking is confirmed.
The Check runs it on the server as it is (it must pass), then on a server whose pay_booking pays at once (it must fail).
Nikhil will ask: the evals passed last chapter. Why write tests too? What does each catch that the other cannot?
What you will learn
- Testing over MCP: the SDK's Client on a new server in memory, with no port and no token.
- The test helpers: mcpTest(), lab.connect, lab.sql, lab.approve.
- Reading a result in a test: isError, structuredContent, content.
- Exact assertions: toEqual on a list of ids, and not.toContain.
- Mutants: breaking the server on purpose to see whether a test notices.
More in Ready for every assistant
Build "Testing the server" 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.