Skip to main content
Glama
mixelpixx

meMCP - Memory-Enhanced Model Context Protocol

memory_cleanup

Clear outdated or unnecessary data from persistent memory to maintain optimal performance and storage efficiency in LLM sessions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registers the memory_cleanup tool with the server, including description, input schema (dryRun, minQualityScore, maxAge, keepCount), and delegates to handleCleanup method.
    registerCleanupTool(server) {
      server.registerTool(
        'memory_cleanup',
        'Clean up old or low-quality facts based on retention policies',
        {
          type: 'object',
          properties: {
            dryRun: {
              type: 'boolean',
              description: 'If true, show what would be deleted without actually deleting',
              default: true,
            },
            minQualityScore: {
              type: 'number',
              description: 'Minimum quality score to keep facts',
              default: 40,
            },
            maxAge: {
              type: 'number',
              description: 'Maximum age in days to keep facts (0 = no age limit)',
              default: 0,
            },
            keepCount: {
              type: 'number',
              description: 'Minimum number of facts to keep regardless of quality',
              default: 100,
            },
          },
        },
        async (args) => {
          return await this.handleCleanup(args);
        }
      );
    }
  • Executes the cleanup: queries all facts, filters by quality score, age, ensures minimum keep count, performs dry-run preview or actual deletion via factStore.deleteFact, returns formatted response with results or errors.
    async handleCleanup(args) {
      try {
        const { dryRun = true, minQualityScore = 40, maxAge = 0, keepCount = 100 } = args;
        
        const allFacts = await this.factStore.queryFacts({
          query: '',
          limit: 10000,
        });
        
        let toDelete = allFacts.facts.filter(fact => fact.qualityScore < minQualityScore);
        
        if (maxAge > 0) {
          const cutoffDate = new Date(Date.now() - (maxAge * 24 * 60 * 60 * 1000));
          toDelete = toDelete.filter(fact => new Date(fact.createdAt) < cutoffDate);
        }
        
        const totalFacts = allFacts.facts.length;
        const factsToKeep = totalFacts - toDelete.length;
        
        if (factsToKeep < keepCount && toDelete.length > 0) {
          const sortedToDelete = toDelete.sort((a, b) => b.qualityScore - a.qualityScore);
          const reduceBy = keepCount - factsToKeep;
          toDelete = sortedToDelete.slice(reduceBy);
        }
        
        if (dryRun) {
          return {
            content: [
              {
                type: 'text',
                text: `🧹 **Cleanup Preview** (Dry Run)\n\n**Would delete:** ${toDelete.length} facts\n**Would keep:** ${totalFacts - toDelete.length} facts\n**Criteria:** Quality < ${minQualityScore}${maxAge > 0 ? `, Age > ${maxAge} days` : ''}\n\n**Sample facts to delete:**\n${toDelete.slice(0, 5).map(f => `- ${f.type}: ${f.content.substring(0, 60)}... (Score: ${f.qualityScore})`).join('\n')}${toDelete.length > 5 ? `\n... and ${toDelete.length - 5} more` : ''}`,
              },
            ],
          };
        }
        
        let deleted = 0;
        const errors = [];
        
        for (const fact of toDelete) {
          try {
            await this.factStore.deleteFact(fact.id);
            deleted++;
          } catch (error) {
            errors.push(`Failed to delete fact ${fact.id}: ${error.message}`);
          }
        }
        
        let response = `🧹 **Cleanup Complete**\n\n**Deleted:** ${deleted} facts\n**Failed:** ${toDelete.length - deleted} facts\n**Remaining:** ${totalFacts - deleted} facts`;
        
        if (errors.length > 0) {
          response += `\n\n**Errors:**\n${errors.slice(0, 3).join('\n')}${errors.length > 3 ? `\n... and ${errors.length - 3} more errors` : ''}`;
        }
        
        return {
          content: [
            {
              type: 'text',
              text: response,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error during cleanup: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • MemoryTools.registerTools calls this.management.registerTools(server), which triggers the registration of memory_cleanup among other memory management tools.
    async registerTools(server) {
      // Register tools from modular components
      this.operations.registerTools(server);
      this.queryHandler.registerTools(server);
      this.streamingTools.registerTools(server);
      this.management.registerTools(server);
    }
  • Wrapper method in MemoryTools that delegates cleanup calls to the MemoryManagement instance.
    async handleCleanup(args) {
      return await this.management.handleCleanup(args);
    }
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/mixelpixx/meMCP'

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