memory-engineering
Version:
Advanced Memory-Aware Code Context System with claude-flow-inspired architecture, showcasing MongoDB + Voyage AI strategic positioning
85 lines (75 loc) ⢠3.14 kB
text/typescript
/**
* Memory Product Context Tool
* Using claude-flow-inspired MemoryManager for conflict-free operations
*/
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { IMemoryManager } from '../memory/memory-manager.js';
import { generateMemoryId } from '../utils/id-generator.js';
import { logger } from '../utils/logger.js';
export const memoryProductContextTool: Tool = {
name: 'memory_product_context',
description: 'Store product vision and user context',
inputSchema: {
type: 'object',
properties: {
projectPath: { type: 'string', description: 'Project path' },
problemsSolved: { type: 'array', items: { type: 'string' } },
userGoals: { type: 'array', items: { type: 'string' } },
keyFeatures: { type: 'array', items: { type: 'string' } },
valueProposition: { type: 'string', description: 'Value proposition' }
},
required: ['projectPath', 'problemsSolved', 'userGoals', 'keyFeatures', 'valueProposition']
}
};
export function createMemoryProductContextHandler(memoryManager: IMemoryManager) {
return async (args: any) => {
try {
const { projectPath, problemsSolved, userGoals, keyFeatures, valueProposition } = args;
const content = { problemsSolved, userGoals, keyFeatures, valueProposition };
const searchableText = `${problemsSolved.join(' ')} ${userGoals.join(' ')} ${keyFeatures.join(' ')} ${valueProposition}`;
const memoryId = generateMemoryId(projectPath, 'product');
const existing = await memoryManager.retrieve(memoryId);
const memoryEntry = {
id: memoryId,
projectPath,
memoryType: 'product',
content,
context: {
problemsSolvedCount: problemsSolved.length,
userGoalsCount: userGoals.length,
keyFeaturesCount: keyFeatures.length,
valuePropositionLength: valueProposition.length
},
timestamp: new Date(),
tags: ['product', 'vision', 'user-needs', 'value-proposition'],
version: existing ? (existing.version + 1) : 1,
metadata: {
created: existing?.metadata?.created || new Date(),
lastUpdated: new Date(),
},
searchableText
};
const storedId = await memoryManager.store(memoryEntry);
logger.info('Product context saved', {
projectPath,
valueProposition: valueProposition.substring(0, 100),
memoryId: storedId,
isNew: !existing,
version: memoryEntry.version
});
return {
content: [{
type: 'text',
text: 'ā
Product context saved!\n\nYour product vision is captured.\n\nšÆ Next: Use \'memory_tech_context\' to define:\n- Programming languages\n- Frameworks and libraries\n- Databases\n- Development setup\n\nThis helps maintain technical consistency.'
}],
isError: false
};
} catch (error) {
logger.error('Failed to save product context', error);
return {
content: [{ type: 'text', text: `ā Error: ${error instanceof Error ? error.message : 'Unknown error'}` }],
isError: true
};
}
};
}