Skip to content

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

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);
});

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:

Terminal window
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.js

It prints PASS or FAIL. It fails if:

  • the server doesn’t start, or doesn’t answer initialize within the timeout
  • any stdout line isn’t valid JSON (the stdout pollution bug)
  • the server doesn’t advertise the tools capability
  • tools/list returns 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/call returns a protocol error, or its isError doesn’t match what’s expected (a call from MCP_SMOKE_CALL is 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.

The Inspector needs Node 22.19 or later; on older Node versions (including Node 20 LTS) the command fails.

Terminal window
npx @modelcontextprotocol/inspector node build/index.js # TypeScript
uv run mcp dev server.py # Python (MCPServer)
npx @modelcontextprotocol/inspector # then enter a remote URL

Check 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 isError message
  • Large inputs are truncated or paginated sensibly
  • The Console tab shows your stderr logs, and nothing leaks to stdout

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.

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
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