maia-cli
Version:
Command-line interface for MAIA (Modern AI Assistant)
199 lines (172 loc) ⢠6.79 kB
JavaScript
/**
* MAIA Tools Command - Manage MCP tools
*/
import { Command } from 'commander';
import chalk from 'chalk';
import { ConfigManager, getBuiltinTools } from 'maia-core';
export const toolsCommand = new Command('tools')
.description('Manage MCP tools and integrations');
// List available tools
toolsCommand
.command('list')
.description('List available tools')
.option('--enabled', 'show only enabled tools')
.option('--available', 'show only available tools')
.action(async (options) => {
try {
const configManager = new ConfigManager();
const builtinTools = getBuiltinTools();
let enabledTools = [];
if (configManager.exists()) {
const config = configManager.load();
enabledTools = config.tools.enabled || [];
}
console.log(chalk.cyan('š§ MAIA Tools\n'));
if (options.enabled) {
// Show only enabled tools
if (enabledTools.length === 0) {
console.log(chalk.yellow('No tools enabled'));
return;
}
console.log(chalk.green('ā
Enabled Tools:'));
enabledTools.forEach(toolName => {
const tool = builtinTools.find(t => t.name === toolName);
if (tool) {
console.log(` ${chalk.green('ā')} ${chalk.bold(tool.name)} - ${tool.description}`);
} else {
console.log(` ${chalk.red('ā')} ${chalk.bold(toolName)} - ${chalk.red('Not found')}`);
}
});
} else if (options.available) {
// Show only available tools
console.log(chalk.blue('š¦ Available Tools:'));
builtinTools.forEach(tool => {
const isEnabled = enabledTools.includes(tool.name);
const status = isEnabled ? chalk.green('ā
') : chalk.gray('ā');
console.log(` ${status} ${chalk.bold(tool.name)} - ${tool.description}`);
});
} else {
// Show all tools with status
console.log(chalk.green('ā
Enabled Tools:'));
if (enabledTools.length === 0) {
console.log(chalk.gray(' None'));
} else {
enabledTools.forEach(toolName => {
const tool = builtinTools.find(t => t.name === toolName);
if (tool) {
console.log(` ${chalk.green('ā')} ${chalk.bold(tool.name)} - ${tool.description}`);
}
});
}
console.log(chalk.blue('\nš¦ Available Tools:'));
const availableTools = builtinTools.filter(tool => !enabledTools.includes(tool.name));
if (availableTools.length === 0) {
console.log(chalk.gray(' All tools are enabled'));
} else {
availableTools.forEach(tool => {
console.log(` ${chalk.gray('ā')} ${chalk.bold(tool.name)} - ${tool.description}`);
});
}
}
console.log(chalk.gray(`\nTotal: ${builtinTools.length} available, ${enabledTools.length} enabled`));
} catch (error) {
console.error(chalk.red('ā Failed to list tools:'), error.message);
}
});
// Enable a tool
toolsCommand
.command('enable <tool>')
.description('Enable a tool')
.action(async (toolName) => {
try {
const configManager = new ConfigManager();
if (!configManager.exists()) {
console.log(chalk.red('ā MAIA not initialized. Run "maia init" first.'));
return;
}
const builtinTools = getBuiltinTools();
const tool = builtinTools.find(t => t.name === toolName);
if (!tool) {
console.log(chalk.red(`ā Tool "${toolName}" not found`));
console.log(chalk.gray('Available tools:'));
builtinTools.forEach(t => {
console.log(chalk.gray(` ⢠${t.name}`));
});
return;
}
const config = configManager.load();
if (config.tools.enabled.includes(toolName)) {
console.log(chalk.yellow(`ā ļø Tool "${toolName}" is already enabled`));
return;
}
config.tools.enabled.push(toolName);
configManager.save(config);
console.log(chalk.green(`ā
Enabled tool: ${toolName}`));
console.log(chalk.gray(`Description: ${tool.description}`));
} catch (error) {
console.error(chalk.red('ā Failed to enable tool:'), error.message);
}
});
// Disable a tool
toolsCommand
.command('disable <tool>')
.description('Disable a tool')
.action(async (toolName) => {
try {
const configManager = new ConfigManager();
if (!configManager.exists()) {
console.log(chalk.red('ā MAIA not initialized. Run "maia init" first.'));
return;
}
const config = configManager.load();
const index = config.tools.enabled.indexOf(toolName);
if (index === -1) {
console.log(chalk.yellow(`ā ļø Tool "${toolName}" is not enabled`));
return;
}
config.tools.enabled.splice(index, 1);
configManager.save(config);
console.log(chalk.green(`ā
Disabled tool: ${toolName}`));
} catch (error) {
console.error(chalk.red('ā Failed to disable tool:'), error.message);
}
});
// Show tool info
toolsCommand
.command('info <tool>')
.description('Show detailed information about a tool')
.action(async (toolName) => {
try {
const builtinTools = getBuiltinTools();
const tool = builtinTools.find(t => t.name === toolName);
if (!tool) {
console.log(chalk.red(`ā Tool "${toolName}" not found`));
return;
}
console.log(chalk.cyan(`š§ Tool: ${tool.name}\n`));
console.log(chalk.yellow('Description:'));
console.log(` ${tool.description}\n`);
console.log(chalk.yellow('Parameters:'));
if (tool.parameters.properties) {
Object.entries(tool.parameters.properties).forEach(([param, schema]) => {
const required = tool.parameters.required?.includes(param) ? chalk.red('*') : '';
console.log(` ${param}${required} (${schema.type}) - ${schema.description || 'No description'}`);
});
} else {
console.log(' No parameters');
}
if (tool.parameters.required && tool.parameters.required.length > 0) {
console.log(chalk.gray(`\n ${chalk.red('*')} Required parameters`));
}
// Check if enabled
const configManager = new ConfigManager();
if (configManager.exists()) {
const config = configManager.load();
const isEnabled = config.tools.enabled.includes(toolName);
console.log(chalk.yellow('\nStatus:'));
console.log(` ${isEnabled ? chalk.green('ā
Enabled') : chalk.gray('ā Disabled')}`);
}
} catch (error) {
console.error(chalk.red('ā Failed to show tool info:'), error.message);
}
});