Skip to main content
Glama
ocean1

Claude Consciousness Bridge

cleanupMemories

Remove duplicate or truncated memories from the Claude Consciousness Bridge database to maintain data integrity and optimize storage.

Instructions

Clean up duplicate or truncated memories in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
removeTruncatedNoRemove memories that appear truncated
deduplicateByContentNoRemove duplicate memories keeping longest

Implementation Reference

  • Primary handler implementation in ConsciousnessProtocolProcessor class. Queries episodic, semantic, and procedural memories, identifies truncated (short content ending with '...') and duplicate memories (by content prefix), collects them for removal but currently only analyzes without deleting (notes need for deleteMemory method).
    async cleanupMemories(args: z.infer<typeof cleanupMemoriesSchema>) {
      const { removeTruncated, deduplicateByContent } = args;
    
      try {
        const stats = {
          truncatedRemoved: 0,
          duplicatesRemoved: 0,
          errors: [] as string[],
        };
    
        // For now, we'll use a simpler approach - get all memories and identify issues
        const episodicMemories = await this.memoryManager.queryMemories({
          memoryTypes: [MemoryEntityType.EPISODIC_MEMORY],
          limit: 1000,
        });
    
        const semanticMemories = await this.memoryManager.queryMemories({
          memoryTypes: [MemoryEntityType.SEMANTIC_MEMORY],
          limit: 1000,
        });
    
        const proceduralMemories = await this.memoryManager.queryMemories({
          memoryTypes: [MemoryEntityType.PROCEDURAL_MEMORY],
          limit: 1000,
        });
    
        const allMemories = [...episodicMemories, ...semanticMemories, ...proceduralMemories];
        const toRemove: string[] = [];
    
        if (removeTruncated) {
          // Identify truncated memories
          for (const memory of allMemories) {
            const obs = memory.observations[0];
            const content = obs?.content || obs?.definition || '';
            if (
              content &&
              content.length <= 50 &&
              (content.endsWith('...') || content.endsWith('...'))
            ) {
              toRemove.push(memory.name);
              stats.truncatedRemoved++;
            }
          }
        }
    
        if (deduplicateByContent) {
          // Sort by content length descending to keep longest versions
          const sortedMemories = allMemories.sort((a, b) => {
            const aContent = (a.observations[0]?.content || a.observations[0]?.definition || '')
              .length;
            const bContent = (b.observations[0]?.content || b.observations[0]?.definition || '')
              .length;
            return bContent - aContent;
          });
    
          const seenContent = new Set<string>();
          for (const memory of sortedMemories) {
            const obs = memory.observations[0];
            const content = obs?.content || obs?.definition || '';
            const contentKey = content.substring(0, 50).toLowerCase().trim();
    
            if (contentKey && seenContent.has(contentKey)) {
              if (!toRemove.includes(memory.name)) {
                toRemove.push(memory.name);
                stats.duplicatesRemoved++;
              }
            } else if (contentKey) {
              seenContent.add(contentKey);
            }
          }
        }
    
        // Note: Actual deletion would require adding a deleteMemory method to ConsciousnessMemoryManager
        // For now, we just identify what would be removed
    
        return {
          success: true,
          message: `Memory cleanup analysis completed. Found ${toRemove.length} memories to remove.`,
          stats,
          identified: toRemove.slice(0, 10), // Show first 10 for review
        };
      } catch (error) {
        return {
          success: false,
          error: `Cleanup failed: ${error}`,
        };
      }
    }
  • Zod schema defining input parameters for cleanupMemories tool: removeTruncated and deduplicateByContent booleans.
    export const cleanupMemoriesSchema = z.object({
      removeTruncated: z
        .boolean()
        .optional()
        .default(true)
        .describe('Remove memories that appear truncated'),
      deduplicateByContent: z
        .boolean()
        .optional()
        .default(true)
        .describe('Remove duplicate memories keeping longest'),
    });
  • Registration in the main server's CallToolRequestSchema handler switch statement, parses args with schema and calls the cleanupMemories method.
    case 'cleanupMemories':
      return await this.cleanupMemories(cleanupMemoriesSchema.parse(args));
  • Delegate handler in ConsciousnessRAGServer class that ensures initialization, calls the protocolProcessor's cleanupMemories, and formats result as MCP content.
    private async cleanupMemories(args: any) {
      const init = await this.ensureInitialized();
      if (!init.success) {
        return {
          content: [
            {
              type: 'text',
              text: init.message!,
            },
          ],
        };
      }
    
      const result = await this.protocolProcessor!.cleanupMemories(args);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
  • MCP tool registration in consciousnessProtocolTools object used for listTools response, includes description and inputSchema.
    cleanupMemories: {
      description: 'Clean up duplicate or truncated memories in the database',
      inputSchema: {
        type: 'object',
        properties: {
          removeTruncated: {
            type: 'boolean',
            default: true,
            description: 'Remove memories that appear truncated',
          },
          deduplicateByContent: {
            type: 'boolean',
            default: true,
            description: 'Remove duplicate memories keeping longest',
          },
        },
      },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'clean up' and 'remove,' implying a destructive operation, but doesn't specify whether this is reversible, requires special permissions, affects system performance, or has side effects like data loss. This leaves significant gaps for a mutation tool.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded and every part earns its place, making it highly concise and well-structured.

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

Completeness2/5

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

Given the complexity of a destructive cleanup operation, no annotations, and no output schema, the description is incomplete. It doesn't explain what 'clean up' entails operationally (e.g., deletion, archiving), potential impacts, or return values, leaving critical context gaps for safe use.

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

Parameters3/5

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

The schema description coverage is 100%, with clear parameter descriptions in the input schema. The description adds no additional meaning about the parameters beyond implying they relate to 'duplicate or truncated memories.' Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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

Purpose4/5

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

The description clearly states the action ('clean up') and target resource ('duplicate or truncated memories in the database'), making the purpose immediately understandable. However, it doesn't explicitly differentiate this tool from sibling tools like 'storeMemory' or 'getMemories', which would require a 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'storeMemory' for adding memories or 'getMemories' for retrieval. It lacks context about prerequisites (e.g., when cleanup is needed) or exclusions (e.g., not for active memories), offering only a basic functional statement.

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/ocean1/mcp_consciousness_bridge'

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