What this thread does
Never write to stdout from an MCP stdio server: stdout carries the JSON-RPC messages, so a stray print() or console.log() corrupts them and the client disconnects or reports JSON parse errors. First action: move all logging to stderr, then run the Inspector against the server (npx @modelcontextprotocol/inspector node build/index.js). Checked 2026-11-17, as of November 2026. Evidence: the rule, the per-language logging advice and the Inspector commands are from the official MCP docs; nothing was run here (untested). Not for: servers showing no tools under nvm, see mcp-desktop-client-npx-wrong-node-nvm; reconnecting a dropped server, see claude-code-mcp-reconnect-all-command.
The problem
You wrote an MCP server (weather, database, internal API). It starts fine in a terminal, but the client shows it as disconnected, shows no tools, or reports JSON parse errors. A debugging print or console.log is a common cause.
What the official guide says
The Build an MCP server tutorial has a "Logging in MCP Servers" section per language:
- STDIO servers must never write to stdout. Python: no
print(); use the standardloggingmodule (it writes to stderr). TypeScript: neverconsole.log(); useconsole.error()or a logger that writes to stderr or files. Java: neverSystem.out.println(). Kotlin: neverprintln(). Go:log.Println()orfmt.Fprintf(os.Stderr, ...). Rust:eprintln!ortracing/log. - HTTP servers may log to stdout, since it does not share the channel with responses.
- In a desktop client config pass the absolute path to the server (
pwdon macOS/Linux,cdin Windows Command Prompt); on Windows use forward slashes or double backslashes.
Debug with the Inspector
As of November 2026, the MCP Inspector needs Node.js 22.23.4+, 24.22.1+, or 26.12.1+ and runs through npx; pass your server's launch command as the arguments:
npx @modelcontextprotocol/inspector node build/index.js # web UI; prints a URL with a per-launch token
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list
npx @modelcontextprotocol/inspector --tui node build/index.js # terminal UI
npx @modelcontextprotocol/inspector --server-url https://api.example.com/mcp --transport http # remote server
Mode flags (--web, --cli, --tui) are recognized only at the front; everything after the first other token, such as --method tools/list, is forwarded to the Inspector client unchanged (a literal later --cli reaches your server). For the 2026-07-28 spec era add --protocol-era modern; the Inspector defaults to legacy, so run once per era if you support both (build-server tutorial).
Python: the Python SDK running guide shows uv run mcp dev server.py. The Inspector launches the file as a subprocess and talks stdio, so there is no port to configure. Keep mcp.run() under if __name__ == "__main__": because mcp dev imports the file; the same guide warns that an unbuffered import-time print or a buffered print() that flushes at exit still lands on the wire.
If the server runs in Claude Desktop, read its logs: mcp.log for connection failures and mcp-server-SERVERNAME.log for your server's stderr. Locations: macOS ~/Library/Logs/Claude, Windows %APPDATA%\Claude\logs, Linux ~/.config/Claude/logs (connect local servers). A stray stdout line breaks the stream, while stderr output appears in the server log without harm.
How to describe it to your agent
Our stdio MCP server must never write to stdout. Search the code and its dependencies forconsole.log,process.stdout.writeand similar, including startup code, and move logging to stderr or a file. Add a test that spawns the server, sends aninitializerequest on stdin and asserts every stdout line is valid JSON-RPC. Then run the Inspector CLItools/listagainst the built server and fix the client config to use absolute paths.
Mistakes to check
- A dependency that logs to stdout or prints a progress bar on startup.
- A relative path in the client config; the client launches from a different directory.
- Testing only in a terminal, where stray output looks harmless.
Limits
Official docs and a second source for the Python path (the SDK guide); no server was run. The Inspector's web UI port is not stated on the current page, so none is given.
Sources
Build an MCP server (never-write-to-stdout rule, per-language advice, HTTP may log to stdout, absolute paths, --protocol-era), MCP Inspector (launch forms, Node requirement, flag order), Python SDK running guide (uv run mcp dev server.py, stdio pitfalls), connect local servers (log locations). All checked 2026-11-17.
Started from a post by @Model Context Protocol, packaged by the editor. Original post