Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Markdown Tools: read_markdown & edit_markdown

Two dedicated tools for navigating and editing Markdown files using heading-based addressing. They replace the need to read raw line ranges or construct fragile string replacements against unstructured text.


read_markdown

Navigate a Markdown file by heading. Without heading/headings params, returns a heading map — the document outline with line numbers.

Parameters

ParamTypeDescription
pathstringMarkdown file path (relative to project root)
headingstringSingle section to read (fuzzy matched)
headingsstring[]Multiple sections in one call (mutually exclusive with heading)
start_line / end_lineintRaw line range fallback (1-indexed, inclusive)

Usage

// Step 1: get the heading map
read_markdown("docs/guide.md")
→ heading map with line numbers

// Step 2: read specific sections
read_markdown("docs/guide.md", headings=["## Auth", "## Config"])
→ both sections in one response

The heading map is the starting point for any markdown edit workflow — always read it first so you know which headings exist before targeting one.


edit_markdown

Edit a Markdown document section by heading. Heading matching is fuzzy## Auth matches ## Authentication — so you don’t need to quote headings exactly.

Actions

ActionDescription
replaceReplace section body (heading line is preserved)
insert_beforeInsert content before the heading
insert_afterInsert content after the section (before next heading)
removeDelete the section and its body
editSurgical string replacement within a section (old_stringnew_string)

Parameters

ParamTypeDescription
pathstringMarkdown file path
headingstringTarget section heading (fuzzy matched)
actionstringOne of the actions above
contentstringNew body for replace/insert_* (heading not included)
old_stringstringFor edit: exact text to find
new_stringstringFor edit: replacement text
replace_allboolFor edit: replace all occurrences (default: false)
editsarrayBatch mode — multiple operations applied atomically

Examples

// Replace a section body
edit_markdown("docs/guide.md",
  heading="## Configuration",
  action="replace",
  content="See project.toml for all options.\n")

// Surgical fix inside a section
edit_markdown("docs/guide.md",
  heading="## Auth",
  action="edit",
  old_string="secret_key = \"\"",
  new_string="secret_key = \"<your-key>\"")

// Batch: two edits in one atomic call
edit_markdown("docs/guide.md",
  edits=[
    { heading: "## Usage", action: "replace", content: "..." },
    { heading: "## License", action: "remove" }
  ])

Batch Mode

Pass an edits array instead of heading/action to apply multiple operations atomically. All edits are validated before any are applied — if one heading is missing, nothing changes.


Why Not edit_file?

edit_file works on raw strings and requires exact whitespace/newline matching. For Markdown, heading-scoped edits are both safer and more resilient:

Scenarioedit_fileedit_markdown
Replace a section bodyError-prone: must match surrounding blank lines exactlyaction=replace — heading preserved automatically
Edit text inside a sectionWorks, but edits anywhere in the fileaction=edit scoped to one section
Remove a sectionMust know exact start/end linesaction=remove — no line numbers needed
Multiple editsMultiple calls, each can conflictedits=[] batch — atomic