Skip to main content
Glama
drdee

Memory MCP

by drdee

get_memory

Retrieve specific memories by ID or title using the Memory MCP server. Access stored data efficiently for quick retrieval and management.

Instructions

Retrieve a specific memory by ID or title.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idNoThe ID of the memory to retrieve
titleNoThe title of the memory to retrieve

Implementation Reference

  • The primary handler function implementing the get_memory tool logic. It retrieves a memory from the database by ID or title and returns a formatted text response.
    def get_memory(memory_id: Optional[int] = None, title: Optional[str] = None) -> str:
        """
        Retrieve a specific memory by ID or title.
    
        Args:
            memory_id: The ID of the memory to retrieve
            title: The title of the memory to retrieve
    
        Returns:
            The memory content or an error message
        """
        try:
            if memory_id is not None:
                memory = db.get_memory_by_id(int(memory_id))
            elif title is not None:
                memory = db.get_memory_by_title(title)
            else:
                return "Error: Please provide either a memory_id or title."
    
            if memory:
                return f"Title: {memory['title']}\n\nContent: {memory['content']}"
            return "Memory not found."
        except Exception as e:
            return f"Error retrieving memory: {str(e)}"
  • The input schema definition for the get_memory tool, allowing optional memory_id (integer) or title (string).
    types.Tool(
        name="get_memory",
        description="Retrieve a specific memory by ID or title.",
        inputSchema={
            "type": "object",
            "properties": {
                "memory_id": {
                    "type": "integer",
                    "description": "The ID of the memory to retrieve",
                },
                "title": {
                    "type": "string",
                    "description": "The title of the memory to retrieve",
                },
            },
            "title": "getMemoryArguments",
        },
    ),
  • The dispatch logic in the call_tool handler that invokes the get_memory function with parsed arguments.
    elif name == "get_memory":
        if not arguments:
            raise ValueError("Missing arguments")
        memory_id = arguments.get("memory_id")
        title = arguments.get("title")
        result = get_memory(memory_id, title)
        return [types.TextContent(type="text", text=result)]
  • Database helper method to fetch memory by ID from SQLite.
    def get_memory_by_id(self, memory_id: int) -> Optional[Dict[str, Any]]:
        """Retrieve a memory by its ID."""
        if not self.conn:
            self.initialize_db()
    
        if self.conn is None:
            raise RuntimeError("Database connection not available")
    
        cursor = self.conn.execute(
            "SELECT id, title, content, created_at, updated_at FROM memories WHERE id = ?",
            (memory_id,),
        )
        row = cursor.fetchone()
    
        if row:
            return {
                "id": row[0],
                "title": row[1],
                "content": row[2],
                "created_at": row[3],
                "updated_at": row[4],
            }
        return None
  • Database helper method to fetch memory by title from SQLite.
    def get_memory_by_title(self, title: str) -> Optional[Dict[str, Any]]:
        """Retrieve a memory by its title."""
        if not self.conn:
            self.initialize_db()
    
        if self.conn is None:
            raise RuntimeError("Database connection not available")
    
        cursor = self.conn.execute(
            "SELECT id, title, content, created_at, updated_at FROM memories WHERE title = ?",
            (title,),
        )
        row = cursor.fetchone()
    
        if row:
            return {
                "id": row[0],
                "title": row[1],
                "content": row[2],
                "created_at": row[3],
                "updated_at": row[4],
            }
        return None
Install Server

Other Tools

Related 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/drdee/memory-mcp'

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