Skip to main content
Glama

cleanup_expired_working_memory

Removes expired working memories from the AGI MCP Server's persistent storage system to maintain efficient memory management and free up resources.

Instructions

Clean up expired working memories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual implementation that deletes expired working memory records from the database. It queries the working_memory table for records where expiry is not null and less than or equal to current timestamp, then deletes and returns them.
    async cleanupExpiredWorkingMemory() {
      try {
        const expired = await this.db
          .delete(schema.workingMemory)
          .where(
            and(
              isNotNull(schema.workingMemory.expiry),
              lte(schema.workingMemory.expiry, new Date())
            )
          )
          .returning();
    
        return expired;
      } catch (error) {
        console.error('Error cleaning up expired working memory:', error);
        throw error;
      }
    }
  • Database schema definition for the working_memory table that includes the expiry timestamp field used to identify expired records.
    export const workingMemory = pgTable("working_memory", {
    	id: uuid().defaultRandom().primaryKey().notNull(),
    	createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
    	content: text().notNull(),
    	embedding: vector({ dimensions: 1536 }).notNull(),
    	expiry: timestamp({ withTimezone: true, mode: 'string' }),
    });
  • Tool schema definition in the memory-tools module that defines the input/output structure for cleanup_expired_working_memory tool.
    {
      name: "cleanup_expired_working_memory",
      description: "Clean up expired working memories",
      inputSchema: {
        type: "object",
        properties: {}
      }
    },
  • mcp.js:450-457 (registration)
    MCP tool registration that exposes cleanup_expired_working_memory as an available tool to MCP clients.
    {
      name: "cleanup_expired_working_memory",
      description: "Clean up expired working memories",
      inputSchema: {
        type: "object",
        properties: {}
      }
    },
  • mcp.js:670-672 (handler)
    MCP request handler that routes cleanup_expired_working_memory tool calls to the MemoryManager's cleanupExpiredWorkingMemory method and returns the cleaned memories as JSON.
    case "cleanup_expired_working_memory":
      const cleanedMemories = await memoryManager.cleanupExpiredWorkingMemory();
      return { content: [{ type: "text", text: JSON.stringify(cleanedMemories, null, 2) }] };

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/randyandrade/agi-mcp-server'

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