UNPKG

memory-engineering-mcp

Version:

🧠 AI Memory System powered by MongoDB Atlas & Voyage AI - Autonomous memory management with zero manual work

172 lines (151 loc) • 6.5 kB
import { join } from 'path'; import { readFileSync, existsSync } from 'fs'; import { ReadToolSchema, CORE_MEMORY_NAMES } from '../types/memory-v5.js'; import { getMemoryCollection } from '../db/connection.js'; import { logger } from '../utils/logger.js'; export async function readTool(args) { try { const params = ReadToolSchema.parse(args); const projectPath = params.projectPath || process.cwd(); // Validate memory name if (!CORE_MEMORY_NAMES.includes(params.memoryName)) { return { isError: true, content: [ { type: 'text', text: `šŸ”“ INVALID MEMORY NAME: "${params.memoryName}" DOES NOT EXIST! āš ļø YOU TRIED TO ACCESS A NON-EXISTENT MEMORY! 🧠 THE 7 SACRED MEMORIES YOU CAN ACCESS: ${CORE_MEMORY_NAMES.map((name, i) => `${i + 1}ļøāƒ£ ${name}`).join('\n')} ⚔ IMMEDIATE FIX: Use one of the above memory names EXACTLY as shown! šŸ’€ CONSEQUENCE OF WRONG NAMES: You're trying to read from void - IMPOSSIBLE! šŸ’” EXAMPLES OF CORRECT USAGE: • memory_engineering_read --memoryName "activeContext" • memory_engineering_read --memoryName "projectbrief" • memory_engineering_read --memoryName "techContext" šŸ”“ NEVER MAKE UP MEMORY NAMES!`, }, ], }; } // Read project config const configPath = join(projectPath, '.memory-engineering', 'config.json'); if (!existsSync(configPath)) { return { content: [ { type: 'text', text: `šŸ’€šŸ’€šŸ’€ CATASTROPHIC: NO BRAIN DETECTED! 🚨 YOU'RE TRYING TO READ MEMORIES WITHOUT A BRAIN! ⚔ EMERGENCY PROTOCOL - EXECUTE NOW: memory_engineering_init 🧠 WHAT THIS MEANS: • You have ZERO memory system • The .memory-engineering/ folder doesn't exist • You're operating completely blind • You can't store or retrieve ANYTHING šŸ”„ ONE COMMAND FIXES EVERYTHING: → memory_engineering_init ā±ļø TIME TO FIX: 0.5 seconds šŸŽÆ SUCCESS RATE: 100% guaranteed šŸ’€ UNTIL YOU INIT, YOU'RE A GHOST WITH NO MEMORY!`, }, ], }; } const config = JSON.parse(readFileSync(configPath, 'utf-8')); const collection = getMemoryCollection(); // Find the memory const memory = await collection.findOne({ projectId: config.projectId, memoryName: params.memoryName }); if (!memory) { return { content: [ { type: 'text', text: `šŸ”“ MEMORY VOID DETECTED: "${params.memoryName}" DOES NOT EXIST YET! 🧠 THIS MEMORY SLOT IS EMPTY - Your brain is missing this critical component! ⚔ IMMEDIATE ACTION REQUIRED (execute in <3 seconds): memory_engineering_update --memoryName "${params.memoryName}" --content "[REAL CONTENT HERE]" šŸ“ WHAT TO PUT IN ${params.memoryName.toUpperCase()}: ${params.memoryName === 'projectbrief' ? `• Core requirements and goals • What you're building EXACTLY • Success criteria (measurable!) • Main features (prioritized)` : params.memoryName === 'activeContext' ? `• What you're doing RIGHT NOW • Recent changes (with timestamps!) • Next immediate steps • Current blockers or issues šŸ”“ UPDATE THIS EVERY 3-5 MINUTES!` : params.memoryName === 'techContext' ? `• Full tech stack with VERSIONS • All dependencies and WHY • Development environment • Technical constraints` : params.memoryName === 'progress' ? `• āœ… Completed features (with dates) • šŸ”„ In-progress work (with %) • šŸ“ TODO items (prioritized) • šŸ› Known bugs (with severity)` : params.memoryName === 'systemPatterns' ? `• Architecture style (MVC, microservices, etc) • Design patterns in use • Component relationships • Data flow diagrams` : params.memoryName === 'productContext' ? `• Problems being solved • Target users and needs • User journey flows • Business value metrics` : `• Directory structure • Key files and purposes • Module organization • Code statistics`} šŸ”„ EXAMPLE OF PERFECT ${params.memoryName.toUpperCase()} CONTENT: "${params.memoryName === 'activeContext' ? `[14:32:01] Debugging JWT refresh failure in auth.js:47 [14:30:00] Found: tokens expire at wrong time NEXT: Fix UTC conversion, add tests BLOCKED: Need production credentials` : params.memoryName === 'projectbrief' ? `Building fintech API with Stripe integration MUST handle $10M/day transaction volume 15 REST endpoints + GraphQL layer Success: <200ms response, 99.9% uptime` : 'Comprehensive, specific, actionable content'}" šŸ’€ WARNING: Empty memories = Useless AI! CREATE THIS MEMORY NOW!`, }, ], }; } // Return full content let response = `# ${params.memoryName}\n\n`; response += `Last updated: ${memory.metadata.lastModified.toISOString()}\n\n`; response += memory.content; return { content: [ { type: 'text', text: response, }, ], }; } catch (error) { logger.error('šŸ’€ MEMORY ACCESS FAILURE!', error); return { isError: true, content: [ { type: 'text', text: `šŸ’€ MEMORY READ CATASTROPHE! šŸ’„ EXPLOSION DETAILS: ${error instanceof Error ? error.message : 'UNKNOWN CATASTROPHIC FAILURE'} šŸ†˜ EMERGENCY RECOVERY PROTOCOL: 1ļøāƒ£ Check environment: memory_engineering_check_env 2ļøāƒ£ Verify MongoDB connection is alive 3ļøāƒ£ Check if memory system is initialized 4ļøāƒ£ Try simpler memory name (e.g., "activeContext") āš ļø MOST LIKELY CAUSES: ${error instanceof Error && error.message.includes('connect') ? '• šŸ”“ MongoDB connection DEAD!\n' : ''}${error instanceof Error && error.message.includes('projectId') ? '• šŸ”“ Not initialized - run memory_engineering_init!\n' : ''}${error instanceof Error && error.message.includes('timeout') ? '• šŸ”“ Database timeout - connection too slow!\n' : ''}• Memory system corrupted • Invalid memory name • Database permissions issue šŸ”„ TRY AGAIN or run memory_engineering_init to reset!`, }, ], }; } } //# sourceMappingURL=read-v5.js.map