Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_replace_in_note

Replace text in a single Obsidian note using literal or regex search. Supports case-sensitive matching and replacing all occurrences at once.

Instructions

Search and replace inside one note. Supports literal or regex matching and replaceAll.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
pathYesVault-relative path. Absolute paths and traversal are rejected.
searchYes
replaceYes
regexNo
caseSensitiveNo
replaceAllNo

Implementation Reference

  • src/tools.ts:522-546 (registration)
    Registration of the 'obsidian_replace_in_note' tool with its schema (args validation) and handler function. This is the complete tool definition including the schema and the handler.
      "obsidian_replace_in_note",
      "Search and replace inside one note. Supports literal or regex matching and replaceAll.",
      {
        vault: vaultArg,
        path: pathArg,
        search: z.string(),
        replace: z.string(),
        regex: z.boolean().optional().default(false),
        caseSensitive: z.boolean().optional().default(false),
        replaceAll: z.boolean().optional().default(false),
      },
      async (args) => {
        const read = await vaults.readText(args.path, args.vault);
        const flags = `${args.replaceAll ? "g" : ""}${args.caseSensitive ? "" : "i"}`;
        const re = new RegExp(args.regex ? args.search : escapeRegExp(args.search), flags);
        let count = 0;
        const next = read.text.replace(re, () => {
          count += 1;
          return args.replace;
        });
        if (count === 0) return { path: read.path, replaced: 0 };
        await vaults.writeText(read.path, next, args.vault, { overwrite: true });
        return { path: read.path, replaced: count };
      },
    );
  • The handler function for obsidian_replace_in_note — reads the note, builds a RegExp from the search pattern with appropriate flags (global for replaceAll, case-insensitive by default), performs the replacement counting occurrences, writes back if replacements happened, and returns the count.
      async (args) => {
        const read = await vaults.readText(args.path, args.vault);
        const flags = `${args.replaceAll ? "g" : ""}${args.caseSensitive ? "" : "i"}`;
        const re = new RegExp(args.regex ? args.search : escapeRegExp(args.search), flags);
        let count = 0;
        const next = read.text.replace(re, () => {
          count += 1;
          return args.replace;
        });
        if (count === 0) return { path: read.path, replaced: 0 };
        await vaults.writeText(read.path, next, args.vault, { overwrite: true });
        return { path: read.path, replaced: count };
      },
    );
  • Input schema for obsidian_replace_in_note: vault (optional), path (required), search string, replace string, regex flag (default false), caseSensitive flag (default false), replaceAll flag (default false).
    {
      vault: vaultArg,
      path: pathArg,
      search: z.string(),
      replace: z.string(),
      regex: z.boolean().optional().default(false),
      caseSensitive: z.boolean().optional().default(false),
      replaceAll: z.boolean().optional().default(false),
    },
  • The escapeRegExp helper function used by the handler to escape the search string for literal (non-regex) mode.
    export function escapeRegExp(value: string): string {
      return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
    }
Behavior2/5

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

Annotations indicate it is not read-only and not destructive. The description adds only 'search and replace' which is already implied by the name. It does not clarify behavior such as whether replaceAll is destructive, what happens if the search string is not found, or any side effects.

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

Conciseness3/5

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

The description is one sentence, which is concise, but it lacks structure and omits important details. It could be longer to include usage guidance and parameter semantics without being verbose.

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

Completeness2/5

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

For a tool with 7 parameters, 3 required, and no output schema, the description is too brief. It does not explain return values, edge cases, or the effect of each parameter option. The presence of annotations reduces the burden somewhat, but the description still falls short.

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

Parameters2/5

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

Schema description coverage is only 29%. The description adds minimal parameter meaning ('literal or regex matching and replaceAll') but does not explain key parameters like caseSensitive, vault, or the behavior when options are used. The schema itself provides descriptions only for vault and path.

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?

The description clearly states the verb 'search and replace', the resource 'inside one note', and key features 'literal or regex matching and replaceAll'. This distinguishes it from siblings like obsidian_append_to_note or obsidian_patch_note.

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

Usage Guidelines2/5

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

The description provides no explicit guidance on when to use this tool versus alternatives. It does not mention exclusions, prerequisites, or compare to similar tools like obsidian_regex_replace.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jagoff/obsidian-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server