Skip to content

Markdown Frontmatter Plugin

The markdown_frontmatter plugin provides a tool to extract and parse metadata from Markdown files. It uses python-frontmatter to cleanly separate frontmatter blocks (YAML, TOML, or JSON) from the document body, and returns the parsed metadata in a user-specified format.

Tools

get_markdown_frontmatter

Extracts and parses frontmatter from a Markdown file.

Arguments:

  • file_path (string, required): Path to the Markdown file.
  • output_format (string, optional): The format in which to return the metadata. Allowed values are "json", "yaml", "toml", or "dict". Defaults to "json".

Features:

  • Automatic Format Detection: Seamlessly handles YAML (---), TOML (+++), and JSON frontmatter.
  • .aiignore Compliance: If the target file is ignored by .aiignore rules, the tool will refuse to process it, returning an error.
  • Size Limits: Ensures files do not exceed a safe processing size (defaults to 1MB).
  • Flexible Output: Allows the caller to consume the metadata in the most convenient format.

Example

Assuming you have a file post.md with the following content:

---
title: My First Post
author: Alice
tags: [markdown, frontmatter]
---
# Content starts here

When you invoke the tool:

{
  "file_path": "post.md",
  "output_format": "json"
}

The tool will return:

{
  "status": "ok",
  "frontmatter": "{\n  \"title\": \"My First Post\",\n  \"author\": \"Alice\",\n  \"tags\": [\n    \"markdown\",\n    \"frontmatter\"\n  ]\n}"
}