Skip to main content
Glama

obsidian_get_frontmatter

Extract YAML frontmatter metadata from Obsidian notes to access tags, creation dates, and properties without loading full content for efficient Zettelkasten workflows.

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

  • MCP tool handler that reads frontmatter from specified file path by delegating to ObsidianClient
    @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 model validating the input 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 )
  • Core implementation: reads file content and parses YAML frontmatter using frontmatter.loads
    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
  • Helper function to parse frontmatter from markdown content using the frontmatter library
    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 def serialize_with_frontmatter(self, metadata: Dict[str, Any], body: str) -> str: """Serialize content with frontmatter.""" post = frontmatter.Post(body, **metadata) return frontmatter.dumps(post)

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