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
| Name | Required | Description | Default |
|---|---|---|---|
| memory_id | No | The ID of the memory to retrieve | |
| title | No | The title of the memory to retrieve |
Implementation Reference
- memory_mcp/server.py:221-245 (handler)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)}"
- memory_mcp/server.py:352-369 (schema)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", }, ),
- memory_mcp/server.py:430-436 (registration)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)]
- memory_mcp/server.py:78-100 (helper)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
- memory_mcp/server.py:102-124 (helper)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