read_diary_entry
Retrieve specific diary entries from your Obsidian journal by date to review past reflections and maintain consistent journaling habits.
Instructions
Read an existing diary entry.
Args: date: Date of the entry in YYYY-MM-DD format
Returns: The diary entry content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes |
Implementation Reference
- src/obsidian_diary_mcp/server.py:239-253 (handler)The handler function for the 'read_diary_entry' tool. Parses the date parameter, constructs the file path, checks if the entry exists, and reads the content using the entry_manager helper.def read_diary_entry( date: Annotated[str, "Date of the entry in YYYY-MM-DD format"] ) -> str: """Read a specific diary entry by date.""" try: entry_date = datetime.strptime(date, "%Y-%m-%d") except ValueError: return "Error: Date must be in YYYY-MM-DD format" file_path = entry_manager.get_entry_path(entry_date) if not entry_manager.entry_exists(entry_date): return f"No memory log found for {date}" return entry_manager.read_entry(file_path)
- src/obsidian_diary_mcp/server.py:232-238 (registration)Registers the 'read_diary_entry' tool with MCP using the @mcp.tool decorator, including metadata annotations.@mcp.tool( annotations={ "title": "Read Memory Log", "readOnlyHint": True, "openWorldHint": False } )
- Supporting method in EntryManager class that performs the actual file reading operation called by the tool handler.def read_entry(self, file_path: Path) -> str: """Read the content of a diary entry file.""" try: return file_path.read_text(encoding="utf-8") except (FileNotFoundError, PermissionError, OSError) as e: return f"Error reading file: {e}"
- Helper method used by the tool to check if the diary entry file exists before attempting to read it.def entry_exists(self, date: datetime) -> bool: """Check if an entry exists for the given date.""" filename = date.strftime("%Y-%m-%d") file_path = self.diary_path / f"{filename}.md" return file_path.exists()
- Helper method used by the tool to construct the file path from the input date.def get_entry_path(self, date: datetime) -> Path: """Get the file path for an entry on the given date.""" filename = date.strftime("%Y-%m-%d") return self.diary_path / f"{filename}.md"