fix: resolve Claude Desktop stdio communication issues and update documentation
- Fixed console output interference with stdio JSON-RPC protocol: - Modified logger to suppress ALL output in stdio mode - Added DISABLE_CONSOLE_OUTPUT environment variable support - Updated error handlers to respect stdio mode - Updated Claude Desktop configuration documentation: - Added required environment variables for clean stdio communication - Promoted local installation as recommended method - Fixed remote connection instructions (removed broken mcp-remote) - Added troubleshooting section for common issues - Updated both README.md and docs/README_CLAUDE_SETUP.md - Environment variables now required for stdio mode: - MCP_MODE=stdio - LOG_LEVEL=error - DISABLE_CONSOLE_OUTPUT=true - NODE_ENV=production This ensures clean JSON-RPC communication without console output corruption. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,21 +5,25 @@ import { logger } from '../utils/logger';
|
||||
|
||||
// Add error details to stderr for Claude Desktop debugging
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('Uncaught Exception:', error);
|
||||
if (process.env.MCP_MODE !== 'stdio') {
|
||||
console.error('Uncaught Exception:', error);
|
||||
}
|
||||
logger.error('Uncaught Exception:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
if (process.env.MCP_MODE !== 'stdio') {
|
||||
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
}
|
||||
logger.error('Unhandled Rejection:', reason);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
async function main() {
|
||||
const mode = process.env.MCP_MODE || 'stdio';
|
||||
|
||||
try {
|
||||
const mode = process.env.MCP_MODE || 'stdio';
|
||||
|
||||
// Only show debug messages in HTTP mode to avoid corrupting stdio communication
|
||||
if (mode === 'http') {
|
||||
console.error(`Starting n8n Documentation MCP Server in ${mode} mode...`);
|
||||
@@ -55,20 +59,23 @@ async function main() {
|
||||
await server.run();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to start MCP server:', error);
|
||||
logger.error('Failed to start MCP server', error);
|
||||
|
||||
// Provide helpful error messages
|
||||
if (error instanceof Error && error.message.includes('nodes.db not found')) {
|
||||
console.error('\nTo fix this issue:');
|
||||
console.error('1. cd to the n8n-mcp directory');
|
||||
console.error('2. Run: npm run build');
|
||||
console.error('3. Run: npm run rebuild');
|
||||
} else if (error instanceof Error && error.message.includes('NODE_MODULE_VERSION')) {
|
||||
console.error('\nTo fix this Node.js version mismatch:');
|
||||
console.error('1. cd to the n8n-mcp directory');
|
||||
console.error('2. Run: npm rebuild better-sqlite3');
|
||||
console.error('3. If that doesn\'t work, try: rm -rf node_modules && npm install');
|
||||
// In stdio mode, we cannot output to console at all
|
||||
if (mode !== 'stdio') {
|
||||
console.error('Failed to start MCP server:', error);
|
||||
logger.error('Failed to start MCP server', error);
|
||||
|
||||
// Provide helpful error messages
|
||||
if (error instanceof Error && error.message.includes('nodes.db not found')) {
|
||||
console.error('\nTo fix this issue:');
|
||||
console.error('1. cd to the n8n-mcp directory');
|
||||
console.error('2. Run: npm run build');
|
||||
console.error('3. Run: npm run rebuild');
|
||||
} else if (error instanceof Error && error.message.includes('NODE_MODULE_VERSION')) {
|
||||
console.error('\nTo fix this Node.js version mismatch:');
|
||||
console.error('1. cd to the n8n-mcp directory');
|
||||
console.error('2. Run: npm rebuild better-sqlite3');
|
||||
console.error('3. If that doesn\'t work, try: rm -rf node_modules && npm install');
|
||||
}
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user