@tb.p/terminai
Version:
MCP (Model Context Protocol) server for secure SSH remote command execution. Enables AI assistants like Claude, Cursor, and VS Code to execute commands on remote servers via SSH with command validation, history tracking, and web-based configuration UI.
71 lines (64 loc) • 2.26 kB
JavaScript
import { Command } from 'commander';
import { runServer } from './server.js';
import { loadConfig, saveConfig, getConfigPath } from './config/loader.js';
import { DEFAULT_CONFIG } from './config/defaults.js';
const program = new Command();
program
.name('terminai')
.description('MCP server for executing commands on remote servers via SSH')
.version('0.0.8')
.option('--config <path>', 'Path to config file')
.option('--ui', 'Start web UI instead of MCP server')
.option('--port <port>', 'Web UI port (default: 8374)', '8374')
.action(async (options) => {
if (options.ui) {
try {
const { startUIServer } = await import('./ui/server.js');
const port = parseInt(options.port, 10);
await startUIServer(port, options.config);
} catch (error) {
console.error(`Error starting UI server: ${error.message}`);
process.exit(1);
}
} else {
await runServer(options.config);
}
});
program
.command('init')
.description('Initialize configuration file')
.option('--config <path>', 'Path to config file')
.action((options) => {
try {
const configPath = saveConfig(DEFAULT_CONFIG, options.config);
console.log(`Configuration initialized at: ${configPath}`);
} catch (error) {
console.error(`Error initializing config: ${error.message}`);
process.exit(1);
}
});
program
.command('config')
.description('Manage configuration via web UI')
.option('--ui', 'Start web UI')
.option('--port <port>', 'Web UI port (default: 8374)', '8374')
.option('--config <path>', 'Path to config file')
.action(async (options) => {
if (options.ui) {
try {
const { startUIServer } = await import('./ui/server.js');
const port = parseInt(options.port, 10);
await startUIServer(port, options.config);
} catch (error) {
console.error(`Error starting UI server: ${error.message}`);
process.exit(1);
}
} else {
const configPath = getConfigPath(options.config);
console.log(`Configuration file location: ${configPath}`);
console.log('\nTo edit configuration via web UI:');
console.log(' terminai config --ui');
}
});
program.parse();