memory-engineering
Version:
Advanced Memory-Aware Code Context System with claude-flow-inspired architecture, showcasing MongoDB + Voyage AI strategic positioning
65 lines (55 loc) ⢠2.3 kB
text/typescript
/**
* Memory Init Tool
* Initialize memory system for a project
*/
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { IMemoryManager } from '../memory/memory-manager.js';
import { logger } from '../utils/logger.js';
export const memoryInitTool: Tool = {
name: 'memory_init',
description: 'Initialize memory system for a project',
inputSchema: {
type: 'object',
properties: {
projectPath: { type: 'string', description: 'Project path to initialize' }
},
required: ['projectPath']
}
};
export function createMemoryInitHandler(memoryManager: IMemoryManager) {
return async (args: any) => {
try {
const { projectPath } = args;
// Check health status
const health = await memoryManager.getHealthStatus();
if (!health.healthy) {
throw new Error(`Memory system not healthy: ${health.error}`);
}
// Query existing memories for this project
const existingMemories = await memoryManager.query({
projectPath,
limit: 10
});
logger.info('Memory system initialized', {
projectPath,
existingMemoriesCount: existingMemories.length,
healthy: health.healthy,
metrics: health.metrics
});
const memoryTypes = [...new Set(existingMemories.map(m => m.memoryType))];
return {
content: [{
type: 'text',
text: `ā
Memory system initialized for project!\n\nš **Status:**\n- Health: ${health.healthy ? 'ā
Healthy' : 'ā Unhealthy'}\n- Existing memories: ${existingMemories.length}\n- Memory types: ${memoryTypes.join(', ') || 'None yet'}\n\nš **Available Tools:**\n1. memory_project_brief - Define project requirements\n2. memory_product_context - Product vision\n3. memory_active_context - Current work tracking\n4. memory_search - Search memories\n5. memory_codebase_embed - Index codebase\n\nš” Start with 'memory_project_brief' to establish project identity.`
}],
isError: false
};
} catch (error) {
logger.error('Failed to initialize memory system', error);
return {
content: [{ type: 'text', text: `ā Initialization error: ${error instanceof Error ? error.message : 'Unknown error'}` }],
isError: true
};
}
};
}