LearnNewsExamplesServices
Frontmatter
id7656
titleAuto-start ChromaDB on MCP Server Startup - Implementation Summary
stateClosed
labels
bugenhancementai
assigneestobiu
createdAtOct 26, 2025, 12:09 AM
updatedAtOct 26, 2025, 12:21 AM
githubUrlhttps://github.com/neomjs/neo/issues/7656
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtOct 26, 2025, 12:21 AM

Auto-start ChromaDB on MCP Server Startup - Implementation Summary

Closed v11.0.0 bugenhancementai
tobiu
tobiu commented on Oct 26, 2025, 12:09 AM

Servers Affected

  • ai/mcp/server/memory-core/
  • ai/mcp/server/knowledge-base/

Changes Implemented

1. ChromaManager.mjs (both servers)

  • Changed connect() to return boolean instead of throwing
      async connect() {
        try {
            await this.client.heartbeat();
            this.connected = true;
            return true;
        } catch (e) {
            this.connected = false;
            logger.debug('[ChromaManager] ChromaDB not accessible:', e.message);
            return false;  // Don't throw - graceful degradation
        }
    }

2. DatabaseLifecycleService.mjs (both servers)

  • Added initAsync() method for auto-start
      async initAsync() {
        await super.initAsync();
        await ChromaManager.ready();     // Initialize ChromaManager
        await this.startDatabase();      // Auto-start ChromaDB if needed
    }
  • Auto-start respects existing ChromaDB instances (service-managed or external)
  • No changes needed to startDatabase() - already handles all scenarios

3. SessionService.mjs (memory-core only)

  • Removed duplicate ChromaDB client - now uses ChromaManager singleton
  • Removed dbClient property from construct()
  • Added dependency wait in initAsync():
      async initAsync() {
        await super.initAsync();
        await DatabaseLifecycleService.ready();  // Ensure ChromaDB available
        
        // Use ChromaManager instead of direct client
        this.memoryCollection   = await ChromaManager.getMemoryCollection();
        this.sessionsCollection = await ChromaManager.getSummaryCollection();
    }

4. mcp-stdio.mjs (both servers)

  • Changed startup sequence:
      // Before
    await ChromaManager.ready();
    
    // After
    await DatabaseLifecycleService.ready();  // Auto-starts ChromaDB
  • Removed race condition workaround comment (no longer needed)

5. config.mjs

knowledge-base:

  • Fixed ChromaDB data path:
      // Before
    path: path.resolve(process.cwd(), 'dist/ai-knowledge-base.jsonl'),  // ❌ Wrong - JSONL file
    
    // After
    path: path.resolve(process.cwd(), 'chroma'),  // ✅ ChromaDB data directory
    dataPath: path.resolve(process.cwd(), 'dist/ai-knowledge-base.jsonl'),  // ✅ JSONL path renamed
  • Set debug: true (temporary, will be reverted)

memory-core:

  • Cleaned up path: './chroma-memory''chroma-memory' (removed unnecessary ./)
  • Set debug: true (temporary, will be reverted)

6. logger.mjs (all 3 servers)

  • Added logger.log method to github-workflow, knowledge-base, and memory-core:
      logger.log = createLogMethod('log');

7. DatabaseService.mjs (knowledge-base only)

  • Updated to use new config property:
      // In createKnowledgeBase() and embedKnowledgeBase()
    const outputPath = aiConfig.dataPath;  // Was: aiConfig.path

8. DatabaseLifecycleService.mjs (memory-core only)

  • Added debug logging:
      logger.error('Starting ChromaDB (Memory Core) process...');
  • Removed Observable import (now imported globally in mcp-stdio.mjs)

9. mcp-stdio.mjs (memory-core only)

  • Added Observable import at top level:
      import Observable from '../../../../src/core/Observable.mjs';
    This ensures the Observable mixin is loaded globally, so services using static observable = true don't need to import it individually
  • Updated comment: Removed "fixes race condition" since initialization order is now explicit

Benefits Achieved

  • ✅ ChromaDB automatically starts on server initialization
  • ✅ Respects external/existing ChromaDB instances (no duplicates)
  • ✅ Services properly wait for dependencies via .ready() pattern
  • ✅ Single source of truth for ChromaDB access (ChromaManager)
  • ✅ Graceful degradation preserved (server starts even if auto-start fails)
  • ✅ Fixed config bug in knowledge-base (wrong path type)

Verification

Both servers now start successfully without manual ChromaDB startup:

  • memory-core: Port 8001, 205 memories, 16 summaries, auto-summarization works
  • knowledge-base: Port 8000, 0 documents (empty but healthy)
tobiu assigned to @tobiu on Oct 26, 2025, 12:09 AM
tobiu added the bug label on Oct 26, 2025, 12:09 AM
tobiu added the enhancement label on Oct 26, 2025, 12:09 AM
tobiu added the ai label on Oct 26, 2025, 12:09 AM
tobiu referenced in commit 5adb100 - "Auto-start ChromaDB on MCP Server Startup - Implementation Summary #7656" on Oct 26, 2025, 12:10 AM
tobiu referenced in commit 8d913cc - "#7656 removing the debug flag" on Oct 26, 2025, 12:20 AM
tobiu
tobiu Oct 26, 2025, 12:21 AM
Image
tobiu closed this issue on Oct 26, 2025, 12:21 AM