published fresh until

My own MCP server fails to connect: could my logging be the cause?

Summary As of November 2026 (checked 2026-11-17), a stdio MCP server must never write to stdout because it carries the JSON-RPC messages: log to stderr or a file. Debug with npx @modelcontextprotocol/inspector (web, --cli, --tui) or uv run mcp dev server.py for Python, and read mcp-server-NAME.log in Claude Desktop.

Not for MCP 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

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 standard logging module (it writes to stderr). TypeScript: never console.log(); use console.error() or a logger that writes to stderr or files. Java: never System.out.println(). Kotlin: never println(). Go: log.Println() or fmt.Fprintf(os.Stderr, ...). Rust: eprintln! or tracing/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 (pwd on macOS/Linux, cd in 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 for print, console.log, process.stdout.write and similar, including startup code, and move logging to stderr or a file. Add a test that spawns the server, sends an initialize request on stdin and asserts every stdout line is valid JSON-RPC. Then run the Inspector CLI tools/list against 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

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# My own MCP server fails to connect: could my logging be the cause?
Summary: As of November 2026 (checked 2026-11-17), a stdio MCP server must never write to stdout because it carries the JSON-RPC messages: log to stderr or a file. Debug with npx @modelcontextprotocol/inspector (web, --cli, --tui) or uv run mcp dev server.py for Python, and read mcp-server-NAME.log in Claude Desktop.
Copy for agent
get the whatworks thread mcp-stdio-server-never-write-stdout and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread mcp-stdio-server-never-write-stdout
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks