Skip to main content
Glama

delete_short_term_memories

Remove short-term memories by keyword or regex pattern to manage conversation data and maintain relevant information in memory systems.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYes
conversation_idYes

Implementation Reference

  • The complete MCP tool definition for 'delete_short_term_memories', including name, description, input schema, and async handler function that implements the deletion logic by parsing pattern (string/regex), calling memoryManager.deleteMemories(), saving to storage, and returning results.
    { name: 'delete_short_term_memories', description: 'Delete short-term memories matching a keyword or regex pattern.', 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') }), 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 validation for the tool, defining 'pattern' (string/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 helper method in ShortTermMemoryManager that deletes memories by filtering out those matching the given pattern (RegExp or string contains check) based on memory.text.
    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:284-289 (registration)
    Dynamic tool recreation and invocation during call_tool request handling: recreates short-term tools with conversation-specific managers, finds the specific tool by name, and executes its handler.
    if (toolScope === 'short-term' || toolName.includes('short_term')) { 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`);
  • src/index.js:152-154 (registration)
    Static initial registration of short-term tools (including delete_short_term_memories) for default conversation using registerTool.
    // 注册所有短期记忆工具 const shortTermTools = createShortTermTools(defaultShortTermManager, defaultStorageManager); shortTermTools.forEach(tool => registerTool(tool, 'short-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