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
JavaScript
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