UNPKG

@aurracloud/mcp-cli

Version:

A command-line tool to install, manage, and setup MCP (Model Context Protocol) servers with Docker support

129 lines • 6.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listCommand = listCommand; const logger_1 = require("../utils/logger"); const client_ops_1 = require("../client-ops"); /** * Display information about an MCP server configuration */ function displayServerInfo(serverName, serverConfig) { console.log(`\nšŸ“¦ ${serverName}`); console.log(` Type: ${serverConfig.type || 'unknown'}`); if (serverConfig.command) { console.log(` Command: ${serverConfig.command}`); } if (serverConfig.args && Array.isArray(serverConfig.args)) { console.log(` Arguments: ${serverConfig.args.join(' ')}`); } // Display full command line if (serverConfig.command && serverConfig.args) { console.log(` Full Command: ${serverConfig.command} ${serverConfig.args.join(' ')}`); } // Check if it's a Docker-based installation if (serverConfig.command === 'docker' && serverConfig.args?.includes('run')) { console.log(` 🐳 Running in Docker (sandboxed)`); } else if (serverConfig.command === 'npx' || (serverConfig.args && serverConfig.args.includes('npx'))) { console.log(` āš ļø Running directly on host`); } // Display any additional configuration const otherKeys = Object.keys(serverConfig).filter(key => !['type', 'command', 'args'].includes(key)); if (otherKeys.length > 0) { console.log(` Additional Config:`); otherKeys.forEach(key => { console.log(` ${key}: ${JSON.stringify(serverConfig[key])}`); }); } } /** * Command to list all installed MCP servers for a specific client */ async function listCommand(options) { const clientName = options.client.toLowerCase(); logger_1.logger.info(`Listing MCP servers for ${options.client} client...`); try { // Check if the client is supported const clientConfig = client_ops_1.clientPaths[clientName]; if (!clientConfig) { logger_1.logger.error(`Unsupported client: ${options.client}`); console.log('\nSupported clients:'); Object.keys(client_ops_1.clientPaths).forEach(client => { console.log(` - ${client}`); }); process.exit(1); } // Read the configuration const config = (0, client_ops_1.readConfig)(clientName); if (config.type === "command") { logger_1.logger.info("Command-based client detected - no configuration file to read"); console.log('\nThis client type does not use a configuration file for MCP servers.'); return; } // Check if mcpServers exists and has any servers const mcpServers = config.mcpServers || {}; const serverNames = Object.keys(mcpServers); if (serverNames.length === 0) { logger_1.logger.info(`No MCP servers are currently installed for ${options.client}`); console.log('\nšŸ“­ No MCP servers found in the configuration.'); console.log(`\nTo install an MCP server, use:`); console.log(` mcp install <package-name> -c ${options.client}`); return; } // Display header console.log('\n==============================================='); console.log(`MCP SERVERS FOR ${options.client.toUpperCase()} CLIENT`); console.log('==============================================='); console.log(`Configuration file: ${clientConfig.path || 'N/A'}`); console.log(`Total servers: ${serverNames.length}`); // Display each server serverNames.forEach(serverName => { displayServerInfo(serverName, mcpServers[serverName]); }); console.log('\n==============================================='); console.log('SUMMARY'); console.log('==============================================='); // Count different types of installations const dockerServers = serverNames.filter(name => mcpServers[name].command === 'docker'); const directServers = serverNames.filter(name => mcpServers[name].command === 'npx' || (mcpServers[name].args && mcpServers[name].args.includes('npx') && mcpServers[name].command !== 'docker')); const otherServers = serverNames.filter(name => !dockerServers.includes(name) && !directServers.includes(name)); if (dockerServers.length > 0) { console.log(`🐳 Docker-based (sandboxed): ${dockerServers.length}`); dockerServers.forEach(name => console.log(` - ${name}`)); } if (directServers.length > 0) { console.log(`āš ļø Direct installation: ${directServers.length}`); directServers.forEach(name => console.log(` - ${name}`)); } if (otherServers.length > 0) { console.log(`šŸ”§ Other configurations: ${otherServers.length}`); otherServers.forEach(name => console.log(` - ${name}`)); } console.log('\nšŸ’” Tips:'); console.log(' - Use `mcp info <package-name>` to get detailed information about a package'); console.log(' - Use `mcp uninstall <package-name> -c <client>` to remove a server'); console.log(' - Docker-based installations are safer as they run in sandboxed containers'); } catch (error) { if (error.code === 'ENOENT') { logger_1.logger.warn(`Configuration file not found for ${options.client}`); console.log('\nšŸ“„ Configuration file does not exist yet.'); console.log('This is normal if you haven\'t installed any MCP servers yet.'); console.log(`\nTo install your first MCP server, use:`); console.log(` mcp install <package-name> -c ${options.client}`); } else if (error instanceof SyntaxError) { logger_1.logger.error(`Invalid JSON in configuration file for ${options.client}`); console.log('\nāŒ The configuration file contains invalid JSON.'); console.log('Please check the file format or restore from a backup.'); if (client_ops_1.clientPaths[clientName]?.path) { console.log(`Configuration file location: ${client_ops_1.clientPaths[clientName].path}`); } } else { logger_1.logger.error('Failed to list MCP servers', error); } process.exit(1); } } //# sourceMappingURL=list.js.map