MCP: testing & debugging
Test at four layers, from fastest to slowest.
| Layer | Tool | Catches |
|---|---|---|
| 1. Unit | Your test runner (Vitest, Jest, pytest) | Logic bugs in handlers |
| 2. Protocol | The template’s scripts/mcp-smoke.mjs, or an SDK in-memory client |
Connection, schemas, tool registration, and (smoke script only) stdout pollution |
| 3. Interactive | MCP Inspector | Descriptions, schemas, and error messages as the model sees them |
| 4. End-to-end | A real host (Cursor, Claude Code) + eval prompts | Whether the model picks the right tool and uses it correctly |
1. Unit tests
Section titled “1. Unit tests”Keep handler logic in plain functions and test them directly. In the TypeScript template, searchNotes is exported from src/index.ts, and importing the file doesn’t start the server:
import { test, expect } from "vitest";import { searchNotes } from "../src/index.js";
test("search is case-insensitive", () => { expect(searchNotes([{ title: "MCP", body: "", created: "" }], "mcp", 5)).toHaveLength(1);});2. Protocol smoke test (automated)
Section titled “2. Protocol smoke test (automated)”Each MCP template ships with a dependency-free smoke tester, scripts/mcp-smoke.mjs (download the templates from the templates page). It needs Node 20 or later. It launches any stdio server, performs the legacy (2025) initialize handshake, which every v2 server still serves, lists the tools (and the resources and prompts, if advertised), and optionally calls one. The maintainers of this guide also run it in CI as a 2026-07-28 client; the copy in the templates runs the legacy handshake.
Run it from your project folder:
node scripts/mcp-smoke.mjs <command> [args...]node scripts/mcp-smoke.mjs node build/index.js # TypeScript (or: npm run smoke)node scripts/mcp-smoke.mjs python server.py # Python
# also call a tool with JSON arguments (bash syntax; in PowerShell, set $env:MCP_SMOKE_CALL first)MCP_SMOKE_CALL='search_notes {"query":"test"}' node scripts/mcp-smoke.mjs node build/index.jsIt prints PASS or FAIL. It fails if:
- the server doesn’t start, or doesn’t answer
initializewithin the timeout - any stdout line isn’t valid JSON (the stdout pollution bug)
- the server doesn’t advertise the
toolscapability tools/listreturns no tools- a tool name falls outside
[A-Za-z0-9_.-]{1,64} - a tool’s description is missing or under 20 characters
- a tool’s input schema isn’t an object schema (
"type": "object") - a
tools/callreturns a protocol error, or itsisErrordoesn’t match what’s expected (a call fromMCP_SMOKE_CALLis expected to succeed)
Add the same command to your own CI.
In-process alternative: in TypeScript, InMemoryTransport.createLinkedPair() (exported from @modelcontextprotocol/server) connects a client (from @modelcontextprotocol/client) and the McpServer returned by createServer() in one process, which is ideal for Vitest or Jest. In Python v2, use from mcp import Client, then async with Client(mcp) as client:, where mcp is your MCPServer instance. An in-memory client can’t catch stdout pollution, because nothing goes over stdout, so keep the smoke test as well.
3. MCP Inspector
Section titled “3. MCP Inspector”The Inspector needs Node 22.19 or later; on older Node versions (including Node 20 LTS) the command fails.
npx @modelcontextprotocol/inspector node build/index.js # TypeScriptuv run mcp dev server.py # Python (MCPServer)npx @modelcontextprotocol/inspector # then enter a remote URLCheck each of these:
- Tools, Resources, and Prompts tabs list what you expect
- Each tool’s description and parameter descriptions read clearly
- The happy path works for every tool
- Every error path returns a helpful
isErrormessage - Large inputs are truncated or paginated sensibly
- The Console tab shows your stderr logs, and nothing leaks to stdout
4. End-to-end evals
Section titled “4. End-to-end evals”In a real host, in a fresh chat each time:
| # | Prompt | Expected tool | Expected args | Result |
|---|---|---|---|---|
| E1 | “Find my notes about onboarding” | search_notes |
query: "onboarding" |
|
| E2 | “Save this as a note titled Standup” | add_note |
title: "Standup" |
|
| E3 | “What’s the weather?” (unrelated) | none | n/a | |
| E4 | “Save a note titled Standup” again | add_note → error → model explains |
n/a |
If the model picks the wrong tool, fix the descriptions first, then the names, then consider merging tools.
Debugging playbook
Section titled “Debugging playbook”| Symptom | Where to look | Likely fix |
|---|---|---|
| Server won’t start | Host MCP logs; run the command manually in a terminal | Wrong path, a missing build, or a missing runtime on PATH |
| Starts, then disconnects | Run the smoke test; look for non-JSON on stdout | Move all logging to stderr |
| Tool list empty | Inspector | Tools registered outside createServer() (TypeScript) or after mcp.run() (Python)? Register them before the server starts |
| Model never calls the tool | Description | Add trigger words; say when to use it |
| Wrong arguments | Schema | Add description, enum, and format to each parameter |
| Timeouts | Server logs | Make I/O async, add timeouts upstream, and report progress |
| Works in the Inspector, not in the host | Host env and cwd | GUI apps don’t inherit your shell PATH or env; set env and absolute paths explicitly |
Where the logs are
Section titled “Where the logs are”| Host | Logs |
|---|---|
| Cursor | Output panel (Ctrl+Shift+U or Cmd+Shift+U) → “MCP Logs” |
| Claude Code | claude --debug=mcp; /mcp in a session |
| Claude Desktop | %APPDATA%\Claude\logs\mcp*.log (Windows), ~/Library/Logs/Claude/mcp*.log (macOS) |
| Your server | stderr: shown in the host logs for stdio servers; for remote servers, in your hosting platform’s logs |