Topic 5 of 5 · 5 min read
Testing servers with MCP Inspector and scripted clients
Goal: Read an Inspector or test-client log and identify whether a failing call comes from the schema, the handler or the transport.
Test a server in three layers before a model touches it: look at it by hand in MCP Inspector, assert on it with a scripted client in CI, then try it with a real model. Each layer finds a different kind of bug.
Check yourself · 1 of 3
What is the main benefit of an in-memory transport in server tests?
Why it matters
A server can pass its unit tests and still be unusable, because the problem is in the definition the model reads, the framing on the wire or how the client sees an error. Testing only the handler function misses all three.
The layers
- MCP Inspector (manual). A visual tool that connects to your server over stdio or HTTP. It lists tools, resources and prompts, lets you fill in arguments and call them, and shows the raw JSON-RPC messages and the server's stderr. Use it while you build. It answers "does it connect, and what exactly does the client see?"
- Scripted client tests (automated). Use the SDK's client to connect to your server, ideally through an in-memory transport that links client and server in one process with no subprocess or port. Then assert on
listTools(), call each tool with good and bad arguments, and check results. Run it in CI. Also run one test through the real transport, since in-memory tests cannot catch a stdout leak. - Schema checks. Assert that each tool has a description, that every property has a description, that required fields are set and that outputs validate against
outputSchema. - A real model. Connect the server to a client such as Claude Desktop, Claude Code or Cursor and give the model a few realistic tasks. Watch which tool it picks, which arguments it invents and where it gets stuck. Fix the definitions, not just the handlers.
Reading a failure
Ask where the failure appears:
- Never lists, or the client says it cannot parse a message: transport, usually stdout pollution or a wrong command or path.
- Lists but the call is rejected with an invalid-arguments error: schema, either your schema or the client's arguments.
- Call accepted, result has
isErroror an exception message: handler. - Works in Inspector, model calls it wrongly: definition quality.
Before and after
// Weak: only the function is tested, so schema and wiring are never exercised
expect(await lookup("ORD-1042")).toMatchObject({ status: "shipped" });
// Better: test through the protocol
const [clientT, serverT] = InMemoryTransport.createLinkedPair();
await server.connect(serverT);
const client = new Client({ name: "test", version: "1.0.0" });
await client.connect(clientT);
const res = await client.callTool({ name: "get_order", arguments: { orderId: "bad" } });
expect(res.isError).toBe(true);
What goes wrong
- Only testing the handler. Schema bugs and wiring bugs survive.
- Only testing in-memory. A stray print only fails on stdio.
- Skipping the model run. A definition that passes every test can still confuse a model.
- Tests that depend on live data. Use fixtures so CI does not flake.
Examples
Triaging an Inspector log
-> tools/call {"name":"get_order","arguments":{"order_id":"ORD-1042"}}
<- error -32602: Invalid arguments: orderId is required
The server declares orderId, and the caller sent order_id. The request reached the SDK and failed validation, so the problem is in the schema or the caller's arguments, not the handler and not the transport. Fix the description so models see the exact name, or accept the name you documented.
A CI test for definition quality
const { tools } = await client.listTools();
for (const t of tools) {
expect(t.description?.length).toBeGreaterThan(30);
for (const [name, p] of Object.entries(t.inputSchema.properties ?? {})) {
expect((p as { description?: string }).description, `${t.name}.${name}`).toBeTruthy();
}
}
This fails the build when someone adds a tool or property without a description.
Key points
- MCP Inspector shows what a client sees: the tool list, arguments, raw messages and stderr output.
- Scripted client tests with an in-memory transport exercise the real protocol without subprocesses or ports.
- Keep one test through the real stdio or HTTP transport, because in-memory tests cannot catch a stdout leak.
- Where a failure appears tells you its source: no listing points to transport, rejected arguments to schema, and an error result to the handler.
- A model run is a test of the definitions, so fix descriptions and schemas when the model misuses a tool.
Common mistakes
- Testing only the handler function and never calling the tool through the protocol.
- Relying only on in-memory tests, which cannot see output written to stdout.
- Never running a real model against the server before sharing it.
- Depending on live production data in tests, which makes CI results unstable.
Check yourself · 2 of 3
In Inspector, tools/list works but calling a tool returns "Invalid arguments: limit must be <= 100". Where is the cause?
Check yourself · 3 of 3
Your tests all pass, but a model keeps passing wrong arguments to a tool. What should you change first?
Practice items, not counted towards your mastery.
Start here
- Build an MCP server (official tutorial) (opens in a new tab)DocsFree
Step-by-step server in Python, TypeScript and other SDKs, including the stdout logging rule.
- MCP SDKs (opens in a new tab)DocsFree
The list of official SDKs by language and their support tiers.
- MCP specification: Tools (opens in a new tab)StandardFree
The normative definition of tool schemas, outputSchema, structuredContent, annotations and isError.
More for this topic
- MCP Inspector (opens in a new tab)ToolFree
The visual tester for listing and calling tools, resources and prompts on any server.
- MCP reference servers (opens in a new tab)ToolFree
Maintained example servers to copy structure, schemas and tests from.