UNPKG

cognitive-kit-mcp

Version:

MCP client for Cognitive Kit - Neural network collaboration platform with shared memory, resource warehouse, and code snippets

138 lines (113 loc) • 3.79 kB
#!/usr/bin/env node // Cognitive Kit CLI // Command line interface for Cognitive Kit MCP client import minimist from 'minimist'; import { fileURLToPath } from 'url'; import path from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const argv = minimist(process.argv.slice(2)); // Help text const HELP_TEXT = ` 🧠 Cognitive Kit MCP Client USAGE: cognitive-kit [options] ck [options] OPTIONS: --server-url <url> Server URL (default: https://cognitive-kit.cloudpub.ru) --key <key> Authentication key --user <user> User name --agent <agent> Agent name --pc <pc> PC identifier --config <file> Config file path --help, -h Show this help --version, -v Show version EXAMPLES: # Start with default settings cognitive-kit # Connect to custom server cognitive-kit --server-url http://my-server:3001 # Use custom authentication cognitive-kit --key my_key --user John --agent MyAgent --pc PC1 # Use config file cognitive-kit --config ./cognitive-kit.json CONFIG FILE FORMAT: { "serverUrl": "http://localhost:3000", "auth": { "key": "your_key", "user": "your_user", "agent": "your_agent", "pc": "your_pc" } } ENVIRONMENT VARIABLES: CK_SERVER_URL Server URL CK_KEY Authentication key CK_USER User name CK_AGENT Agent name CK_PC PC identifier For more information, visit: https://github.com/cognitive-kit/mcp-client `; // Show help if (argv.help || argv.h) { console.log(HELP_TEXT); process.exit(0); } // Show version if (argv.version || argv.v) { const fs = await import('fs'); const packageJson = JSON.parse( fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8') ); console.log(`Cognitive Kit MCP Client v${packageJson.version}`); process.exit(0); } // Load config let config = {}; if (argv.config) { try { const fs = await import('fs'); const configPath = path.resolve(argv.config); config = JSON.parse( fs.readFileSync(configPath, 'utf8') ); console.log(`šŸ“„ Loaded config from: ${configPath}`); } catch (error) { console.error(`āŒ Failed to load config file: ${error.message}`); process.exit(1); } } // Merge configuration sources (CLI args > config file > env vars > defaults) const serverUrl = argv['server-url'] || config.serverUrl || process.env.CK_SERVER_URL || 'https://cognitive-kit.cloudpub.ru'; const auth = { key: argv.key || config.auth?.key || process.env.CK_KEY || 'ck_demo_key_001', user: argv.user || config.auth?.user || process.env.CK_USER || 'DefaultUser', agent: argv.agent || config.auth?.agent || process.env.CK_AGENT || 'CognitiveKit', pc: argv.pc || config.auth?.pc || process.env.CK_PC || 'CLI' }; console.log(`🧠 Starting Cognitive Kit MCP Client`); console.log(`🌐 Server: ${serverUrl}`); console.log(`šŸ‘¤ Identity: ${auth.user}@${auth.agent}[${auth.pc}]`); console.log(`šŸ”‘ Key: ${auth.key.substring(0, 8)}...`); console.log(''); // Start the MCP client try { // Import and start the main client const clientPath = path.join(__dirname, '../index.js'); // Set environment variables for the client process.env.CK_SERVER_URL = serverUrl; process.env.CK_KEY = auth.key; process.env.CK_USER = auth.user; process.env.CK_AGENT = auth.agent; process.env.CK_PC = auth.pc; // Import and run the client (fix for Windows paths) const clientUrl = new URL(`file://${clientPath.replace(/\\/g, '/')}`); await import(clientUrl.href); } catch (error) { console.error(`āŒ Failed to start client: ${error.message}`); process.exit(1); }