Skip to main content

frontmatter-mcp

An MCP server for querying Markdown frontmatter with DuckDB SQL.

Configuration

Basic Usage

{
  "mcpServers": {
    "frontmatter": {
      "command": "uvx",
      "args": ["frontmatter-mcp"],
      "env": {
        "FRONTMATTER_BASE_DIR": "/path/to/markdown/directory"
      }
    }
  }
}

Semantic search requires large dependencies (~1GB). Set MCP_TIMEOUT to extend installation timeout:

{
  "mcpServers": {
    "frontmatter": {
      "command": "uvx",
      "args": ["--from", "frontmatter-mcp[semantic]", "frontmatter-mcp"],
      "env": {
        "FRONTMATTER_BASE_DIR": "/path/to/markdown/directory",
        "FRONTMATTER_ENABLE_SEMANTIC": "true",
        "MCP_TIMEOUT": "300000"
      }
    }
  }
}

Note: MCP_TIMEOUT is in milliseconds (300000 = 5 minutes).

Installation (Optional)

If you prefer to install globally:

pip install frontmatter-mcp
# or
uv tool install frontmatter-mcp

Tools

query_inspect

Get schema information from frontmatter across files.

Parameter Type Description
glob string Glob pattern relative to base directory

Example:

// Input
{ "glob": "**/*.md" }

// Output
{
  "file_count": 186,
  "schema": {
    "path": { "type": "string", "nullable": false, "examples": ["notes/a.md"] },
    "date": { "type": "string", "nullable": true, "examples": ["2025-11-28"] },
    "tags": { "type": "array", "nullable": true, "examples": [["python", "mcp"]] }
  }
}

// With semantic search ready, the schema also has
//   "embedding": { "type": "FLOAT[256]", "nullable": true }
// (NULL for files without indexed text)

query

Query frontmatter data with DuckDB SQL.

Parameter Type Description
glob string Glob pattern relative to base directory
sql string DuckDB SQL query referencing files table

Example:

// Input
{
  "glob": "**/*.md",
  "sql": "SELECT path, date FROM files WHERE date >= '2025-11-01' ORDER BY date DESC"
}

// Output
{
  "columns": ["path", "date"],
  "row_count": 24,
  "results": [
    {"path": "daily/2025-11-28.md", "date": "2025-11-28"},
    {"path": "daily/2025-11-27.md", "date": "2025-11-27"}
  ]
}

update

Update frontmatter properties in a single file.

Parameter Type Description
path string File path relative to base directory
set object Properties to add or overwrite
unset string[] Property names to remove

Example:

// Input
{ "path": "notes/idea.md", "set": {"status": "published"} }

// Output
{
  "path": "notes/idea.md",
  "frontmatter": {"title": "Idea", "status": "published"},
  "updated": true
}

updated is false when the values were already as requested; the file is then not written.

batch_update

Update frontmatter properties in multiple files.

Parameter Type Description
glob string Glob pattern relative to base directory
set object Properties to add or overwrite
unset string[] Property names to remove

Example:

// Input
{ "glob": "drafts/*.md", "set": {"status": "review"} }

// Output
{ "updated_count": 5, "updated_files": ["drafts/a.md", "drafts/b.md", ...] }

Files whose values are already as requested are not written and not listed.

batch_array_add

Add a value to an array property in multiple files.

Parameter Type Description
glob string Glob pattern relative to base directory
property string Name of the array property
value any Value to add
allow_duplicates bool Allow duplicate values (default: false)

Example:

// Input
{ "glob": "**/*.md", "property": "tags", "value": "reviewed" }

// Output
{ "updated_count": 42, "updated_files": ["a.md", "b.md", ...] }

batch_array_remove

Remove a value from an array property in multiple files.

Parameter Type Description
glob string Glob pattern relative to base directory
property string Name of the array property
value any Value to remove

Example:

// Input
{ "glob": "**/*.md", "property": "tags", "value": "draft" }

// Output
{ "updated_count": 15, "updated_files": ["a.md", "b.md", ...] }

batch_array_replace

Replace a value in an array property in multiple files.

Parameter Type Description
glob string Glob pattern relative to base directory
property string Name of the array property
old_value any Value to replace
new_value any New value

Example:

// Input
{ "glob": "**/*.md", "property": "tags", "old_value": "draft", "new_value": "review" }

// Output
{ "updated_count": 10, "updated_files": ["a.md", "b.md", ...] }

batch_array_sort

Sort an array property in multiple files.

Parameter Type Description
glob string Glob pattern relative to base directory
property string Name of the array property
reverse bool Sort in descending order (default: false)

Example:

// Input
{ "glob": "**/*.md", "property": "tags" }

// Output
{ "updated_count": 20, "updated_files": ["a.md", "b.md", ...] }

batch_array_unique

Remove duplicate values from an array property in multiple files.

Parameter Type Description
glob string Glob pattern relative to base directory
property string Name of the array property

Example:

// Input
{ "glob": "**/*.md", "property": "tags" }

// Output
{ "updated_count": 5, "updated_files": ["a.md", "b.md", ...] }

Search document text and return the best-matching passage of each document. Finds paraphrases as well as exact names.

This tool is only available when FRONTMATTER_ENABLE_SEMANTIC=true.

Parameter Type Description
query string What to look for, as a sentence or keywords
glob string Glob pattern to search within (default **/*.md)
where string Optional SQL condition on frontmatter, same columns as query
limit number Maximum documents to return, 1-50 (default 10)
exclude_sections string[] Headings whose passages are skipped, at any level (optional)

Example:

// Input
{ "query": "felt lonely on my birthday", "where": "date < '2025-11-01'", "limit": 5 }

// Output
{
  "results": [
    {
      "path": "daily/2025-10-15.md",
      "line": 42,
      "heading": "Timeline",
      "section": ["Daily", "Timeline"],
      "text": "Timeline\n- 20:48 Nobody around on my birthday ...",
      "score": 0.9312
    }
  ],
  "index": { "state": "ready", "has_index": true, "last_run": { "indexed": 1903, "removed": 0, "failed": 0, "error": null } }
}

line is where the passage starts in the file. section is the heading path from the top level down to heading, so a passage under a recurring section (for example comments added to each note by a tool) can be told apart; exclude_sections leaves such sections out of the search. Scores are only comparable within one search.

index_status

Get the status of the semantic search index.

This tool is only available when FRONTMATTER_ENABLE_SEMANTIC=true.

Example:

// Output (not started in this session; the first search starts it)
{ "state": "idle", "has_index": false, "last_run": null }

// Output (after a run)
{
  "state": "ready",
  "has_index": true,
  "last_run": { "indexed": 12, "removed": 0, "failed": 0, "error": null }
}

has_index stays true while a later refresh runs (the previous index is served). last_run.error says why a run stopped early (for example, the model could not be downloaded).

index_wait

Wait until a running indexing run finishes (or the timeout passes).

This tool is only available when FRONTMATTER_ENABLE_SEMANTIC=true.

Parameter Type Description
timeout number Maximum seconds to wait (default 60)

Example:

// Output
{ "success": true, "state": "ready", "has_index": true, "last_run": { "indexed": 3, "removed": 0, "failed": 0, "error": null } }

success is false when the timeout passed while indexing was still running.

index_refresh

Refresh the semantic search index (differential update).

This tool is only available when FRONTMATTER_ENABLE_SEMANTIC=true.

Example:

// Output
{ "state": "indexing", "message": "Indexing started", "target_count": 665 }

// Output (when already indexing)
{ "state": "indexing", "message": "Indexing already in progress" }

Technical Notes

Warnings

Tools that read or write many files report per-file problems instead of failing: "warnings": [{ "path": "notes/a.md", "error": "..." }] (malformed frontmatter, a property that is not an array, a frontmatter key named path, which is reserved for the file path). SQL errors fail the call and list the columns of the files table.

Array Operations

batch_array_remove and batch_array_replace act on every occurrence of the value. batch_array_sort skips (with a warning) arrays whose values can't be compared.

All Values Are Strings

All frontmatter values are passed to DuckDB as strings. Use TRY_CAST in SQL for type conversion when needed.

SELECT * FROM files
WHERE TRY_CAST(date AS DATE) >= '2025-11-01'

Arrays Are JSON Strings

Arrays like tags: [ai, python] are stored as JSON strings '["ai", "python"]'. Use from_json() and UNNEST to expand them.

SELECT path, tag
FROM files, UNNEST(from_json(tags, '[""]')) AS t(tag)
WHERE tag = 'ai'

Writes Keep the File's Formatting

The update tools rewrite only the frontmatter keys whose values change. Other keys, comments, quotes, line wrapping, and the body stay byte for byte. A replaced list keeps its style (tags: [a, b] stays inline, block lists keep their indentation), and a new list follows the style already used in the file. Files are written atomically, so a failed write never leaves a partial file.

Excluding Files

FRONTMATTER_EXCLUDE takes comma-separated globs relative to FRONTMATTER_BASE_DIR, such as IDENTITY.md,_templates. Matching files are left out of query and the write tools, update refuses them, and the semantic index drops them on its next run. A pattern that matches a directory excludes everything under it; **/name.md matches at any depth. Dot directories (.obsidian, .git) are always skipped by the semantic index.

Templater Expression Support

Files containing Obsidian Templater expressions (e.g., <% tp.date.now("YYYY-MM-DD") %>) are handled gracefully. These expressions are treated as strings and naturally excluded by date filtering.

Each file's body is split into chunks of about 400 characters at headings and line breaks, and each chunk is embedded. Chunks with under 20 characters of text once links, embeds, URLs and list markers are removed are not indexed. A chunk whose text, ignoring checkbox state, numbers and whitespace, appears in 10 or more documents is template text (a daily checklist, for example) and is never returned by search. Indexing starts on the first semantic call (search, a query using embed(), or index_refresh), not at server startup, and only re-reads files whose mtime changed. Dot directories such as .obsidian are skipped.

The search tool combines three signals:

  1. Dense: cosine similarity of query and chunk embeddings. With ruri-v3 models the recommended prefixes (検索クエリ: / 検索文書: ) are applied
  2. Lexical: BM25 over character bigrams, which needs no Japanese tokenizer and catches exact names and phrases
  3. Rerank: a cross-encoder scores the best chunks of the top candidates from 1 and 2. With the reranker turned off, 1 and 2 are combined by weighted reciprocal rank fusion

On a 1,900-file Japanese vault with 16 queries that each have one known target document, the target ranked first for 2 queries with the previous whole-document embeddings and 13 with this pipeline (top 5: 6 and 15). Reranking adds about 0.3 seconds per query.

SQL access is still available: embedding is the normalized mean of a document's chunk vectors, and embed() encodes a query.

SELECT path, array_cosine_similarity(embedding, embed('feeling better')) AS score
FROM files
WHERE embedding IS NOT NULL AND date >= '2025-11-01'
ORDER BY score DESC
LIMIT 10

Environment variables:

Variable Default Description
FRONTMATTER_BASE_DIR (required) Base directory for files
FRONTMATTER_EXCLUDE (none) Comma-separated globs no tool reads, writes or indexes
FRONTMATTER_ENABLE_SEMANTIC false Enable semantic search
FRONTMATTER_EMBEDDING_MODEL cl-nagoya/ruri-v3-30m Embedding model name
FRONTMATTER_EMBEDDING_QUERY_PREFIX model default (検索クエリ: for ruri-v3) Prefix added to queries
FRONTMATTER_EMBEDDING_DOCUMENT_PREFIX model default (検索文書: for ruri-v3) Prefix added to indexed chunks
FRONTMATTER_RERANKER_MODEL hotchpotch/japanese-reranker-xsmall-v2 Cross-encoder for search; empty string turns it off
FRONTMATTER_CACHE_DIR FRONTMATTER_BASE_DIR/.frontmatter-mcp Cache directory for embeddings

Changing the model or the document prefix rebuilds the cache on the next start. Each schema version has its own file (chunks-v4.duckdb), so sessions still running an older version keep their own store instead of deleting the new one; files of other versions are deleted once no process has them open.

Resource use, measured on a 1,900-file vault (27,700 chunks) on an M-series Mac:

Server memory before any semantic call about 110 MB (torch and the models are loaded on first use)
Memory after the first search about 1.1 GB (torch, both models, vectors, BM25 index)
First full index about 90 s; later runs only re-index changed files (300 files: about 15 s)
One search about 0.4 s (retrieval about 10 ms, rerank about 0.3 s); the first search also loads the models (a few seconds)
Cache file about 35 MB; rewritten after indexing once it grows 25% (and 8 MB) past its compact size
Model downloads (Hugging Face cache) about 150 MB each for the embedding model and the reranker

License

MIT

Metadata

Release files for frontmatter-mcp 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for frontmatter-mcp 0.7.1
File Size Uploaded Provenance Actions
frontmatter_mcp-0.7.1.tar.gz 276.6 kB With provenance Details for frontmatter_mcp-0.7.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for frontmatter-mcp 0.7.1
File Interpreter ABI Platform Actions
frontmatter_mcp-0.7.1-py3-none-any.whl Python 3 none any Details for frontmatter_mcp-0.7.1-py3-none-any.whl

Total release size: 325.0 kB

Release files / frontmatter_mcp-0.7.1.tar.gz

Download URL frontmatter_mcp-0.7.1.tar.gz
Size 276.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5fb3807e0d5917f5cc27f7a84932d0560ea3d4154a2bcd837f98e42b663f3890
BLAKE2b-256 checksum
How to use checksums
e02c6a3c87baa52895ba7f2bf0a0a2e417ae962c3d43f86a703df7c9e5e587e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / frontmatter_mcp-0.7.1-py3-none-any.whl

Download URL frontmatter_mcp-0.7.1-py3-none-any.whl
Size 48.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6387905857683a29439efec562ad9210925da33f01fc2741e608beabba2b71d6
BLAKE2b-256 checksum
How to use checksums
3db2e490c93739dc2df8f6444a54600b9ba200f144eaef66b11f51c882c253d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for frontmatter-mcp 0.7.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for frontmatter_mcp-0.7.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page