md-mcp
md-mcp lets agents inspect, search, and surgically modify individual Markdown sections via dot-path addresses without rewriting whole files.
Build a file's section tree with
get_index, returning headings, levels, dot paths, and children; frontmatter appears as a separatefrontmatternode per README.Read a section or subtree as raw Markdown with
get_section, optionally limiting included child depth.Search section bodies by Python regex with
search_sections, optionally case-sensitive; heading text is not searched by this schema.Insert new sections with
add_sectionusing a heading and body, placed under, before, after, or appended.Replace a section's body while preserving its heading with
replace_section.Preview changes as a unified diff with
patch_sectionwithout writing to disk.Delete a section with
delete_section, optionally promoting its children instead of deleting them.Address sections with case-insensitive dot-separated heading paths; literal dots in heading text are escaped as
\.per schema.README notes byte-preserving writes, CRLF/newline fidelity, and
frontmatterread/replace support (with YAML mapping validation); add/delete rejectfrontmatter.
Provides tools for reading, searching, and editing Markdown files at the section level, including section indexing, dot-path addressing, and add/replace/patch/delete operations without rewriting the whole document.
Supports reading and editing YAML frontmatter blocks in Markdown files, including replacement, patching, search, and validation that edits remain a valid YAML mapping.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@md-mcp Fetch the 'Installation' section from docs/guide.md"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
md-mcp
An MCP server that gives agents surgical read/write access to individual sections of Markdown files.
Overview
Large Markdown files — documentation, changelogs, wikis — are expensive for agents to work with: reading the entire file just to update one section wastes tokens, and rewriting the whole file risks accidental data loss. md-mcp solves this by exposing each section as an individually addressable unit, so an agent can fetch, edit, or delete exactly the slice it needs without touching anything else.
The server runs over stdio as a local MCP server. Files are addressed by path on disk; sections within a file
are addressed by a dot-separated heading path (e.g. "User Guide.Installation.Prerequisites"). Parsed ASTs are
cached in memory and invalidated automatically on mtime change, so repeated reads of an unchanged file are fast.
Related MCP server: mnema
Installation
The package is not yet published to PyPI. Install it in editable mode directly from the repository.
pip
pip install -e .uv
uv pip install -e .Connecting to opencode / Claude Desktop
After installation the md-mcp entry-point script is on your PATH. Add it as a local stdio MCP server in your client config.
opencode (opencode.json / opencode.jsonc)
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"md-mcp": {
"type": "local",
"command": ["md-mcp", "--allow-root", "/your/docs/dir"]
}
}
}Claude Desktop (claude_desktop_config.json)
Claude Desktop uses the top-level key mcpServers:
{
"mcpServers": {
"md-mcp": {
"command": "md-mcp",
"args": [],
"transport": "stdio"
}
}
}Dot-path addressing
Every tool that targets a section takes a path argument — a dot-separated string of heading texts from the
document root down to the target section. Given this Markdown file:
# My Project
## Installation
### Prerequisites
## UsageThe available paths are:
Section | Path |
|
|
|
|
|
|
|
|
Matching is case-insensitive, so my project.installation and My Project.Installation resolve to the
same section. Ambiguous paths (duplicate heading texts at the same level) resolve to the first match.
Tool reference
Tool | Arguments | Returns | Description |
|
|
| Returns the full section tree of a file as a nested dict with |
|
|
| Returns the raw Markdown text of the named section. |
|
|
| Searches lines matching |
|
|
| Runs |
|
|
| Inserts a new section. |
|
|
| Replaces the body of the named section, preserving its heading line. |
|
|
| Replaces the exact string |
|
|
| Returns a unified diff of what |
|
|
| Deletes the named section. With |
File paths. Pass file_path (and directory) as an absolute path, e.g. /path/to/repo/docs/guide.md. A relative path resolves against the md-mcp server process's working directory, not the MCP client's workspace, so repo/docs/guide.md becomes <server cwd>/repo/docs/guide.md and fails when the server already runs in repo. A leading ~ expands to the home directory. --allow-root only restricts which resolved paths are accepted; it is not a base directory.
Frontmatter
A file has frontmatter when its first line is exactly ---, a later line is exactly ---, and the lines between
them are a YAML mapping (key: value lines). {{ ... }} template actions inside count as scalar values; a block that
fails to parse only because it contains {{ template syntax (e.g. {{- if .x }} around keys) is still frontmatter.
Anything else — such as a document that opens with a horizontal rule and has another one later — is not frontmatter
and is parsed as ordinary Markdown, headings included.
get_index lists frontmatter as a separate first node {"heading": "frontmatter", "level": 0, "path": "frontmatter", "children": []};
it is never parsed as a heading and the body after it is indexed normally. The path frontmatter is reserved: when a file
has a frontmatter block it takes precedence over a top-level heading literally named "frontmatter". get_section,
replace_section, patch_section, replace_in_section and search_sections accept it; add_section and delete_section
reject it. An edit must leave a valid YAML mapping (templates as scalars) or it is rejected and the file stays unchanged;
a block that already could not be parsed because of template syntax is not re-validated.
Template files and byte fidelity
Files with {{ ... }} template actions (e.g. *.md.tmpl) are supported: # inside a fenced code block or inside a
multi-line template action is text, not a heading. A template action may span at most 20 lines and never a blank line;
an unbalanced {{ is plain text. Every write tool (replace_section, replace_in_section, add_section,
delete_section) preserves all bytes outside the edited span: CRLF, mixed and lone-CR line endings, trailing blank
lines, and a missing final newline. Lines created by an edit use the file's dominant line ending. Lines are split on \n
only, so form feed, U+2028 and similar characters stay inside their line.
Examples
A short worked session against a file docs/guide.md whose top-level heading is User Guide:
1. Inspect the structure
get_index("docs/guide.md")Returns a nested tree:
{
"sections": [
{
"heading": "User Guide",
"level": 1,
"path": "User Guide",
"children": [
{
"heading": "Getting Started",
"level": 2,
"path": "User Guide.Getting Started",
"children": []
},
{
"heading": "Configuration",
"level": 2,
"path": "User Guide.Configuration",
"children": []
}
]
}
]
}2. Read a section
get_section("docs/guide.md", "User Guide.Getting Started")Returns the raw Markdown text of that section (heading line + body).
3. Preview a change
patch_section("docs/guide.md", "User Guide.Configuration", "Set `debug: true` in `config.yaml`.")Returns a unified diff showing exactly what would change — nothing is written yet.
4. Apply the change
replace_section("docs/guide.md", "User Guide.Configuration", "Set `debug: true` in `config.yaml`.")Returns "ok". The file is updated; the heading line is preserved unchanged.
5. Add a new section
add_section("docs/guide.md", "## Troubleshooting", "See the FAQ.", after="User Guide.Configuration")Returns "ok". The new ## Troubleshooting section is inserted immediately after ## Configuration.
6. Find sections mentioning a term
search_sections("docs/guide.md", "debug")Returns:
[
{
"path": "User Guide.Configuration",
"matches": [
{"line": 18, "text": "Set `debug: true` in `config.yaml`."}
]
}
]Development
Requirements: Python 3.11+
Install the package with dev dependencies:
pip install -e ".[dev]"Run the test suite:
pytestSet up and run pre-commit hooks (ruff + mypy):
pre-commit install
pre-commit run --all-filesAvailable Tools
7 toolsadd_sectionA
Insert a new section into a Markdown file.
heading must start with 1–6 '#' characters followed by a space, e.g. "## New Section".
content is the body text (no heading line).
Placement: exactly one of under, before, after may be set, or all None to append.
under: insert as the last child of the named sectionbefore: insert immediately before the named sectionafter: insert immediately after the named section (and all its children) Returns "ok" on success.
Inputs: content (required), heading (required), file_path (required), after, +2 more. Returns: result
delete_sectionA
Delete a section from a Markdown file.
With include_children=True (default): deletes the heading, its body, and all child sections. With include_children=False: deletes only the heading and its own body; child sections are promoted. Returns "ok" on success.
Inputs: path (required), file_path (required), include_children. Returns: result
get_indexA
Return the section index of a Markdown file as a nested tree.
Each node: {"heading": str, "level": int, "path": str, "children": [...]} The "path" field is the dot-separated address used by all other tools. Literal dots in heading text are represented as . in path strings.
Inputs: file_path (required). Returns: object
get_sectionA
Return the heading line(s) and body of the section at path.
path is a dot-separated heading path, e.g. "My README.Installation.Prerequisites".
Matching is case-insensitive. Returns the raw Markdown text of the section.
depth controls how many levels of child sections are included:
None (default): return the section and all descendants
0: return the heading and its own body only (no child sections)
1: heading + own body + immediate children
2: heading + own body + children + grandchildren etc.
Raises an error string if the path does not exist.
Inputs: path (required), file_path (required), depth. Returns: result
patch_sectionA
Return a unified diff of what replace_section would do, without writing.
Useful for previewing changes before committing them. Returns the unified diff as a string (empty string if no changes).
Inputs: path (required), file_path (required), new_content (required). Returns: result
replace_sectionA
Replace the body of a section, preserving its heading line.
The heading line is kept unchanged; only the body text is replaced. Returns "ok" on success.
Inputs: path (required), file_path (required), new_content (required). Returns: result
search_sectionsA
Search all section bodies for lines matching query (regex).
Returns a list of match objects — one per section that contains at least one hit — in file order:
[
{
"path": "Root.Child",
"matches": [
{"line": 12, "text": "...the matching line text..."},
...
]
},
...
]line is the 1-based line number within the file.
Only each section's own body is searched (not its children), so results
are never duplicated across parent and child sections.
Note: heading text is not searched — only section bodies. If the term you
are looking for may appear in a heading, call get_index first and scan
the returned paths.
query is a Python regex; raises an error string if the pattern is invalid.
Inputs: query (required), file_path (required), case_sensitive. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool has a clearly distinct purpose: adding, deleting, getting index, getting content, previewing replacement, replacing, and searching. Even the closely related patch_section and replace_section serve different functions (preview vs action). No overlap.
All tool names follow a consistent verb_noun pattern in snake_case (add_section, delete_section, get_index, get_section, patch_section, replace_section, search_sections). Deviations are absent.
7 tools is well-scoped for the domain of Markdown section manipulation. Each tool addresses a core operation without redundancy, and the count is neither too few nor too many.
The toolset covers essential CRUD-like operations (add, read, update, delete) plus search and preview. However, it lacks a tool to rename a section heading or move sections, which are minor gaps in a complete lifecycle.
Maintenance
Related MCP Connectors
Agent-native MCP server over the public saagarpatel.dev corpus. Read-only, stateless.
One memory, every AI. A shared, user-owned markdown memory your AI clients read and write over MCP.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Markdown-based note-taking with a hosted MCP server. Your notes serve you and your AI.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceMCP server that syncs Markdown docs from a GitHub repository and provides search, reading, and listing capabilities for AI agents.-
- AlicenseNot gradedqualityDmaintenanceProvides a file-first personal memory layer for AI agents, enabling them to store and retrieve memories as markdown files with an SQLite index. The MCP server offers read-only search by default, with optional write tools for manual memory addition and conflict resolution.4 npmMIT
- AlicenseAqualityCmaintenanceAn MCP server that gives AI models a persistent notebook backed by a folder of Markdown files, with tools to discover, read, write, edit, and delete notes.9MIT
- AlicenseNot gradedqualityAmaintenanceAn MCP server that enables verified agents to retrieve from, propose changes to, and share capabilities around a human-owned Markdown/Git knowledge base, ensuring curation, exact-byte approval, and Git-based promotion.MIT