Claude Desktop: MCP server disconnects due to startup logs written to stdout instead of stderr
When integrating bookstack-mcp-server with Claude Desktop, the server immediately disconnects with the error:
MCP bookstack: Unexpected non-whitespace character after JSON at position 4 (line 1 column 5)
Root cause
The Winston logger uses a Console transport that writes to stdout by default. Claude Desktop communicates with MCP servers exclusively via stdout (JSON-RPC over stdio), so the startup log lines corrupt the protocol stream. The JSON parser sees 2026 (the start of the timestamp) as a valid JSON number, then chokes on the - at position 4.
Workaround
Set LOG_LEVEL=error in the environment. Since all startup messages are info-level, stdout stays clean and Claude Desktop can connect successfully.
In claude_desktop_config.json:
"env": {
"BOOKSTACK_BASE_URL": "...",
"BOOKSTACK_API_TOKEN": "...",
"LOG_LEVEL": "error"
}
Proper fix
The logger should direct all output to stderr, leaving stdout exclusively for JSON-RPC. In dist/utils/logger.js:
new winston.transports.Console({
stderrLevels: ['error', 'warn', 'info', 'debug', 'http', 'verbose', 'silly']
})
Confirming this fix works end-to-end. I hit the same issue integrating with Claude Desktop on macOS and applied @skempken's proposed patch to src/utils/logger.ts. After rebuilding (npm run build) and pointing Claude Desktop at the local build, the MCP server connects cleanly, all 56 tools load, and I've successfully called bookstack_books_list, bookstack_shelves_create, bookstack_books_create, and bookstack_pages_create against a live BookStack v26.03.3 instance.
Opened #7 with the fix. Thanks @skempken for the thorough diagnosis.