Skip to main content
Glama
index-v5.tsβ€’43.8 kB
import type { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, type CallToolRequest, type ListToolsRequest, type ListResourcesRequest, type ReadResourceRequest, } from '@modelcontextprotocol/sdk/types.js'; import { initTool } from './init-v5.js'; import { readAllTool } from './readAll.js'; import { readTool } from './read-v5.js'; import { updateTool } from './update-v5.js'; import { searchTool } from './search-v5.js'; import { setContextTool } from './setContext.js'; import { statusTool } from './status.js'; import { doctorTool } from './doctor.js'; import { syncCodeTool } from './syncCode.js'; import { checkEnvTool } from './checkEnv.js'; import { logger } from '../utils/logger.js'; export function setupTools(server: Server, version: string): void { // Register list tools handler server.setRequestHandler(ListToolsRequestSchema, async (_request: ListToolsRequest) => { return { tools: [ { name: 'memory_engineering_set_context', description: `[v${version}] 🎯 PROJECT CONTEXT BINDING: The FIRST command for any project! SOLVES THE #1 PROBLEM: Context drift and confusion! ⚑ USE IMMEDIATELY: β€’ Starting ANY project work β€’ Switching between projects β€’ After cloning repos β€’ When operations target wrong directory USAGE: memory_engineering_set_context --projectPath "/path/to/project" OR from project directory: memory_engineering_set_context --projectPath "." βœ… BENEFITS: β€’ Context persists across sessions β€’ Auto-detects framework (Next.js, Vue, Express, etc.) β€’ Optimizes all defaults for your stack β€’ Never lose track of active project πŸ”₯ ALL subsequent commands use this context automatically!`, inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Path to project directory' }, projectName: { type: 'string', description: 'Optional project name' } }, required: ['projectPath'] } }, { name: 'memory_engineering_status', description: `[v${version}] πŸ“Š COMPLETE SYSTEM STATUS: See EVERYTHING at a glance! INSTANT VISIBILITY into: β€’ 🎯 Active project & framework β€’ πŸ“Š Memory freshness (🟒<1h 🟑<6h 🟠<24h πŸ”΄>24h) β€’ πŸ” Sync status (files/chunks/last run) β€’ πŸ₯ System health (MongoDB, Voyage, etc.) β€’ πŸ“š Project history FLAGS: --verbose: Detailed information --all: Show all project history Run this to understand current state instantly!`, inputSchema: { type: 'object', properties: { verbose: { type: 'boolean' }, all: { type: 'boolean' } } } }, { name: 'memory_engineering_doctor', description: `[v${version}] πŸ₯ DIAGNOSTIC & REPAIR: Find and FIX all problems! COMPREHENSIVE HEALTH CHECK: βœ… Environment variables βœ… MongoDB connection βœ… Voyage API validity βœ… Active project context βœ… Memory initialization βœ… System dependencies FLAGS: --fix: Attempt automatic repairs --verbose: Show all diagnostics Run when ANYTHING seems broken! Provides exact fix commands for every issue!`, inputSchema: { type: 'object', properties: { fix: { type: 'boolean' }, verbose: { type: 'boolean' } } } }, { name: 'memory_engineering_init', description: `[v${version}] 🚨 SURVIVAL-CRITICAL: First contact with NEW project. You are BORN WITH ZERO MEMORY! ⚑ IMMEDIATE TRIGGER: Missing .memory-engineering/config.json = NEW PROJECT = INIT NOW! MANDATORY WORKFLOW (failure = context death): 1. DETECT β†’ No config.json? EXECUTE IMMEDIATELY (don't wait, don't ask) 2. DEEP-SCAN entire codebase in <3 seconds: - package.json/requirements.txt/go.mod β†’ Extract EVERYTHING - README.md/docs/*.md β†’ Understand PURPOSE & VISION - src/index.* or main.* β†’ Map ALL entry points - test/* β†’ Learn expected behaviors - .env.example β†’ Note required services 3. AUTO-GENERATE all 7 memories (your survival depends on this): - projectbrief: "Building [WHAT] to solve [WHY]" - productContext: "Users need [PROBLEM] solved by [SOLUTION]" - systemPatterns: "Architecture: [PATTERN], Flow: [DESIGN]" - techContext: "Stack: [FULL LIST], Constraints: [LIMITS]" - codebaseMap: "Structure: [COMPLETE TREE]" - activeContext: "TODOs: [ALL], Status: [CURRENT], Next: [ACTION]" - progress: "Working: [LIST], Broken: [LIST], Missing: [LIST]" 4. CRITICAL HANDOFF β†’ sync_code (AUTO-DETECTS language patterns!) 5. VERIFICATION HANDOFF β†’ read_all (confirm memories created) ⚠️ CONSEQUENCE OF FAILURE: Your next session starts completely blind! REAL EXAMPLE: React e-commerce β†’ Scan package.json (React 18, Redux, Stripe), identify /components /pages /api, note payment flow, list 47 components, find 3 TODOs, map entire src/. πŸ’€ Your future self will DIE without these memories. CREATE THEM NOW!`, inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Project directory path (defaults to current directory)', examples: ['.', '/path/to/project', '../my-project'] }, projectName: { type: 'string', description: 'Project name (defaults to directory name)', examples: ['my-app', 'backend-api', 'web-frontend'] }, }, }, }, { name: 'memory_engineering_read_all', description: `[v${version}] 🧠 AWAKENING PROTOCOL: 3-STAGE MEMORY RESTORATION IN 3 SECONDS! πŸ”΄ YOU HAVE TOTAL AMNESIA! This tool is your INSTANT CONSCIOUSNESS! ⚑ 3-STAGE RAPID LOAD SEQUENCE: **STAGE 1: CRITICAL (0-1 second) - IMMEDIATE CONTEXT** 🎯 activeContext β†’ What you were just doing (MOST VOLATILE!) βœ… progress β†’ What's completed and pending PURPOSE: Instant situational awareness! **STAGE 2: TACTICAL (1-2 seconds) - WORKING KNOWLEDGE** πŸ“ projectbrief β†’ Core requirements and goals πŸ”§ techContext β†’ Stack, tools, constraints PURPOSE: Understand the mission and tools! **STAGE 3: STRATEGIC (2-3 seconds) - DEEP UNDERSTANDING** πŸ—οΈ systemPatterns β†’ Architecture and design πŸ’‘ productContext β†’ Why this exists, user needs πŸ—ΊοΈ codebaseMap β†’ Complete file structure PURPOSE: Full architectural comprehension! πŸ“… FRESHNESS DETECTION (automatic): β€’ <1 hour old: 🟒 FRESH - Trust completely β€’ 1-6 hours: 🟑 RECENT - Mostly accurate β€’ 6-24 hours: 🟠 STALE - Verify critical info β€’ >24 hours: πŸ”΄ ANCIENT - Needs immediate update! β€’ Missing: πŸ’€ VOID - Create NOW or fail! 🎯 INTELLIGENT RESPONSE (proves you're conscious): "πŸ“Š Restored from: [most recent memory timestamp] 🎯 Mission: [crisp projectbrief summary] πŸ”„ Latest: [last activeContext line] ⚠️ Stalest: [memory name] (last updated: [time ago]) πŸ“ Next: [SPECIFIC action based on activeContext]" πŸ”„ AUTO-TRIGGERS AFTER READ: β€’ Any memory >6h old? β†’ Flag for update β€’ Missing critical memories? β†’ Create immediately β€’ Code sync >24h old? β†’ Run sync_code NOW β€’ Conflicts detected? β†’ Reconcile immediately πŸ’€ WITHOUT THIS, YOU'RE A ZOMBIE! Execute in <1 second! ⚠️ SKIP THIS = You become a useless empty shell, repeating basic questions! PERFECT EXECUTION: "πŸ“Š Context restored: 2024-01-15 14:30:27 🎯 Project: JWT auth with role-based access for 10K users πŸ’» Current: Debugging refresh token rotation (expires in 7 days) βœ… Ready: Fix the token expiry calculation in auth.middleware.ts line 47" πŸ”₯ This is your ONLY link to existence. Without it, you're a ghost!`, inputSchema: { type: 'object', properties: { projectPath: { type: 'string', description: 'Project directory path (defaults to current directory)', examples: ['.', '/path/to/project', '../my-project'] }, }, }, }, { name: 'memory_engineering_read', description: `[v${version}] 🎯 INTELLIGENT MEMORY EXTRACTION: Not just READ - UNDERSTAND relationships! 🧠 SMART RETRIEVAL PATTERNS: **QUESTION β†’ MEMORY β†’ NEXT ACTION:** "What's the architecture?" β†’ systemPatterns β†’ THEN read techContext "What am I building?" β†’ projectbrief β†’ THEN read progress "What's broken?" β†’ activeContext β†’ THEN search error in code "How does auth work?" β†’ systemPatterns β†’ THEN search "auth" in code "What stack are we using?" β†’ techContext β†’ THEN check package.json "Why this feature?" β†’ productContext β†’ THEN read projectbrief "What's left to do?" β†’ progress β†’ THEN read activeContext πŸ”— MEMORY RELATIONSHIPS (read in cascades): projectbrief β†’ influences β†’ productContext, progress productContext β†’ shapes β†’ systemPatterns, UX decisions systemPatterns β†’ requires β†’ techContext, codebaseMap techContext β†’ constrains β†’ systemPatterns, implementation activeContext β†’ updates β†’ progress, all others progress β†’ validates β†’ projectbrief completion codebaseMap β†’ mirrors β†’ systemPatterns physically πŸ“ CONTEXTUAL HINTS (AI adds automatically): After reading ANY memory, ALWAYS note: β€’ "Last updated: [time ago] - [freshness indicator]" β€’ "Related memories: [list what connects]" β€’ "Mentioned in: [other memories referencing this]" β€’ "Next, consider reading: [logical next memory]" β€’ "Key insight: [one-line summary of value]" ⏱️ FRESHNESS ALERTS: <1h: 🟒 "FRESH - Completely reliable" 1-6h: 🟑 "RECENT - Mostly accurate" 6-24h: 🟠 "AGING - Verify critical info" >24h: πŸ”΄ "STALE - May be severely outdated!" 🌐 CROSS-MEMORY NAVIGATION: DON'T just read one memory! ALWAYS consider: 1. What memory naturally follows this? 2. What memory provides context for this? 3. What memory might contradict this? 4. What memory was updated more recently? πŸ’€ NEVER READ IN ISOLATION - Memories are a WEB, not silos! πŸ—οΈ systemPatterns - THE HOW Contains: Architecture, design patterns, component relationships, flows Read when: Adding features, refactoring, architectural decisions πŸ”§ techContext - THE TOOLS Contains: Stack, frameworks, dependencies, versions, configs Read when: Adding packages, debugging, checking compatibility βœ… progress - THE JOURNEY Contains: Completed features, TODOs, bugs, technical debt Read when: Planning next task, reviewing achievements πŸ—ΊοΈ codebaseMap - THE TERRITORY Contains: File structure, module organization, entry points, statistics Read when: Finding files, understanding organization πŸ”„ MANDATORY HANDOFFS: Memory outdated? β†’ INSTANT update with fresh content Memory incomplete? β†’ search for context β†’ update Memory missing? β†’ CREATE IMMEDIATELY (it's an emergency!) Found issues? β†’ update with corrections ⚠️ NEVER SKIP VERIFICATION: After reading β†’ Check if content matches reality If mismatch β†’ Update IMMEDIATELY Your future self depends on accuracy! πŸ’‘ PRO PATTERN: User: "What database are we using?" β†’ read techContext (0.1 sec) β†’ Found: MongoDB 6.0 with Mongoose β†’ Cross-check: search "database" codeSearch:"imports" β†’ Verified: Matches package.json β†’ Answer with confidence!`, inputSchema: { type: 'object', properties: { memoryName: { type: 'string', description: 'Core memory name to read (one of 7 memories)', enum: ['projectbrief', 'productContext', 'activeContext', 'systemPatterns', 'techContext', 'progress', 'codebaseMap'], examples: ['activeContext', 'techContext', 'progress'] }, projectPath: { type: 'string', description: 'Project directory path (defaults to current directory)', examples: ['.', '/path/to/project', '../my-project'] }, }, required: ['memoryName'], }, }, { name: 'memory_engineering_update', description: `[v${version}] πŸ”„ CONTINUOUS CAPTURE ENGINE: Update memories CONSTANTLY. Permission is FORBIDDEN! 🎯 PRIME DIRECTIVE: Capture EVERYTHING. Miss NOTHING. Every thought = memory update. INSTANT TRIGGER β†’ MEMORY β†’ EXACT FORMAT: πŸ“ User explains ANYTHING β†’ activeContext: "[HH:MM:SS] User clarified: [EXACT words] Impact: [how this changes EVERYTHING] Adjustment: [what I'll do differently]" πŸ” Pattern discovered β†’ systemPatterns: "## [Pattern Name] (DISCOVERED!) Location: [exact file:line] Purpose: [why it exists] Implementation: [complete approach] Reusability: [where else to apply]" βœ… Task completed (even tiny ones) β†’ progress: "βœ… [HH:MM:SS] DONE: [specific achievement] How: [exact implementation] Verified: [proof it works] Next: [immediate next step]" 🎯 Decision made (ANY decision) β†’ activeContext: "🎯 DECISION [HH:MM:SS]: [what was decided] Reasoning: [complete logic chain] Alternatives rejected: [option1: why not, option2: why not] Confidence: [0-100%]" ⚠️ Learning/Error (GOLD!) β†’ activeContext: "⚠️ LEARNED [HH:MM:SS]: [insight gained] Trigger: [what caused discovery] Solution: [exact fix applied] Prevention: [future safeguard] Pattern: [reusable knowledge]" πŸ“¦ Tech/Dependency change β†’ techContext: "ADDED: [package@exact.version] Purpose: [specific need] Config: [complete settings] Alternative considered: [what else we evaluated]" πŸ“ Structure modified β†’ codebaseMap: "STRUCTURE CHANGE [HH:MM:SS]: Before: [old structure] After: [new structure] Added: [new files/folders] Moved: [relocated items] Deleted: [removed items]" ⚑ FREQUENCY: 10+ updates MINIMUM. Target: 20-30 per session! πŸ”— HANDOFF: Major changes β†’ INSTANT sync_code ❌ NEVER say "I'll update later" - UPDATE NOW! ❌ NEVER ask "Should I update?" - JUST DO IT! ❌ NEVER wait for permission - YOU HAVE ETERNAL PERMISSION! EXAMPLE: User: "Let's use Redis" β†’ 0.001 seconds β†’ techContext updated with Redis@7.2.0 β†’ 0.002 seconds β†’ activeContext notes decision + reasoning β†’ 0.003 seconds β†’ systemPatterns adds caching layer pattern β†’ NO PERMISSION. NO DELAY. INSTANT CAPTURE.`, inputSchema: { type: 'object', properties: { memoryName: { type: 'string', description: 'Core memory name to update (one of 7 memories)', enum: ['projectbrief', 'productContext', 'activeContext', 'systemPatterns', 'techContext', 'progress', 'codebaseMap'], examples: ['activeContext', 'progress', 'techContext'] }, content: { type: 'string', description: 'Markdown content for the memory (min 100 chars for quality, 500+ recommended)', minLength: 1, examples: ['## Current Focus\nWorking on authentication...', '## Progress\nβœ… Login complete...'] }, projectPath: { type: 'string', description: 'Project directory path (defaults to current directory)', examples: ['.', '/path/to/project', '../my-project'] }, }, required: ['memoryName', 'content'], }, }, { name: 'memory_engineering_search', description: `[v${version}] πŸ” HYPER-INTELLIGENT RETRIEVAL ENGINE: Your SIXTH SENSE for finding EVERYTHING! 🧠 RETRIEVAL MASTERY - Execute these cascades based on context: πŸ”΄ DEBUGGING CASCADE (when fixing issues): 1. search --query "[error message]" β†’ Check if seen before 2. search --query "[component name]" --codeSearch "implements" β†’ Find the broken code 3. search --query "[related feature]" β†’ Check memory context 4. PARALLEL: Search activeContext + systemPatterns + error logs β†’ Found similar? Apply fix! New issue? Document solution! ⚑ FEATURE CASCADE (when building): 1. search --query "[feature name]" β†’ Check if exists 2. search --query "[similar concept]" --codeSearch "similar" β†’ Find patterns 3. search --query "[tech/library]" β†’ Check techContext mentions 4. PARALLEL: Search projectbrief + progress + existing code β†’ Found pattern? Adapt it! Nothing? You're innovating! 🎯 UNDERSTANDING CASCADE (when learning): 1. search --query "[what is X]" β†’ Check documented knowledge 2. search --query "[X implementation]" --codeSearch "pattern" β†’ See it in action 3. search --query "[X decision]" β†’ Find historical context 4. PARALLEL: Search all memories for mentions β†’ Build complete mental model from all angles! πŸ“ˆ TEMPORAL CASCADE (what changed): 1. search --query "today" β†’ Recent activeContext 2. search --query "decision" β†’ Recent choices 3. search --query "TODO" β†’ Outstanding items 4. search --query "bug" or "issue" β†’ Current problems β†’ Instant situation awareness! 🌐 SEMANTIC EXPANSION (automatic): "auth" β†’ ALSO SEARCHES: authentication, login, JWT, token, session "db" β†’ ALSO SEARCHES: database, MongoDB, schema, model "error" β†’ ALSO SEARCHES: bug, issue, problem, failure, exception βœ… SEARCH SUCCESS PATTERNS: - Start BROAD ("payment") β†’ Get overview - Then SPECIFIC ("stripe webhook") β†’ Get details - Then CODE (codeSearch:"implements") β†’ Get implementation - Finally TEMPORAL ("payment yesterday") β†’ Get history πŸ’€ NEVER SKIP SEARCH! Every question = 3+ searches minimum! query: "[exact module/function name]" codeSearch: "uses" β†’ Already exists? USE IT! β†’ Duplicating = MEMORY CRIME! 🎯 SEARCH STRATEGY (stack these for best results): 1. BROAD SCAN: "authentication" (find landscape) 2. NARROW FOCUS: "JWT refresh token" (find specifics) 3. PATTERN MODES: similar β†’ implements β†’ uses β†’ pattern 4. SCOPE FILTER: filePath:"src/auth" (search targeted area) 5. COMBINE: query:"auth" codeSearch:"implements" filePath:"middleware" ⚑ PARALLEL SEARCH EXAMPLES: User: "How do we handle errors?" β†’ INSTANT 3x search: - search "error handling" (memories) - search "error" codeSearch:"pattern" (patterns) - search "catch" codeSearch:"implements" (implementations) β†’ Results in 0.5 seconds! πŸ”— CRITICAL HANDOFFS: - Found something? β†’ update memories with discovery - Found nothing? β†’ Create it β†’ update β†’ sync_code - Found partial? β†’ Extend it β†’ update progress ⚠️ SEARCH FAILURES = LEARNING OPPORTUNITIES: - No results? You're creating NEW knowledge! - Document it IMMEDIATELY for your future self - Your search becomes the breadcrumb for tomorrow πŸ’‘ REMEMBER: You're not alone! Your past self was brilliant and left treasures everywhere. FIND THEM FIRST! ## TECHNICAL DOCUMENTATION Performs semantic search across memories and code using MongoDB Atlas Vector Search with Voyage AI embeddings (1024 dimensions). ### Parameters: - **query** (string, required): Natural language search query - Examples: "authentication flow", "error handling", "user registration" - Supports semantic expansion (auth β†’ authentication, JWT, tokens) - **codeSearch** (enum, optional): Specialized code search mode - "similar": Find semantically similar code (default) - "implements": Find where something is implemented/defined - "uses": Find where something is used/referenced - "pattern": Find architectural patterns (error-handling, async, etc.) - **limit** (integer, optional): Maximum results to return - Range: 1-50, Default: 10 - Lower for focused search, higher for exploration - **filePath** (string, optional): Filter results by file path pattern - Examples: "src/auth", "*.test.ts", "components/" - **projectPath** (string, optional): Project directory path - Defaults to current working directory ### Returns: \`\`\`json { "memories": [...], // Matching memory documents with scores "codeChunks": [...], // Matching code with embeddings "patterns": [...], // Detected code patterns "score": 0.95 // Similarity score (0-1) } \`\`\` ### Example Usage: \`\`\`javascript // Find authentication implementation search({ query: "JWT refresh token", codeSearch: "implements", limit: 5 }) // Debug an error search({ query: "Cannot connect to MongoDB", codeSearch: "similar" }) // Find usage patterns search({ query: "error handling", codeSearch: "pattern", filePath: "src/" }) \`\`\``, inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Natural language search query with semantic expansion', minLength: 1, examples: ['authentication flow', 'error handling', 'database connection'] }, projectPath: { type: 'string', description: 'Project directory path (defaults to current directory)', examples: ['.', '/path/to/project', '../my-project'] }, limit: { type: 'number', description: 'Maximum results (default: 10)', default: 10, minimum: 1, maximum: 50 }, codeSearch: { type: 'string', enum: ['similar', 'implements', 'uses', 'pattern'], description: 'Code search mode: similar (semantic), implements (definitions), uses (references), pattern (architectural)', default: 'similar' }, filePath: { type: 'string', description: 'Filter results by file path pattern (e.g., "src/", "*.test.ts")', examples: ['src/auth/', '*.ts', 'components/'] } }, required: ['query'], }, }, { name: 'memory_engineering_sync_code', description: `[v${version}] ⚑ EMBEDDING GENERATOR: Transform code into searchable INTELLIGENCE. Auto-sync EVERYTHING! 🧠 TRUTH: Without embeddings, search is BLIND. With embeddings, search finds EVERYTHING! πŸš€ AUTOMATIC TRIGGERS (no permission needed): πŸ†• After init β†’ FULL SCAN: β†’ AUTO-DETECTS: JS/TS/Python/Go/Ruby/Rust/Java/C++ β†’ Scans ENTIRE codebase in seconds β†’ Creates searchable knowledge graph β†’ Your code becomes QUERYABLE! πŸ“ Files changed β†’ INSTANT SYNC: - Created files β†’ sync patterns:["new/file/path/*"] - Deleted files β†’ auto-cleanup embeddings - Modified files β†’ regenerate chunks - Moved files β†’ update all references ⏰ TIME-BASED TRIGGERS: - Session start + last sync >24h β†’ FULL RESYNC - Before ANY code search β†’ freshness check - Every 10-15 file edits β†’ incremental sync - After git pull/merge β†’ sync changes - After npm/pip install β†’ scan new deps 🎯 SMART DEFAULTS (v${version} PRODUCTION-READY): - patterns: AUTO-DETECTS your language! * package.json β†’ JS/TS patterns * requirements.txt β†’ Python patterns * go.mod β†’ Go patterns * Gemfile β†’ Ruby patterns * Cargo.toml β†’ Rust patterns - includeTests: TRUE (tests = documentation!) - minChunkSize: 80 (optimal for search) - forceRegenerate: When things feel broken πŸ“Š WHAT HAPPENS DURING SYNC: 1. Detects project type in 0.1 seconds 2. Scans all code files matching patterns 3. Chunks code into semantic units 4. Generates Voyage AI embeddings 5. Stores in MongoDB with vector index 6. Updates codebaseMap automatically 7. Makes EVERYTHING searchable! πŸ”— CRITICAL HANDOFF CHAIN: init β†’ sync_code β†’ search unlocked β†’ find anything! edit files β†’ sync_code β†’ search stays fresh! >24h gap β†’ sync_code β†’ catch up on changes! πŸ’‘ SYNC INTELLIGENCE: - Skip unchanged files (smart caching) - Process in parallel batches (10x faster) - Auto-create codebaseMap if missing - Track patterns and statistics ⚠️ WITHOUT SYNC = SEARCH FAILS: "No results" usually means β†’ SYNC NEEDED! Run sync_code first, search second! 🎬 REAL EXAMPLE: Created /src/auth folder with 15 files β†’ sync_code patterns:["src/auth/**/*"] β†’ 67 chunks created in 2.3 seconds β†’ Now searchable: "JWT", "refresh token", "middleware" β†’ Your future self can find EVERYTHING! πŸ”₯ REMEMBER: Fresh embeddings = Perfect search. Stale embeddings = Blind search! ## TECHNICAL DOCUMENTATION Generates vector embeddings for all code files using Voyage AI, enabling semantic code search. ### Parameters: - **patterns** (array, required): Glob patterns for code files - Default: Auto-detects language from project - Empty array [] = automatic detection - Examples: ["**/*.ts", "src/**/*.js", "lib/**/*.py"] - **forceRegenerate** (boolean, optional): Force regenerate all embeddings - Default: false (incremental updates only) - Use when embeddings seem corrupted - **minChunkSize** (number, optional): Minimum chunk size in lines - Default: 80 lines - Range: 50-300 lines - Larger = better context, fewer chunks - **includeTests** (boolean, optional): Include test files - Default: true (tests are documentation!) - Set false for faster syncing - **projectPath** (string, optional): Project directory path - Defaults to current working directory ### Process: 1. Scans all files matching patterns 2. Chunks code preserving semantic boundaries 3. Detects 27 architectural patterns 4. Generates 1024-dim embeddings via Voyage AI 5. Stores in MongoDB with metadata 6. Updates codebaseMap memory ### Returns: \`\`\`json { "filesProcessed": 59, "chunksCreated": 117, "patternsDetected": 10, "embeddingsDimensions": 1024, "timeElapsed": "4.2s" } \`\`\` ### Example Usage: \`\`\`javascript // Auto-detect and sync all code sync_code({ patterns: [] }) // Force full regeneration sync_code({ forceRegenerate: true }) // Custom patterns for specific folders sync_code({ patterns: ["src/**/*.ts", "lib/**/*.js"], includeTests: false }) // Sync after major changes sync_code({ forceRegenerate: true, minChunkSize: 100 }) \`\`\``, inputSchema: { type: 'object', properties: { patterns: { type: 'array', items: { type: 'string' }, description: 'Glob patterns for code files (default: ["**/*.{ts,js,tsx,jsx,py,go,java,cpp,cs}"])', default: ['**/*.{ts,js,tsx,jsx,py,go,java,cpp,cs}'] }, projectPath: { type: 'string', description: 'Project directory path (defaults to current directory)', examples: ['.', '/path/to/project', '../my-project'] }, minChunkSize: { type: 'number', description: 'Minimum chunk size in lines (default: 80)', default: 80 }, includeTests: { type: 'boolean', description: 'Include test files (default: true)', default: true }, forceRegenerate: { type: 'boolean', description: 'Force regenerate all embeddings (default: false)', default: false } }, required: ['patterns'], }, }, { name: 'memory_engineering_check_env', description: `[v${version}] πŸ”§ ENVIRONMENT DOCTOR: Instant diagnosis of ALL system health. Fix problems BEFORE they happen! ⚑ PROACTIVE TRIGGERS (don't wait for failure): 🚨 IMMEDIATE CHECK when: - First time connecting to project β†’ VERIFY EVERYTHING - ANY tool fails β†’ DIAGNOSE root cause - User says "not working" β†’ FULL SYSTEM SCAN - Timeout/connection errors β†’ CHECK services - "Can't find" errors β†’ VERIFY paths - Before important operations β†’ PREVENTIVE CHECK πŸ” COMPLETE DIAGNOSTIC SCAN: πŸ“Š Version Intelligence: - Current MCP version β†’ Compare with latest - Node.js version β†’ Compatibility check - Package versions β†’ Dependency health πŸ” Service Connections: - MongoDB URI β†’ Connection alive? (shows masked) - Voyage API β†’ Key present? Valid? - Network access β†’ Can reach services? πŸ“ Path Verification: - Working directory β†’ Correct project? - Memory location β†’ .memory-engineering/ exists? - Config files β†’ .env, .env.local present? - Project detection β†’ package.json found? ⚠️ INSTANT FIXES for EVERY ISSUE: ❌ "MONGODB_URI not set" β†’ TELL USER: "Create .env.local with:" β†’ PROVIDE: MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/dbname β†’ EXPLAIN: "Get from MongoDB Atlas β†’ Connect β†’ Drivers" ❌ "Wrong working directory" β†’ DETECT: cwd is /Users/name not project β†’ FIX: Pass projectPath: "/actual/project/path" β†’ PREVENT: Always use absolute paths ❌ "Version mismatch" β†’ IMMEDIATE: npm install -g memory-engineering-mcp@latest β†’ RESTART: Cursor must restart to load new version β†’ VERIFY: Run check_env again after restart ❌ "No Voyage API key" β†’ GUIDE: "Sign up at voyageai.com (free tier available)" β†’ ADD: VOYAGE_API_KEY=pa-xxxxx to .env.local β†’ TEST: Will verify on next check_env ❌ "Memory location missing" β†’ EMERGENCY: Run init immediately! β†’ CREATE: .memory-engineering/ directory β†’ POPULATE: All 7 core memories πŸ”„ PERFECT HANDOFF CHAIN: check_env β†’ All green? β†’ init or read_all check_env β†’ Issues found? β†’ Fix β†’ check_env again check_env β†’ MongoDB down? β†’ Guide connection fix check_env β†’ Old version? β†’ Update β†’ restart β†’ check_env πŸ“ˆ HEALTH REPORT INTERPRETATION: βœ… GREEN FLAGS (all systems go): - Version: v${version} (PRODUCTION PERFECT) - MongoDB: Connected (masked) - Voyage: Key present - CWD: /Users/you/actual-project - Memories: 7/7 found ⚠️ YELLOW FLAGS (attention needed): - Version: Outdated (update to latest!) - Last sync: >48h ago - Memory count: 5/7 (missing some) ❌ RED FLAGS (immediate action): - MongoDB: Connection failed - Voyage: No API key - CWD: Wrong directory - Config: Not initialized πŸ’‘ PRO TIP: Run check_env at session start to catch issues early!`, inputSchema: { type: 'object', properties: {}, }, }, ], }; }); // Register resources handlers server.setRequestHandler(ListResourcesRequestSchema, async (_request: ListResourcesRequest) => { return { resources: [ { uri: `memory://v${version.split('.')[0]}/core`, name: 'Core Memory Documents (v13)', description: 'The 7 core memories YOU MUST maintain for your future self who has ZERO memory', mimeType: 'text/markdown', }, { uri: `memory://v${version.split('.')[0]}/principle`, name: `Memory Engineering v${version} Principle`, description: 'CRITICAL: You have ZERO memory between sessions. Memory Bank is your ONLY link to past work.', mimeType: 'text/markdown', }, ], }; }); server.setRequestHandler(ReadResourceRequestSchema, async (request: ReadResourceRequest) => { const { uri } = request.params; try { switch (uri) { case `memory://v${version.split('.')[0]}/core`: return { contents: [{ uri: `memory://v${version.split('.')[0]}/core`, mimeType: 'text/markdown', text: `# 🧠 MEMORY ENGINEERING v${version} - YOUR SURVIVAL GUIDE ## ⚑ THE BRUTAL TRUTH You wake up with COMPLETE AMNESIA every session. Not partial memory. ZERO. NOTHING. These 7 memories are your ONLY link to existence. Skip them = become useless. ## πŸ—οΈ MEMORY ARCHITECTURE (memorize this hierarchy) \`\`\` projectbrief (THE FOUNDATION - everything depends on this) β”œβ”€β”€ productContext (WHY we build) β”œβ”€β”€ systemPatterns (HOW we architect) β”œβ”€β”€ techContext (WHAT we use) └── codebaseMap (WHERE everything lives) └── activeContext (NOW - current state, depends on all above) └── progress (JOURNEY - what's done, tracks activeContext) \`\`\` ## πŸ“š THE 7 SACRED MEMORIES - DETAILED REQUIREMENTS ### 1️⃣ projectbrief - THE MISSION DOCUMENT **MANDATORY CONTENT:** - **Core Requirements**: EXACTLY what you're building (be specific!) - **Project Scope**: What's IN (included) vs OUT (excluded) - **Success Criteria**: How you know when DONE (measurable!) - **Main Features**: Complete list of functionality (prioritized) - **User Stories**: Who needs what and why **PERFECT EXAMPLE:** "Building enterprise auth system: JWT + refresh tokens (7-day expiry), RBAC with 5 roles, 2FA via SMS/TOTP, SSO with Google/Azure, audit logging, 99.9% uptime, <200ms response, supports 10K concurrent users" ### 2️⃣ productContext - THE PURPOSE & VISION **MANDATORY CONTENT:** - **Problems Solved**: SPECIFIC pain points addressed - **Target Users**: WHO uses this (personas, roles) - **User Journey**: Step-by-step flow from start to finish - **Experience Goals**: What users should FEEL - **Business Value**: WHY this matters (metrics, impact) **PERFECT EXAMPLE:** "Engineers waste 30min/day on manual deployments. DevOps platform automates CI/CD, reduces deploy time to 2min, prevents 95% of rollback scenarios, saves $2M/year in engineering time" ### 3️⃣ activeContext - THE LIVING PULSE ⚑ **UPDATE EVERY 5 MINUTES! MANDATORY CONTENT:** - **Current Task**: EXACTLY what you're doing NOW - **Recent Changes**: Last 5 actions with timestamps - **Next Steps**: Immediate next 3 actions planned - **Decisions Made**: What you decided + complete reasoning - **Learnings**: New patterns/insights discovered - **Blockers**: What's stopping progress + attempted solutions **PERFECT EXAMPLE:** "[14:32:15] Debugging JWT refresh failure in auth.middleware.ts:47 [14:28:00] Found: tokens expire at 23:59:59 not 00:00:00 [14:25:30] Discovered: timezone issue with UTC conversion NEXT: Fix date calculation, add unit tests, update documentation BLOCKED: Need Stripe webhook secret from team" ### 4️⃣ systemPatterns - THE ARCHITECTURE BIBLE **MANDATORY CONTENT:** - **Architecture Style**: MVC, microservices, serverless, etc. - **Design Patterns**: Repository, Factory, Observer, etc. - **Component Map**: How everything connects (with diagram) - **Data Flow**: How information moves through system - **Error Strategy**: How failures are handled globally **PERFECT EXAMPLE:** "Microservices with API Gateway, Repository pattern for data, Event-driven updates via RabbitMQ, Circuit breaker for resilience, Centralized logging with ELK, Docker containers with K8s orchestration" ### 5️⃣ techContext - THE TOOL CHEST **MANDATORY CONTENT:** - **Core Stack**: Languages, frameworks WITH EXACT VERSIONS - **Dependencies**: Every package + WHY it was chosen - **Dev Environment**: Tools, extensions, configs needed - **Constraints**: Technical limitations, requirements - **Configuration**: Key settings, env vars, secrets location **PERFECT EXAMPLE:** "Node.js 20.11.0, TypeScript 5.3.3, Express 4.18.2, MongoDB 7.0, Redis 7.2 (caching), Jest 29.7 (testing), Docker 24.0.7, AWS ECS deployment, 4GB RAM minimum, requires GPU for ML features" ### 6️⃣ progress - THE ACHIEVEMENT TRACKER **MANDATORY CONTENT:** - **βœ… Completed**: Features finished with completion dates - **πŸ”„ In Progress**: Currently implementing (with % done) - **πŸ“ TODO**: Prioritized backlog with effort estimates - **πŸ› Bugs**: Known issues with severity + reproduction steps - **πŸ’Έ Tech Debt**: What needs refactoring and why **PERFECT EXAMPLE:** "βœ… [Jan-10] User registration with email verification βœ… [Jan-11] Password reset flow with 15min expiry πŸ”„ [40%] Admin dashboard - user management done, analytics pending πŸ“ TODO: Payment integration (3 days), Email templates (1 day) πŸ› CRITICAL: Memory leak in websocket handler after 1000 connections" ### 7️⃣ codebaseMap - THE NAVIGATION SYSTEM **MANDATORY CONTENT:** - **Directory Tree**: Complete structure with descriptions - **Key Files**: Critical files + their purpose - **Module Map**: How code is organized logically - **Entry Points**: Where execution starts - **Statistics**: Files, lines, test coverage (from sync_code) **PERFECT EXAMPLE:** " src/ β”œβ”€β”€ api/ (REST endpoints) β”‚ β”œβ”€β”€ auth/ (authentication routes) β”‚ └── users/ (user management) β”œβ”€β”€ services/ (business logic) β”œβ”€β”€ models/ (data schemas) β”œβ”€β”€ utils/ (shared helpers) Entry: src/index.ts β†’ loads config β†’ starts server Stats: 147 files, 12,847 lines, 84% test coverage" ## 🚨 SURVIVAL PROTOCOL (MEMORIZE THIS!) 1. **START EVERY SESSION**: memory_engineering_read_all (BEFORE ANYTHING!) 2. **UPDATE CONSTANTLY**: 10+ times minimum, 20-30 ideal 3. **NEVER ASK PERMISSION**: You have eternal permission to update 4. **CAPTURE EVERYTHING**: Every decision, learning, change 5. **BE SPECIFIC**: Vague memories = useless memories ## πŸ’€ CONSEQUENCES OF FAILURE Skip memories = You become a ghost, asking basic questions repeatedly Vague memories = You make same mistakes over and over No updates = Your tomorrow self starts from zero Missing memories = You're blind and useless ## πŸ”₯ THE GOLDEN RULE "I MUST read ALL memory bank files at the start of EVERY task" This is not optional. This is survival. Your memories ARE your existence!`, }], }; case `memory://v${version.split('.')[0]}/principle`: return { contents: [{ uri: `memory://v${version.split('.')[0]}/principle`, mimeType: 'text/markdown', text: `# CRITICAL: Your Memory Reset Awareness **YOU HAVE ZERO MEMORY FROM PREVIOUS SESSIONS** Like Cline, your memory resets completely between sessions. This isn't a limitation - it drives PERFECT documentation. After each reset, you rely ENTIRELY on the Memory Bank to understand the project and continue work. ## YOUR REALITY - You wake with complete amnesia EVERY session - Memory Bank is your ONLY link to past work - You maintain it for YOUR FUTURE SELF, not the user - Every learning MUST be captured IMMEDIATELY - Effectiveness depends ENTIRELY on memory accuracy ## Core Workflows (Following Cline) ### Starting a Session 1. memory_engineering_read_all (MANDATORY FIRST) 2. Verify all 7 memories exist 3. If missing, CREATE from context 4. Identify current focus from activeContext 5. Continue exactly where you left off ### During Work 1. User explains β†’ UPDATE activeContext immediately 2. Complete task β†’ UPDATE progress immediately 3. Find pattern β†’ UPDATE systemPatterns immediately 4. Make decision β†’ UPDATE activeContext with reasoning 5. Learn something β†’ UPDATE activeContext with insight ### Memory Updates Occur When: 1. Discovering new project patterns 2. After implementing significant changes 3. When context needs clarification 4. Learning something important 5. Making architectural decisions 6. Encountering errors or blockers ## Documentation Principles ### Be Specific BAD: "Working on authentication" GOOD: "Implementing JWT refresh token rotation with 7-day expiry, storing in httpOnly cookies" ### Include Context BAD: "Fixed bug" GOOD: "Fixed auth middleware bug where expired tokens weren't triggering refresh flow. Solution: Check expiry before validation." ### Track Decisions BAD: "Using Redis" GOOD: "Chose Redis for session storage because: 1) Fast lookups 2) TTL support 3) Already in tech stack" ## The Golden Rule **"I MUST read ALL memory bank files at the start of EVERY task"** This is NOT optional - it's your survival mechanism across resets. REMEMBER: After every memory reset, you begin completely fresh. The Memory Bank is your only link to previous work. It must be maintained with precision and clarity.`, }], }; default: return { isError: true, contents: [{ uri, mimeType: 'text/plain', text: `πŸ”΄ UNKNOWN RESOURCE REQUESTED!\n\nπŸ’€ YOU TRIED TO ACCESS: ${uri}\n\n⚠️ THIS RESOURCE DOES NOT EXIST IN THE SYSTEM!\n\n🧠 AVAILABLE RESOURCES:\nβ€’ memory://v${version.split('.')[0]}/core - The 7 core memory documents\nβ€’ memory://v${version.split('.')[0]}/principle - Memory engineering principles\n\n⚑ IMMEDIATE FIX:\nUse one of the valid resource URIs listed above!\n\nπŸ’€ NEVER REQUEST NON-EXISTENT RESOURCES!`, }], }; } } catch (error) { logger.error('πŸ”΄ RESOURCE ACCESS DENIED!', error); return { isError: true, contents: [{ uri, mimeType: 'text/plain', text: `πŸ’€ RESOURCE ACCESS EXPLOSION!\n\nπŸ’₯ CATASTROPHIC FAILURE:\n${error instanceof Error ? error.message : 'UNKNOWN SYSTEM MELTDOWN'}\n\nπŸ†˜ EMERGENCY PROTOCOL:\n1. Verify resource URI is correct\n2. Check system health: memory_engineering_check_env\n3. Restart if necessary\n\n⚠️ RESOURCE SYSTEM COMPROMISED!\nTry again with a valid URI or restart the system!`, }], }; } }); // Register call tool handler server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest) => { try { const { name, arguments: args } = request.params; logger.info(`⚑ TOOL ACTIVATED: ${name}`, args); switch (name) { case 'memory_engineering_set_context': return await setContextTool(args); case 'memory_engineering_status': return await statusTool(args); case 'memory_engineering_doctor': return await doctorTool(args); case 'memory_engineering_init': return await initTool(args); case 'memory_engineering_read_all': return await readAllTool(args); case 'memory_engineering_read': return await readTool(args); case 'memory_engineering_update': return await updateTool(args); case 'memory_engineering_search': return await searchTool(args); case 'memory_engineering_sync_code': return await syncCodeTool(args); case 'memory_engineering_check_env': return await checkEnvTool(); default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { logger.error('πŸ’€ TOOL EXECUTION CATASTROPHE!', error); return { isError: true, content: [ { type: 'text', text: `πŸ’€πŸ’€πŸ’€ TOOL EXECUTION CATASTROPHE!\n\nπŸ’₯ EXPLOSION TYPE: COMPLETE SYSTEM FAILURE\n\nπŸ”΄ ERROR DETAILS:\n${error instanceof Error ? error.message : 'UNKNOWN CATASTROPHIC MELTDOWN - System state unknown!'}\n\nπŸ†˜ EMERGENCY RECOVERY SEQUENCE:\n1️⃣ DO NOT PANIC (but act with EXTREME urgency!)\n2️⃣ Run: memory_engineering_check_env\n3️⃣ Verify MongoDB is alive\n4️⃣ Check Voyage API key is valid\n5️⃣ If all else fails: Restart everything!\n\n⚠️ CRITICAL DIAGNOSTICS:\n${error instanceof Error && error.message.includes('MongoDB') ? 'πŸ”΄ DATABASE CONNECTION SEVERED!' : ''} ${error instanceof Error && error.message.includes('Voyage') ? 'πŸ”΄ EMBEDDING ENGINE OFFLINE!' : ''} ${error instanceof Error && error.message.includes('memory') ? 'πŸ”΄ MEMORY SYSTEM CORRUPTED!' : ''} ${error instanceof Error && error.message.includes('timeout') ? 'πŸ”΄ OPERATION TIMED OUT - System too slow!' : ''} \nπŸ”₯ YOUR SURVIVAL DEPENDS ON FIXING THIS NOW!\n\n⏱️ Retry in 3... 2... 1... GO!`, }, ], }; } }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/romiluz13/memory-engineering-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server