Skip to main content
Glama

get_daily_note

Access or create daily notes for specific dates in your Obsidian vault, maintaining organized documentation with automatic folder management and date-based retrieval.

Instructions

Get or create a daily note for a specific date

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
createNo
date_strNo
folderNoDaily Notes

Implementation Reference

  • MCP tool handler function that exposes get_daily_note tool, parses args, calls vault method, and formats response.
    @mcp.tool(name="get_daily_note", description="Get or create a daily note for a specific date")
    async def get_daily_note(
        date_str: str = "", folder: str = "Daily Notes", create: bool = True
    ) -> str:
        """
        Get or create a daily note.
    
        Args:
            date_str: Date in YYYY-MM-DD format (empty for today)
            folder: Folder where daily notes are stored
            create: If true, create the note if it doesn't exist
    
        Returns:
            Daily note content
        """
        context = _get_context()
    
        try:
            # Parse date
            if date_str:
                target_date = datetime.strptime(date_str, "%Y-%m-%d").date()
            else:
                target_date = None
    
            note = await context.vault.get_daily_note(target_date, folder, create)
    
            result = f"# Daily Note: {note.path}\n\n"
            if note.frontmatter:
                result += "## Frontmatter\n```yaml\n"
                result += yaml.dump(note.frontmatter, default_flow_style=False)
                result += "```\n\n"
    
            result += "## Content\n"
            result += note.body
    
            return result
    
        except ValueError as e:
            return f"Error: Invalid date format (use YYYY-MM-DD): {e}"
        except FileNotFoundError:
            return f"Error: Daily note not found for {date_str}"
        except Exception as e:
            logger.exception("Error getting daily note")
            return f"Error getting daily note: {e}"
  • Core implementation in ObsidianVault class: computes path, reads existing or creates new daily note with default content/frontmatter.
    async def get_daily_note(
        self,
        target_date: date | None = None,
        folder: str = "Daily Notes",
        create_if_missing: bool = True,
    ) -> Note:
        """
        Get or create a daily note.
    
        Args:
            target_date: Date for the daily note (defaults to today)
            folder: Folder where daily notes are stored
            create_if_missing: If True, create the note if it doesn't exist
    
        Returns:
            Daily note
        """
        if target_date is None:
            target_date = date.today()
    
        note_path = self.get_daily_note_path(target_date, folder)
    
        # Try to read existing note
        try:
            return await self.read_note(note_path)
        except FileNotFoundError:
            if not create_if_missing:
                raise
    
            # Create new daily note
            frontmatter = {
                "date": target_date.strftime("%Y-%m-%d"),
                "tags": ["daily-note"],
            }
    
            content = f"# {target_date.strftime('%A, %B %d, %Y')}\n\n"
    
            self.create_note(note_path, content, frontmatter)
            return await self.read_note(note_path)
  • Helper method to generate the filename and path for a daily note based on date and folder.
    def get_daily_note_path(
        self, target_date: date | None = None, folder: str = "Daily Notes"
    ) -> str:
        """
        Get the path for a daily note.
    
        Args:
            target_date: Date for the daily note (defaults to today)
            folder: Folder where daily notes are stored
    
        Returns:
            Relative path to the daily note
        """
        if target_date is None:
            target_date = date.today()
    
        # Format: YYYY-MM-DD.md
        filename = f"{target_date.strftime('%Y-%m-%d')}.md"
    
        if folder:
            return f"{folder}/{filename}"
        return filename

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/getglad/obsidian_mcp'

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