import { connectProfile, listMcpLibrary, loadMcpLibrary } from './index.js'; import { adapterCatalog } from './adapters.js'; const [command = 'profiles', profileName] = process.argv.slice(2); try { const library = await loadMcpLibrary(); if (command === 'profiles' || command === 'list') { console.log('ProjectOS MCP adapter library'); for (const { adapter, profiles } of listMcpLibrary(library)) { console.log(`\n${adapter.name} — ${adapter.title}`); console.log(` ${adapter.description}`); console.log(` Source: ${adapter.source}`); console.log(` Requirements: ${adapter.requires.join(', ')}`); for (const { profile, server } of profiles) { console.log(` ${profile.enabled ? 'enabled' : 'disabled'} profile '${profile.name}' → ${server.name} (${server.accessMode}, ${server.trust} trust, auth: ${server.authMode})${server.credentialRef ? `; credential ref ${server.credentialRef}` : ''}`); } } console.log('\nNamed profiles'); for (const profile of library.profiles) console.log(` ${profile.enabled ? 'enabled' : 'disabled'} ${profile.name}: ${profile.description}`); } else if (command === 'check' || command === 'connect') { if (!profileName) throw new Error(`Usage: pnpm mcp:${command === 'check' ? 'check' : 'connect'} `); const connection = await connectProfile(profileName, library); console.log(`Connected MCP profile '${connection.profile.name}'.`); for (const server of connection.servers) console.log(` ${server.definition.name}: ${server.tools.length} tools available (${server.definition.accessMode}).`); if (command === 'check') { await connection.close(); console.log('Connection check passed; servers were closed cleanly.'); } else { console.log('Profile remains connected. Press Ctrl+C to disconnect.'); await new Promise((resolve) => process.once('SIGINT', resolve)); await connection.close(); } } else if (command === 'catalog') { console.log(JSON.stringify(Object.values(adapterCatalog), null, 2)); } else { throw new Error(`Unknown command '${command}'. Use profiles, check , or connect .`); } } catch (error) { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }