UNPKG

@creedspace/mcp-server

Version:

Universal MCP server for Creed Space - AI safety guardrails in 10 seconds

206 lines 8.6 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const server_js_1 = require("./server.js"); const dotenv_1 = require("dotenv"); const fs = __importStar(require("fs")); // Load environment variables (0, dotenv_1.config)(); const program = new commander_1.Command(); program .name('creedspace-mcp') .description('Universal MCP server for Creed Space - AI safety guardrails in 10 seconds') .version('1.0.0') .option('-p, --persona <id>', 'Set the active persona', 'ambassador') .option('-u, --url <url>', 'API base URL', process.env.CREEDSPACE_API_URL || 'https://api.creed.space') .option('-k, --api-key <key>', 'API key for authentication', process.env.CREEDSPACE_API_KEY) .option('--offline', 'Enable offline mode with cached data') .option('--no-cache', 'Disable caching') .option('--cache-ttl <ms>', 'Cache TTL in milliseconds', '300000') .option('--config <file>', 'Load configuration from JSON file') .option('--generate-config', 'Generate example configuration files') .action(async (options) => { if (options.generateConfig) { generateConfigFiles(); return; } let config = { persona: options.persona, apiUrl: options.url, apiKey: options.apiKey, cacheEnabled: options.cache, cacheTtl: parseInt(options.cacheTtl), offlineMode: options.offline, }; // Load config from file if specified if (options.config) { try { const configFile = fs.readFileSync(options.config, 'utf-8'); const fileConfig = JSON.parse(configFile); config = { ...fileConfig, ...config }; } catch (error) { // SECURITY: Log config file access failures with context const errorContext = { configPath: options.config, error: error instanceof Error ? error.message : String(error), stack: error instanceof Error ? error.stack : undefined, timestamp: new Date().toISOString() }; console.error('[CONFIG_LOAD_ERROR]', JSON.stringify(errorContext)); // Provide actionable error message if (error instanceof Error) { const enhancedError = new Error(`Failed to load config file '${options.config}': ${error.message}`); enhancedError.cause = error; throw enhancedError; } process.exit(1); } } try { const server = new server_js_1.CreedSpaceMCPServer(config); await server.start(); } catch (error) { // SECURITY: Log server startup failures with full context const errorContext = { config: JSON.stringify(config, null, 2), error: error instanceof Error ? error.message : String(error), stack: error instanceof Error ? error.stack : undefined, timestamp: new Date().toISOString() }; console.error('[SERVER_START_ERROR]', JSON.stringify(errorContext)); if (error instanceof Error) { console.error('Failed to start MCP server:', error.message); console.error('Stack trace:', error.stack); } else { console.error('Failed to start server with unknown error:', String(error)); } process.exit(1); } }); program .command('test') .description('Test connection to Creed Space API') .option('-u, --url <url>', 'API base URL', 'http://localhost:8000') .action(async (options) => { console.log('Testing connection to Creed Space API...'); console.log(`URL: ${options.url}`); try { const { CreedSpaceClient } = await Promise.resolve().then(() => __importStar(require('./api-client.js'))); const client = new CreedSpaceClient({ apiUrl: options.url }); console.log('\nFetching personas...'); const personas = await client.getPersonas(); console.log(`✓ Found ${personas.length} personas:`); personas.forEach((p) => console.log(` - ${p.name} (${p.id})`)); console.log('\nFetching ambassador constitution...'); const constitution = await client.getMergedConstitution('ambassador'); console.log(`✓ Constitution loaded: ${constitution.totalRules} rules`); console.log('\n✅ API connection successful!'); } catch (error) { // SECURITY: Log API connection test failures with context const errorContext = { testUrl: options.url, error: error instanceof Error ? error.message : String(error), stack: error instanceof Error ? error.stack : undefined, timestamp: new Date().toISOString() }; console.error('[API_CONNECTION_TEST_ERROR]', JSON.stringify(errorContext)); console.error('\n❌ API connection failed:', error instanceof Error ? error.message : String(error)); if (error instanceof Error && error.stack) { console.error('Stack trace:', error.stack); } process.exit(1); } }); function generateConfigFiles() { // Generate Claude Desktop config const claudeConfig = { mcpServers: { creedspace: { command: 'npx', args: ['creedspace-mcp-server', '--persona', 'ambassador'], env: { CREEDSPACE_API_KEY: '${CREEDSPACE_API_KEY}', }, }, }, }; // Generate example .env file const envExample = `# Creed Space MCP Server Configuration CREEDSPACE_API_URL=https://api.creed.space CREEDSPACE_API_KEY=your-api-key-here CREEDSPACE_DEFAULT_PERSONA=ambassador `; // Generate package.json script example const packageJsonExample = { scripts: { 'mcp:ambassador': 'creedspace-mcp --persona ambassador', 'mcp:nanny': 'creedspace-mcp --persona nanny', 'mcp:sentinel': 'creedspace-mcp --persona sentinel', 'mcp:test': 'creedspace-mcp test', }, }; console.log('📁 Claude Desktop Configuration (claude_desktop_config.json):'); console.log('='.repeat(60)); console.log(JSON.stringify(claudeConfig, null, 2)); console.log('\n📁 Environment Variables (.env):'); console.log('='.repeat(60)); console.log(envExample); console.log('\n📁 Package.json Scripts:'); console.log('='.repeat(60)); console.log(JSON.stringify(packageJsonExample, null, 2)); console.log('\n✅ Configuration files generated!'); console.log('\nQuick Start:'); console.log('1. Copy the Claude Desktop config to your claude_desktop_config.json'); console.log('2. Run: npx creedspace-mcp-server --persona ambassador'); console.log('3. Restart Claude Desktop to load the MCP server'); } // Handle uncaught errors gracefully process.on('uncaughtException', (error) => { console.error('Uncaught exception:', error); process.exit(1); }); process.on('unhandledRejection', (error) => { console.error('Unhandled rejection:', error); process.exit(1); }); // Run the CLI program.parse(process.argv); //# sourceMappingURL=cli.js.map