Skip to main content
Glama
Vault Cortex Obsidian MCP Server

Vault Cortex Obsidian MCP Server

Replace in Note

vault_replace_in_note
Destructive

Find and replace exact text in a markdown note body to fix typos, update values, rename terms, or delete a short line while leaving properties unchanged; enable all occurrences for bulk edits.

Instructions

Find and replace exact text in a markdown note's body. Properties are kept as written, and body line breaks are saved as LF. Edit properties via vault_update_properties or vault_write_note's properties parameter. A repeated call replaces old_text again if the note still holds it, including a copy inside the first call's new_text, so after a timeout or lost response, re-read the note before retrying.

Example: vault_replace_in_note({ path: "Projects/plan.md", old_text: "TODO: write summary", new_text: "Summary complete." }) Example: vault_replace_in_note({ path: "Projects/plan.md", old_text: "- [ ] draft outline\n", new_text: "" }) Example: vault_replace_in_note({ path: "Projects/plan.md", old_text: "Q3", new_text: "Q4", replace_all_occurrences: true })

When to use: Targeted text changes within a single location — fixing typos, updating values, renaming terms, or removing a short line (new_text=""). To delete a large multi-line block, prefer vault_delete_span (short anchors instead of full old_text). To replace a large block by anchors instead of reproducing the full old_text, use vault_replace_span. To relocate content between headings, use vault_patch_note to add at the target first, then remove from source (new_text="") — add-before-delete, so a failure duplicates the block instead of losing it.

Parameters:

  • old_text: include enough surrounding context to ensure uniqueness when the target text appears in multiple places.

  • replace_all_occurrences: set true for deliberate bulk renames or term replacements.

Behavior:

  • A non-empty new_text replaces the match exactly; new_text="" deletes it, and when text remains on the line, the line is written exactly as asked.

  • When new_text="" leaves the match's line empty, blank lines never double: the text above and below ends up separated by the wider of the two runs of empty lines that stood there, and by at least one.

  • At the note's end, where no text follows, the run of empty lines above is kept one line shorter ("A\n\nB\n" without "B" → "A\n").

  • To remove a table row or list item, include its line break in old_text, or the empty line left behind splits the table or list.

  • A line holding only spaces or tabs counts as text, not as an empty line.

Errors:

  • "note not found" — path does not exist; check vault_list_notes for valid paths

  • "path must end in …" — add the .md extension

  • "text not found" — old_text does not appear in the note body; verify exact text with vault_read_note

  • "absolute path blocked" / "path traversal blocked" / "hidden path blocked" — pass a vault-relative path with no dot-prefixed part

  • "concurrent write in progress" — a write to this note is in flight; re-read it and retry

  • "new_text contains a control character" — remove the character the message names

  • "ENAMETOOLONG: …" or another filesystem error — the message says what to do

  • "the note would open with a properties block …" — a note without properties would start with --- lines around text that can't be properties; the error says how to avoid it

Obsidian syntax: new_text is Obsidian Flavored Markdown (no escaping applied). Watch for: #word = tag, [[ = wikilink, %% = comment block in replacement text.

Returns: "Replaced occurrence(s) in ".

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "path": "<path>",
      "old_text": "<old_text>",
      "new_text": "<new_text>"
    },
    "name": "vault_replace_in_note"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYesVault-relative path to the note, including the ".md" extension (e.g. "Projects/plan.md"). Use the exact letter case.
new_textYesReplacement text; "" deletes the matched text.
old_textYesExact text to find, no regex (case-sensitive).
replace_all_occurrencesNoReplace all occurrences (default: false — replaces first occurrence only)

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.56.3
    • changedInput schema / properties / new_text / description
      Previous value: -"Replacement text. Empty string (\"\") deletes the matched text."New value: +"Replacement text; \"\" deletes the matched text."
  2. Changed1 schema field changedv0.55.1
    • changedInput schema / properties / old_text / description
      Previous value: -"Exact text to find (case-sensitive)."New value: +"Exact text to find, no regex (case-sensitive)."
  3. Changed2 schema fields changedv0.54.16
    • addedInput schema / additionalProperties
      Added value: +false
    • changedInput schema / properties / old_text / description
      Previous value: -"Exact text to find (case-sensitive). Matches in the body only — text inside frontmatter properties is not searched."New value: +"Exact text to find (case-sensitive)."
  4. Changed1 schema field changedv0.54.7
    • changedInput schema / properties / path / description
      Previous value: -"Vault-relative path to the note, including the \".md\" extension (e.g. \"Projects/plan.md\")"New value: +"Vault-relative path to the note, including the \".md\" extension (e.g. \"Projects/plan.md\"). Use the exact letter case."
  5. Changed1 schema field changedv0.50.0
    • addedInput schema / properties / replace_all_occurrences / default
      Added value: +false
  6. Addedv0.32.1
  7. Removedv0.32.0
  8. Changed1 schema field changedv0.23.10
    • changedInput schema / properties / path / description
      Previous value: -"Vault-relative path to the note (e.g. \"Projects/plan.md\")"New value: +"Vault-relative path to the note, including the \".md\" extension (e.g. \"Projects/plan.md\")"
  9. Changed3 schema fields changedv0.23.5
    • changedInput schema / properties / new_text / description
      Previous value: -"Replacement text"New value: +"Replacement text. Empty string (\"\") deletes the matched text."
    • changedInput schema / properties / old_text / description
      Previous value: -"Exact text to find (case-sensitive, non-empty)"New value: +"Exact text to find (case-sensitive). Matches in the body only — text inside frontmatter properties is not searched."
    • changedInput schema / properties / path / description
      Previous value: -"Vault-relative path to the note"New value: +"Vault-relative path to the note (e.g. \"Projects/plan.md\")"
  10. Added

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations declare destructiveHint=true and idempotentHint=false, but the description goes well past them: it warns that a repeated call will re-replace old_text even if it now lives inside the prior call's new_text, so a re-read is required after a timeout — a real data-loss hazard the annotations cannot express. It also documents LF line-break normalization, blank-line collapsing rules, the table/list splitting pitfall when the line break is omitted, and a full error-to-cause mapping.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Structure is strong — purpose, examples, when-to-use, parameters, behavior, errors, syntax, returns — with the core contract front-loaded. It is long for a single tool, and the three separate blank-line/end-of-note bullets are dense enough that they could be consolidated without losing meaning.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive, non-idempotent mutation with no output schema, the definition covers everything an agent needs: return string format, whitespace semantics, Obsidian Markdown pitfalls (#, [[, %%), retry safety, and error recovery paths. No output schema exists, so documenting the "Replaced <N> occurrence(s) in <path>" return is a genuine addition.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description still adds actionable meaning, advising enough surrounding context in old_text to guarantee uniqueness and reserving replace_all_occurrences for deliberate bulk renames. It stops short of restating types or defaults, so the gain is modest rather than substantial.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb and resource: "Find and replace exact text in a markdown note's body." It immediately scopes the operation to note bodies (properties excluded) and points property edits to vault_update_properties and vault_write_note, so the agent can distinguish it from adjacent write tools without reading schemas.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The "When to use" block names concrete scenarios (typos, value updates, term renames, short-line removal) and explicitly routes alternatives: vault_delete_span for large block deletion, vault_replace_span for anchor-based replacement, vault_patch_note for relocating content with an add-before-delete rationale. Three worked examples show the exact call shape including the empty new_text deletion case.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.