Fix: Disable logging in stdio mode to prevent MCP protocol errors
- Detect stdio mode and set logger to 'silent' level - stdout must be reserved exclusively for JSON-RPC MCP messages - Prevents 'Unexpected token' JSON parsing errors in Claude Code - Only log when using HTTP transport mode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import pino from 'pino';
|
||||
import { config } from '../config';
|
||||
|
||||
// Detect if running in stdio mode (stdout must be reserved for MCP protocol)
|
||||
const isStdioMode = !process.env.MCP_TRANSPORT || process.env.MCP_TRANSPORT === 'stdio';
|
||||
|
||||
export const logger = pino({
|
||||
level: config.mcp.logLevel,
|
||||
transport: {
|
||||
level: isStdioMode ? 'silent' : config.mcp.logLevel,
|
||||
transport: isStdioMode ? undefined : {
|
||||
target: 'pino-pretty',
|
||||
options: {
|
||||
colorize: true,
|
||||
@@ -11,6 +14,10 @@ export const logger = pino({
|
||||
ignore: 'pid,hostname',
|
||||
},
|
||||
},
|
||||
// In stdio mode, send any logs to stderr instead of stdout
|
||||
...(isStdioMode && {
|
||||
browser: { write: () => {} },
|
||||
}),
|
||||
});
|
||||
|
||||
export function createLogger(name: string): pino.Logger {
|
||||
|
||||
Reference in New Issue
Block a user