MCP server project · Chapter 11 of 12

Testing the server

By the end of this chapter you can test DabbaDrop's MCP server the way an assistant uses it, with the SDK's client in memory and pytest, 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
  • 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

Launch week starts tomorrow, and the server will keep changing: Farah wants a dinner slot, Kunal wants to tidy member.py, Rafiq wants refunds. Three promises must survive every change:

  • Tara's 12:30 is 12:30. find_slots for a time gives that slot and no other.
  • Each member sees only their own orders. Advait's paid order 1 is never in Tara's list.
  • No rupee moves without the member's yes. Rafiq answers for every payment an assistant makes.

Chapter 10's eval does not guard any of them. It measures which tool a model chooses, not what the tool then does. On a copy of the server whose find_slots ignores the time, the eval still says:

$ python -m mcp_server.evals
Passed 12 of 12 (100%)

Every assistant would get all three Tuesday slots for "12:30", and the first one is 12:00. Only a test that calls the tool and checks the answer sees that. In this chapter you write three, one per promise.

What you build: 3 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    test_mcp_server.py: find_slots keeps to the time

    Write test_find_slots_keeps_to_the_time in tests/test_mcp_server.py: through the mcp fixture as Tara, find_slots for Thane on 2026-11-03 at 12:30 must give only slot 80.

    The Check runs your tests on the server as it is (this one must pass), then on a server whose find_slots ignores the time (this one must fail).

  2. Task 2

    test_mcp_server.py: only the member's own orders

    Write test_list_my_orders_shows_only_the_members_own: as Advait, list_my_orders gives only order 1; as Tara, order 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 Tara (it must fail).

  3. Task 3 · interview question

    Interview: test_mcp_server.py, payment waits for a yes

    Write test_pay_order_waits_for_the_members_yes: as Tara, place 2 Jain Thali in slot 80 (dish 25); the first pay_order answers status approval_needed and the order is still pending in the orders table; after approve(Tara's id, the approval_id), pay_order answers paid and the order is confirmed.

    The Check runs it on the server as it is (it must pass), then on a server whose pay_order pays at once (it must fail).

    Kunal 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 server in memory, with no port and no token.
  • Async tests: pytest's anyio marker, and what happens without it.
  • The conftest's MCP fixtures: mcp, members, sql, approve.
  • Reading a result in a test: is_error, structured_content, content.
  • Mutants: breaking the server on purpose to see whether a test notices.

More in Ready for every assistant

Build "Testing the server" 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.