mongodb-memory-bank-mcp-v2
Version:
MongoDB-powered Memory Bank MCP server with hybrid search capabilities for AI assistants
77 lines (66 loc) ⢠2.96 kB
JavaScript
import { join } from 'path';
import { readFileSync, existsSync } from 'fs';
import { GeneratePRPSchema } from '../types/memory.js';
import { logger } from '../utils/logger.js';
import { getContextEngineeringTemplate } from '../services/context-engineering.js';
/**
* Context Engineering Phase 1: Generate PRP from simple user request
* Fetches the original /generate-prp system prompt from MongoDB
*/
export async function generatePRPTool(args) {
try {
const params = GeneratePRPSchema.parse(args);
const projectPath = params.projectPath || process.cwd();
// Read project config
const configPath = join(projectPath, '.memory-bank', 'config.json');
if (!existsSync(configPath)) {
return {
content: [{
type: 'text',
text: 'Memory bank not initialized. Run memory_bank/init first.',
}],
};
}
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
const userRequest = params.request;
logger.info('Fetching Context Engineering /generate-prp template...');
// Fetch the exact original /generate-prp system prompt from MongoDB
const systemPrompt = await getContextEngineeringTemplate('generate-prp');
logger.info('šÆ Context Engineering Phase 1: Research & PRP Generation');
return {
content: [{
type: 'text',
text: `šÆ **Context Engineering Phase 1: Research & PRP Generation**
**Your Request**: "${userRequest}"
**Project**: ${config.projectId}
---
## š¤ AI Assistant Instructions
You are now in Context Engineering Phase 1. Follow these instructions EXACTLY:
${systemPrompt}
---
## šÆ Your Task
**Feature Request**: ${userRequest}
**Steps to Follow**:
1. **Research Process**: Follow the research steps in the system prompt above
2. **Use Memory Bank Tools**:
- \`memory_bank/search --query "[relevant patterns]"\` to find existing patterns
- \`memory_bank/read --fileName "[relevant-file.md]"\` to read project context
3. **ULTRATHINK**: Deep analysis before writing the PRP
4. **Generate PRP**: Create comprehensive implementation blueprint
5. **Store PRP**: Use \`memory_bank/update --fileName "prp_[feature-name].md" --content "[PRP content]"\` to store the PRP
**Next Phase**: After generating the PRP, use \`memory_bank/execute-prp\` for implementation.
š **Start your research NOW following the Context Engineering methodology above!**`,
}],
};
}
catch (error) {
logger.error('PRP generation error:', error);
return {
content: [{
type: 'text',
text: `Error fetching Context Engineering template: ${error instanceof Error ? error.message : 'Unknown error occurred'}`,
}],
};
}
}
//# sourceMappingURL=generate-prp.js.map