Skip to main content
Glama

delete_short_term_memories

Remove short-term memories by keyword or regex pattern to manage conversation data and optimize memory usage in the Memory MCP Server.

Instructions

Delete short-term memories matching a keyword or regex pattern.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesString keyword or regex pattern to match (e.g., "keyword" or "/pattern/i")
conversation_idYesConversation ID for storage

Implementation Reference

  • The primary handler function for the 'delete_short_term_memories' tool. Parses the pattern (supports regex format /pattern/i), delegates deletion to ShortTermMemoryManager.deleteMemories(), persists changes via storage, and returns deletion stats.
    handler: async (args) => {
      try {
        // Parse regex if pattern is in /.../ format
        let searchPattern = args.pattern;
        const regexMatch = args.pattern.match(/^\/(.+)\/([gimsuy]*)$/);
        
        if (regexMatch) {
          searchPattern = new RegExp(regexMatch[1], regexMatch[2]);
        }
    
        const deletedCount = memoryManager.deleteMemories(searchPattern);
        await storageManager.saveShortTermMemories(memoryManager.getMemories());
    
        return {
          success: true,
          deletedCount,
          remainingCount: memoryManager.getMemories().length,
          message: `Deleted ${deletedCount} memor${deletedCount === 1 ? 'y' : 'ies'}`
        };
      } catch (error) {
        return {
          success: false,
          error: error.message
        };
      }
    }
  • Zod input schema defining the tool parameters: pattern (string for keyword or regex) and conversation_id.
    inputSchema: z.object({
      pattern: z.string().describe('String keyword or regex pattern to match (e.g., "keyword" or "/pattern/i")'),
      conversation_id: z.string().describe('Conversation ID for storage')
    }),
  • Core deletion logic in ShortTermMemoryManager: filters memories array by matching pattern against mem.text (regex test or string includes), returns count of deleted items.
    deleteMemories(pattern) {
      const oldLength = this.memories.length;
      
      if (pattern instanceof RegExp) {
        this.memories = this.memories.filter(mem => !pattern.test(mem.text));
      } else {
        this.memories = this.memories.filter(mem => !mem.text.includes(pattern));
      }
    
      return oldLength - this.memories.length;
    }
  • src/index.js:152-154 (registration)
    Static registration of short-term tools (including delete_short_term_memories) for default conversation_id into the toolRegistry for list_tools.
    // 注册所有短期记忆工具
    const shortTermTools = createShortTermTools(defaultShortTermManager, defaultStorageManager);
    shortTermTools.forEach(tool => registerTool(tool, 'short-term'));
  • src/index.js:285-290 (registration)
    Dynamic recreation of short-term tools with conversation-specific managers and invocation of the matching tool handler during actual tool call execution.
      manager = await getShortTermManager(conversationId);
      storage = getStorageManager(conversationId);
      const tools = createShortTermTools(manager, storage, queryCache);
      const tool = tools.find(t => t.name === toolName);
      result = await withTimeout(tool.handler(validatedArgs), timeout, `Tool ${toolName} timeout`);
    } else if (toolScope === 'long-term' || toolName.includes('long_term')) {

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/win10ogod/memory-mcp-server'

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