- https://medium.com/@anil.goyal0057/the-complete-guide-to-testing-mcp-server-applications-a-three-layer-test-pyramid-for-ai-powered-027e941be6d4
- Type: article
- Source: Anil Goyal, Medium
TL;DR
MCP Inspector tells you a tool works; it cannot tell you the agent picks the right tool. The three layers are unit tests on the @mcp.tool() functions with the service layer mocked, integration tests over the real server, and evals that assert on what the LLM chose — including tool order, extracted arguments, iteration count and duration.
Summary
The article starts from a real gap. Inspector connects to the server, lists tools, invokes each one and shows the response — genuinely useful while building. But it validates Tool → Response and not Prompt → Agent → LLM decision → Tool call → Response → Answer. So it cannot catch a wrong tool choice, a bad tool description, a wrong call sequence in a multi-step workflow, or broken multi-turn context.
Layer 1 — unit. Call the tool function directly; mock the service. Fast, deterministic, catches logic errors and mapping bugs. Explicitly not testing the protocol or the model.
Layer 2 — integration. Real FastMCP server, real transport, so serialization, schemas and startup are exercised. This is where “the server does not even boot” and “the schema is wrong” get caught.
Layer 3 — evals. The part that is new for most teams: assert on agent behaviour, not on function output. The examples use mcp-eval with a YAML config and @pytest.mark.task-style registration, and the assertions read like specifications: Expect.tools.sequence([...]) for a CRUD chain, Expect.tools.was_called_with(...) for argument extraction, Expect.tools.count("create_plant", 1) for no duplicate calls, Expect.performance.max_iterations(3) and max_duration(30) for cost and latency budgets. Each layer answers a question the one below cannot.
Key takeaways
- Assert on tool selection, not just tool output. “The agent should choose
get_plantoverlist_plantsfor one ID” is a testable claim and the most common real bug. - Tool descriptions are part of the contract. If the description is vague, the eval fails — and that failure is a prompt bug, not a code bug.
- Sequence and count assertions catch the expensive failures: duplicate calls, loops, missing steps in a workflow.
- Budgets belong in tests.
max_iterationsandmax_durationturn “it felt slow” into a regression test. - The pyramid matters because the layers are cheap in different ways. Unit tests are milliseconds; evals are money — run them on a schedule or on PRs touching prompts.
Tools and concepts
| Item | Role in the page |
|---|---|
| Model Context Protocol | The protocol the server under test speaks |
| AI Agents | Where the mcp-eval row lives |
| MCP Inspector | Official interactive debugger; validates tool → response only |
| FastMCP | Python framework used for the example server |
mcp-eval | Eval framework for layer three: tool choice, order, arguments, budgets |
When to use
As soon as an MCP server has more than two tools and something that matters calls it. Layer 1 belongs in every commit; layer 2 whenever the schema or transport changes; layer 3 whenever a tool description changes or an agent misbehaves — a failing eval there usually means the description was ambiguous, not that the model was dumb. Skip layer 3 only while the server is a prototype nobody else depends on.
Caveats
- Evals on an LLM are non-deterministic: the article does not address flakiness, retries, or how many runs count as a pass.
- The example stack is specific (
fastmcp+mcp-evalin Python); the layering transfers, the code does not. - No numbers: no accuracy thresholds, no cost per eval run.
- Worth pairing with the
mcp-evalrepo itself (row in AI Agents) rather than trusting the snippets.