Always consider the destination and lifecycle of output streams to prevent protocol interference, data loss, and unexpected behavior. Choose stdout for application output and stderr for debugging/logging. Avoid accidentally closing streams and be mindful of output pollution in protocol-sensitive contexts.

Key practices:

Example:

// Good: Prevent stdout closure when piping
fileStream.pipe(process.stdout, { end: false })

// Good: Redirect console in protocol contexts  
if (process.argv.includes('mcp')) {
  console.log = console.error.bind(console)
}

// Good: Use stderr for debug output
console.warn(`${namespace} ${format}`, ...rest)