UNPKG

@yuvakiran-zen/zen-cli

Version:

Intelligent Code Agent powered by Zen

142 lines (119 loc) โ€ข 5.75 kB
#!/usr/bin/env node const fs = require('fs-extra'); const path = require('path'); const os = require('os'); const chalk = require('chalk'); async function diagnoseMCP() { console.log(chalk.yellow('๐Ÿ” Zen CLI MCP Diagnostic Tool\n')); const configDir = path.join(os.homedir(), '.zen-code'); const configPath = path.join(configDir, 'mcp-config.json'); const defaultConfigPath = path.join(process.cwd(), 'zen-mcp-config.json'); // Check Node.js version console.log(`๐Ÿ“‹ Node.js version: ${process.version}`); console.log(`๐Ÿ“‹ Platform: ${os.platform()} ${os.arch()}`); console.log(`๐Ÿ“‹ Home directory: ${os.homedir()}`); console.log(`๐Ÿ“‹ Current directory: ${process.cwd()}\n`); // Check for required commands console.log(chalk.bold('๐Ÿ”ง System Requirements:')); const { exec } = require('child_process'); const util = require('util'); const execPromise = util.promisify(exec); // Check node availability try { const { stdout } = await execPromise('node --version'); console.log(` Node: ${chalk.green('โœ…')} ${stdout.trim()}`); } catch (error) { console.log(` Node: ${chalk.red('โŒ Not found in PATH')}`); } // Check npx availability try { const { stdout } = await execPromise('npx --version'); console.log(` NPX: ${chalk.green('โœ…')} ${stdout.trim()}`); } catch (error) { console.log(` NPX: ${chalk.red('โŒ Not found in PATH')}`); console.log(chalk.yellow(' ๐Ÿ’ก NPX is required for some MCP servers. Install Node.js to get NPX.')); } console.log(''); // Check config directory const configDirExists = await fs.pathExists(configDir); console.log(`๐Ÿ“ Config directory: ${configDir}`); console.log(` Status: ${configDirExists ? chalk.green('โœ… EXISTS') : chalk.red('โŒ MISSING')}`); if (!configDirExists) { console.log(chalk.yellow(' ๐Ÿ’ก Creating config directory...')); try { await fs.ensureDir(configDir); console.log(chalk.green(' โœ… Config directory created')); } catch (error) { console.log(chalk.red(` โŒ Failed to create config directory: ${error.message}`)); } } // Check config file const configExists = await fs.pathExists(configPath); console.log(`\n๐Ÿ“„ MCP Config file: ${configPath}`); console.log(` Status: ${configExists ? chalk.green('โœ… EXISTS') : chalk.yellow('โš ๏ธ MISSING')}`); if (configExists) { try { const config = await fs.readJson(configPath); console.log(` ๐Ÿ“Š Servers configured: ${config.servers?.length || 0}`); console.log(` ๐Ÿ”ง MCP enabled: ${config.enabled !== false ? 'Yes' : 'No'}`); if (config.servers?.length > 0) { console.log(` ๐Ÿ“‹ Configured servers:`); config.servers.forEach((server, index) => { const status = server.enabled !== false ? chalk.green('โœ…') : chalk.red('โŒ'); console.log(` ${index + 1}. ${status} ${server.name} (${server.command})`); }); } } catch (error) { console.log(chalk.red(` โŒ Error reading config: ${error.message}`)); } } else { console.log(chalk.yellow(' ๐Ÿ’ก No MCP configuration found. Use "zen-cli" and run "/mcp add" to configure MCP servers.')); } // Check default config (legacy) const defaultExists = await fs.pathExists(defaultConfigPath); console.log(`\n๐Ÿ“„ Legacy config: ${defaultConfigPath}`); console.log(` Status: ${defaultExists ? chalk.yellow('โš ๏ธ EXISTS (should migrate)') : chalk.green('โœ… NOT FOUND (good)')}`); // Check permissions try { await fs.access(configDir, fs.constants.R_OK | fs.constants.W_OK); console.log(`\n๐Ÿ” Permissions: ${chalk.green('โœ… READ/WRITE OK')}`); } catch (error) { console.log(`\n๐Ÿ” Permissions: ${chalk.red('โŒ PERMISSION DENIED')}`); console.log(chalk.red(` Error: ${error.message}`)); } // Environment check console.log(`\n๐ŸŒ Environment:`); console.log(` ZEN_DEBUG: ${process.env.ZEN_DEBUG || 'not set'}`); console.log(` ANTHROPIC_API_KEY: ${process.env.ANTHROPIC_API_KEY ? chalk.green('set') : chalk.red('not set')}`); console.log(` PATH: ${process.env.PATH ? chalk.green('set') : chalk.red('not set')}`); // Test MCP server execution console.log(`\n๐Ÿงช Testing MCP Server Execution:`); const distPath = path.join(__dirname, '..', 'dist', 'core', 'simple-mcp-server.js'); const srcPath = path.join(__dirname, '..', 'src', 'core', 'simple-mcp-server.js'); if (await fs.pathExists(distPath)) { console.log(` Compiled server: ${chalk.green('โœ… Found')} at ${distPath}`); } else { console.log(` Compiled server: ${chalk.red('โŒ Not found')} at ${distPath}`); console.log(chalk.yellow(' ๐Ÿ’ก Run "npm run build" to compile the TypeScript files')); } if (await fs.pathExists(srcPath)) { console.log(` Source server: ${chalk.green('โœ… Found')} at ${srcPath}`); } else { console.log(` Source server: ${chalk.red('โŒ Not found')} at ${srcPath}`); } console.log(chalk.green('\nโœ… Diagnosis complete!')); // Recommendations console.log(chalk.bold('\n๐Ÿ“ Recommendations:')); console.log(chalk.blue('1. To enable debug mode: ZEN_DEBUG=true zen-cli')); console.log(chalk.blue('2. To configure MCP servers: zen-cli and use "/mcp add"')); console.log(chalk.blue('3. To test MCP connection: zen-cli and use "/mcp status"')); if (!configExists) { console.log(chalk.yellow('\nโš ๏ธ No MCP configuration found!')); console.log(chalk.yellow('Run "zen-cli" and use "/mcp init" to create a default configuration.')); } } // Run the diagnostic diagnoseMCP().catch(error => { console.error(chalk.red('โŒ Diagnostic failed:'), error); process.exit(1); });