mcp-cve-intelligence-server-lite-test
Version:
Lite Model Context Protocol server for comprehensive CVE intelligence gathering with multi-source exploit discovery, designed for security professionals and cybersecurity researchers - Alpha Release
162 lines • 8.33 kB
JavaScript
/* eslint-disable no-console */
import { Command } from 'commander';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { createContextLogger } from '../utils/logger.js';
import { setEnvironmentFromCLI, getAppConfiguration, getEnvironmentVariable, setEnvironmentVariable, setEnvironmentIfNotSet, configManager, } from '../config/index.js';
const logger = createContextLogger('CLIService');
export class CLIService {
program;
version;
constructor() {
// Read version from package.json
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const packageJsonPath = join(__dirname, '..', '..', 'package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
this.version = packageJson.version;
logger.debug('CLIService initialized', { version: this.version });
this.program = new Command();
this.setupCommands();
}
setupCommands() {
this.program
.name('mcp-cve-intelligence-server-lite')
.description('MCP CVE Intelligence Server Lite - Search and analyze CVE vulnerabilities with in-memory storage')
.version(this.version)
.option('-t, --transport <type>', 'transport type (stdio|http)')
.option('-p, --port <number>', 'HTTP port (when using http transport)', '3001')
.option('--host <host>', 'HTTP host (when using http transport)', '0.0.0.0')
.option('--log-level <level>', 'log level (error|warn|info|debug)', 'info')
.helpOption('-?, --help', 'display help for command');
// Quick start command
this.program
.command('quick-start')
.description('Start server with optimal defaults for quick testing')
.option('-p, --port <number>', 'HTTP port', '3001')
.action(async (options) => {
await this.handleQuickStart(options);
});
// Docker command
this.program
.command('docker')
.description('Generate Docker commands and configuration')
.option('-p, --port <number>', 'host port to map', '3001')
.action((options) => {
this.handleDockerCommand(options);
});
// Config command
this.program
.command('config')
.description('Show current configuration and environment')
.action(() => {
this.handleConfigCommand();
});
// Default action for main command
this.program.action(async (options) => {
await this.handleDefaultCommand(options);
});
}
async handleQuickStart(options) {
logger.info('Quick start command initiated', { options });
this.displayMessage('debug', 'quick-start options:', options);
this.displayMessage('debug', 'options.port:', options.port, 'type:', typeof options.port);
// Set environment variables for quick start using centralized config
setEnvironmentVariable('MCP_TRANSPORT_TYPE', 'http'); // Force HTTP for quick-start
setEnvironmentVariable('MCP_HTTP_PORT', options.port || getEnvironmentVariable('MCP_HTTP_PORT') || '3001');
setEnvironmentIfNotSet('MCP_HTTP_HOST', '0.0.0.0');
setEnvironmentIfNotSet('MCP_HTTP_CORS', 'true');
// Reload configuration to pick up the new environment variables
const config = configManager.reload();
logger.info('Quick start configuration applied', {
port: config.transport.http.port,
host: config.transport.http.host,
cors: config.transport.http.enableCors,
});
this.displayMessage('info', '');
this.displayMessage('info', 'Starting MCP CVE Intelligence Server Lite (Quick Start Mode)');
this.displayMessage('info', 'Transport: HTTP');
this.displayMessage('info', `Port: ${config.transport.http.port}`);
this.displayMessage('info', '');
// Import and start server dynamically to avoid circular dependencies
const { startServer } = await import('./server-launcher.js');
await startServer(config.transport.type);
}
handleDockerCommand(options) {
logger.info('Docker command initiated', { options });
this.displayMessage('info', ' Docker deployment commands:');
this.displayMessage('info', '');
this.displayMessage('info', '# Pull and run from Docker Hub (if published):');
const dockerRunCmd = `docker run -d --name mcp-cve-intelligence-server-lite -p ${options.port}:3001 ` +
'mcp-cve-intelligence-server-lite:latest';
this.displayMessage('info', dockerRunCmd);
this.displayMessage('info', '');
this.displayMessage('info', '# Or build locally:');
this.displayMessage('info', 'git clone <repository-url>');
this.displayMessage('info', 'cd mcp-cve-intelligence-server-lite');
this.displayMessage('info', './docker-run.sh run');
this.displayMessage('info', '');
this.displayMessage('info', '# Test the deployment:');
this.displayMessage('info', `curl http://localhost:${options.port}/health`);
this.displayMessage('info', '');
this.displayMessage('info', ' See DOCKER.md for complete setup guide');
}
handleConfigCommand() {
logger.info('Config command initiated');
this.displayMessage('info', ' MCP CVE Intelligence Server Lite Configuration:');
this.displayMessage('info', '');
this.displayMessage('info', 'Environment Variables:');
const config = getAppConfiguration();
logger.debug('Current configuration', { config });
this.displayMessage('info', ` NODE_ENV: ${config.server.environment}`);
this.displayMessage('info', ` MCP_TRANSPORT_TYPE: ${config.transport.type}`);
this.displayMessage('info', ` MCP_HTTP_PORT: ${config.transport.http.port}`);
this.displayMessage('info', ` MCP_HTTP_HOST: ${config.transport.http.host}`);
this.displayMessage('info', ` MCP_JSON_COMPRESS: ${config.transport.http.compressJson}`);
this.displayMessage('info', ` LOG_LEVEL: ${config.logging.level}`);
this.displayMessage('info', '');
this.displayMessage('info', 'Available Commands:');
this.displayMessage('info', ' npx mcp-cve-intelligence-server-lite # Start with default settings');
this.displayMessage('info', ' npx mcp-cve-intelligence-server-lite quick-start # HTTP mode for testing');
this.displayMessage('info', ' npx mcp-cve-intelligence-server-lite --help # Show all options');
this.displayMessage('info', '');
this.displayMessage('info', 'MCP Client Configuration Examples:');
this.displayMessage('info', ' See MCP_QUICK_REFERENCE.md for VS Code and Claude Desktop setup');
}
async handleDefaultCommand(options) {
logger.info('Default command initiated', { options });
// Set environment variables from CLI options - ONLY if not already set by environment
this.setEnvironmentFromOptions(options);
const config = getAppConfiguration();
logger.info('Starting server with configuration', {
transport: config.transport.type,
logLevel: config.logging.level,
});
// Import and start server dynamically to avoid circular dependencies
const { startServer } = await import('./server-launcher.js');
await startServer(config.transport.type);
}
setEnvironmentFromOptions(options) {
logger.debug('Setting environment from CLI options', { options });
// Use centralized configuration management
setEnvironmentFromCLI(options);
logger.debug('Environment variables set from CLI options');
}
displayMessage(level, ...args) {
if (level === 'debug') {
console.log('DEBUG -', ...args);
}
else {
console.log(...args);
}
}
parse(argv) {
logger.debug('Parsing CLI arguments', { argv });
this.program.parse(argv);
}
getProgram() {
return this.program;
}
}
//# sourceMappingURL=cli-service.js.map