File size: 2,325 Bytes
a8f4b72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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'} <profile-name>`);
    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<void>((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 <profile>, or connect <profile>.`);
  }
} catch (error) {
  console.error(error instanceof Error ? error.message : String(error));
  process.exitCode = 1;
}