Skip to main content
Glama

obsidian_get_frontmatter

Extract YAML frontmatter metadata like tags and creation dates from Obsidian notes without loading full content for classification and organization.

Instructions

Extract YAML frontmatter metadata from a note.

Read metadata like tags, creation date, and other properties from Zettelkasten
notes without loading the full content.

Args:
    params (GetFrontmatterInput): Contains:
        - filepath (str): Path to file

Returns:
    str: JSON object containing frontmatter fields
    
Example:
    Get tags and metadata from a note to understand its classification.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • The handler function decorated with @mcp.tool that registers and implements the obsidian_get_frontmatter tool. It extracts frontmatter using the ObsidianClient and returns formatted JSON.
    @mcp.tool(
        name="obsidian_get_frontmatter",
        annotations={
            "title": "Get Note Frontmatter",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False
        }
    )
    async def get_frontmatter(params: GetFrontmatterInput) -> str:
        """Extract YAML frontmatter metadata from a note.
        
        Read metadata like tags, creation date, and other properties from Zettelkasten
        notes without loading the full content.
        
        Args:
            params (GetFrontmatterInput): Contains:
                - filepath (str): Path to file
        
        Returns:
            str: JSON object containing frontmatter fields
            
        Example:
            Get tags and metadata from a note to understand its classification.
        """
        try:
            frontmatter = await obsidian_client.get_file_frontmatter(params.filepath)
            
            return json.dumps({
                "success": True,
                "filepath": params.filepath,
                "frontmatter": frontmatter
            }, indent=2)
            
        except ObsidianAPIError as e:
            return json.dumps({
                "error": str(e),
                "filepath": params.filepath,
                "success": False
            }, indent=2)
  • Pydantic input schema for the tool, defining the required filepath parameter.
    class GetFrontmatterInput(BaseModel):
        """Input for getting frontmatter."""
        model_config = ConfigDict(str_strip_whitespace=True, extra='forbid')
        
        filepath: str = Field(
            description="Path to the file",
            min_length=1,
            max_length=500
        )
  • Helper method in ObsidianClient that reads the file content and parses the YAML frontmatter using the frontmatter library.
    async def get_file_frontmatter(self, filepath: str) -> Dict[str, Any]:
        """Extract frontmatter from a file."""
        content = await self.read_file(filepath)
        metadata, _ = self.parse_frontmatter(content)
        return metadata
  • Utility method that uses the 'frontmatter' library to parse YAML frontmatter from markdown content, returning metadata and body.
    def parse_frontmatter(self, content: str) -> tuple[Dict[str, Any], str]:
        """
        Parse frontmatter from content.
        
        Returns:
            Tuple of (frontmatter_dict, body_content)
        """
        try:
            post = frontmatter.loads(content)
            return post.metadata, post.content
        except Exception:
            # No frontmatter found
            return {}, content

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/Shepherd-Creative/obsidian-mcp'

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