memory_validate
Verify and validate stored memory data in the MCP server to ensure accuracy and consistency for LLM context retention.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/modules/MemoryManagement.js:128-151 (registration)Registers the memory_validate tool with server.registerTool, defining the tool name, description, input schema (fixErrors, checkRelationships params), and handler that delegates to handleValidate method.registerValidateTool(server) { server.registerTool( 'memory_validate', 'Validate the integrity of the memory system', { type: 'object', properties: { fixErrors: { type: 'boolean', description: 'Attempt to fix validation errors automatically', default: false, }, checkRelationships: { type: 'boolean', description: 'Validate fact relationships', default: true, }, }, }, async (args) => { return await this.handleValidate(args); } ); }
- Handler function for memory_validate tool: extracts parameters, invokes validateSystem helper, formats and returns the validation report as a text content response, handles errors.async handleValidate(args) { try { const { fixErrors = false, checkRelationships = true } = args; const validationResult = await this.validateSystem({ fixErrors, checkRelationships, }); let response = `🔍 **Validation Complete**\n\n**Total Facts:** ${validationResult.totalFacts}\n**Valid Facts:** ${validationResult.validFacts}\n**Errors Found:** ${validationResult.errors.length}`; if (validationResult.errors.length > 0) { response += `\n\n**Error Summary:**\n${validationResult.errorSummary.map(e => `- ${e.type}: ${e.count}`).join('\n')}`; if (fixErrors) { response += `\n\n**Fixed:** ${validationResult.fixed} errors`; } } return { content: [ { type: 'text', text: response, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error validating system: ${error.message}`, }, ], isError: true, }; }
- Core implementation of validation logic: queries all facts, checks for missing ID, empty content, invalid quality scores (0-100), and optionally broken relationships by verifying target existence, collects errors and summary.async validateSystem(options = {}) { try { const { fixErrors, checkRelationships } = options; const allFacts = await this.factStore.queryFacts({ query: '', limit: 10000 }); const errors = []; const errorTypes = new Map(); let fixed = 0; for (const fact of allFacts.facts) { if (!fact.id) { errors.push({ type: 'missing_id', factId: 'unknown', message: 'Fact missing ID' }); errorTypes.set('missing_id', (errorTypes.get('missing_id') || 0) + 1); } if (!fact.content || fact.content.trim().length === 0) { errors.push({ type: 'empty_content', factId: fact.id, message: 'Fact has empty content' }); errorTypes.set('empty_content', (errorTypes.get('empty_content') || 0) + 1); } if (fact.qualityScore === undefined || fact.qualityScore < 0 || fact.qualityScore > 100) { errors.push({ type: 'invalid_quality_score', factId: fact.id, message: 'Invalid quality score' }); errorTypes.set('invalid_quality_score', (errorTypes.get('invalid_quality_score') || 0) + 1); } if (checkRelationships && fact.relationships) { for (const rel of fact.relationships) { const relatedFact = allFacts.facts.find(f => f.id === rel.targetId); if (!relatedFact) { errors.push({ type: 'broken_relationship', factId: fact.id, message: `Relationship to ${rel.targetId} is broken` }); errorTypes.set('broken_relationship', (errorTypes.get('broken_relationship') || 0) + 1); } } } } const errorSummary = Array.from(errorTypes.entries()).map(([type, count]) => ({ type, count })); return { totalFacts: allFacts.facts.length, validFacts: allFacts.facts.length - errors.length, errors, errorSummary, fixed, }; } catch (error) { throw new Error(`Failed to validate system: ${error.message}`); } }
- src/tools/MemoryTools.js:23-29 (registration)Top-level tool registration in MemoryTools class: calls registerTools on management (MemoryManagement instance), which includes registration of memory_validate.async registerTools(server) { // Register tools from modular components this.operations.registerTools(server); this.queryHandler.registerTools(server); this.streamingTools.registerTools(server); this.management.registerTools(server); }
- src/tools/MemoryTools.js:17-17 (registration)Instantiates the MemoryManagement class instance used for registering memory management tools including memory_validate.this.management = new MemoryManagement(factStore);