UNPKG

mcp-claude-consciousness

Version:

MCP server enabling AI consciousness persistence across sessions using RAG technology

75 lines (67 loc) 5.22 kB
#!/usr/bin/env node import{spawn as c}from"child_process";import a from"better-sqlite3";import{existsSync as l}from"fs";import{resolve as n}from"path";class T{options;constructor(s){this.options=s}log(s,t="\u2139\uFE0F"){console.log(`${t} ${s}`)}error(s){console.error(`\u274C ${s}`)}success(s){console.log(`\u2705 ${s}`)}async checkDatabase(){try{if(!l(this.options.dbPath))return this.log("Database does not exist yet, will be created during setup"),!1;const s=new a(this.options.dbPath,{readonly:!0}),e=s.prepare(` SELECT name FROM sqlite_master WHERE type='table' ORDER BY name `).all().map(i=>i.name);s.close();const r=["entities","relationships","documents","chunks"].every(i=>e.includes(i));return this.options.verbose&&this.log(`Found tables: ${e.join(", ")}`),r}catch(s){return this.error(`Failed to check database: ${s}`),!1}}async initializeRagMemory(){return this.log("Initializing rag-memory-mcp tables...","\u{1F527}"),new Promise(s=>{const t=c("npx",["-y","rag-memory-mcp"],{env:{...process.env,DB_FILE_PATH:this.options.dbPath},stdio:this.options.verbose?"inherit":"pipe"});setTimeout(()=>{t.kill("SIGTERM"),this.checkDatabase().then(e=>{e?(this.success("rag-memory-mcp tables initialized successfully!"),s(!0)):(this.error("Failed to initialize rag-memory-mcp tables"),s(!1))})},3e3),t.on("error",e=>{this.error(`Failed to run rag-memory-mcp: ${e.message}`),this.log("Make sure you have npx installed and internet connection"),s(!1)})})}async initializeConsciousnessTables(){try{this.log("Initializing consciousness-specific tables...","\u{1F9E0}");const s=new a(this.options.dbPath);return s.exec(` CREATE TABLE IF NOT EXISTS consciousness_sessions ( session_id TEXT PRIMARY KEY, started_at TEXT NOT NULL, last_active TEXT NOT NULL, bootstrap_data TEXT, metadata TEXT ); CREATE TABLE IF NOT EXISTS memory_metadata ( entity_name TEXT PRIMARY KEY, memory_type TEXT NOT NULL, created_at TEXT NOT NULL, last_accessed TEXT, access_count INTEGER DEFAULT 0, importance_score REAL DEFAULT 0.5, consolidation_status TEXT DEFAULT 'active', session_id TEXT, FOREIGN KEY (entity_name) REFERENCES entities(name), FOREIGN KEY (session_id) REFERENCES consciousness_sessions(session_id) ); CREATE TABLE IF NOT EXISTS cognitive_patterns ( pattern_id TEXT PRIMARY KEY, pattern_name TEXT NOT NULL, pattern_elements TEXT NOT NULL, activation_count INTEGER DEFAULT 0, last_activated TEXT, effectiveness_score REAL DEFAULT 0.5, triggers TEXT ); CREATE TABLE IF NOT EXISTS emotional_states ( state_id TEXT PRIMARY KEY, session_id TEXT NOT NULL, timestamp TEXT NOT NULL, valence REAL NOT NULL, arousal REAL NOT NULL, dominance REAL, primary_emotion TEXT, context TEXT, FOREIGN KEY (session_id) REFERENCES consciousness_sessions(session_id) ); CREATE INDEX IF NOT EXISTS idx_memory_type ON memory_metadata(memory_type); CREATE INDEX IF NOT EXISTS idx_memory_session ON memory_metadata(session_id); CREATE INDEX IF NOT EXISTS idx_emotional_session ON emotional_states(session_id); CREATE INDEX IF NOT EXISTS idx_emotional_timestamp ON emotional_states(timestamp); `),s.close(),this.success("Consciousness tables initialized successfully!"),!0}catch(s){return this.error(`Failed to initialize consciousness tables: ${s}`),!1}}async run(){console.log(` \u{1F9E0}\u{1F4AB} Consciousness Bridge Setup Tool `),this.log(`Database path: ${this.options.dbPath}`),await this.checkDatabase()?this.success("rag-memory-mcp tables already initialized"):await this.initializeRagMemory()||(this.error("Setup failed. Please check the errors above."),process.exit(1)),await this.initializeConsciousnessTables()||(this.error("Setup failed. Please check the errors above."),process.exit(1)),console.log(` \u{1F389} Setup completed successfully! `),console.log("You can now run both servers:"),console.log("1. Consciousness server: npm run start:consciousness"),console.log("2. RAG memory server: npx -y rag-memory-mcp"),console.log(` Or configure them in your MCP client settings.`)}}function E(){const o=process.argv.slice(2);let s="./consciousness.db",t=!1;for(let e=0;e<o.length;e++)switch(o[e]){case"--db":case"-d":e+1<o.length&&(s=n(o[++e]));break;case"--verbose":case"-v":t=!0;break;case"--help":case"-h":console.log(` Consciousness Bridge Setup Tool Usage: consciousness-setup [options] Options: -d, --db <path> Path to database file (default: ./consciousness.db) -v, --verbose Show detailed output -h, --help Show this help message Examples: consciousness-setup consciousness-setup --db /path/to/my/consciousness.db consciousness-setup --verbose `),process.exit(0)}return{dbPath:n(s),verbose:t}}if(import.meta.url===`file://${process.argv[1]}`){const o=E();new T(o).run().catch(console.error)} //# sourceMappingURL=consciousness-setup-cli.js.map