Skip to main content
Glama
madebygps

Obsidian Diary MCP Server

by madebygps

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
NameRequiredDescriptionDefault
dateYes

Implementation Reference

  • 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)
  • 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"

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/madebygps/obsidian-diary-mcp'

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