@yuvakiran-zen/zen-cli
Version:
Intelligent Code Agent powered by Zen
142 lines (119 loc) โข 5.75 kB
JavaScript
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);
});