Skip to main content
Glama
jagoff

obsidian-mcp-complete

by jagoff

obsidian_search

Read-only

Search notes by text or regex with ranked snippets and optional tag and folder filters.

Instructions

Search notes by text or regex. Returns ranked snippets and supports tag and folder filters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vaultNoOptional configured vault name. Defaults to the server default vault.
queryNo
tagNo
pathPrefixNo
regexNo
caseSensitiveNo
includeContentNo
contextCharsNo
limitNo
offsetNo

Implementation Reference

  • src/tools.ts:38-60 (registration)
    The registerObsidianTools function that registers all Obsidian tools, including obsidian_search, onto the MCP server.
    export function registerObsidianTools(server: McpServer, vaults: VaultManager, config: ObsidianMcpConfig): void {
      vaults.onInvalidate = invalidateNotesCache;
      const pretty = config.pretty;
      const tool = <S extends ToolShape>(
        name: string,
        description: string,
        schema: S,
        handler: (args: z.objectOutputType<S, z.ZodTypeAny>) => Promise<unknown> | unknown,
        annotations: { readOnlyHint?: boolean; destructiveHint?: boolean; idempotentHint?: boolean } = {},
      ) => {
        (server.tool as any)(
          name,
          description,
          schema,
          {
            readOnlyHint: annotations.readOnlyHint ?? false,
            destructiveHint: annotations.destructiveHint ?? false,
            idempotentHint: annotations.idempotentHint ?? false,
            openWorldHint: false,
          },
          async (args: unknown) => jsonResult(await handler(args as z.objectOutputType<S, z.ZodTypeAny>), pretty),
        );
      };
  • Zod schema for the obsidian_search tool: defines inputs like vault, query, tag, pathPrefix, regex, caseSensitive, includeContent, contextChars, limit, offset.
    tool(
      "obsidian_search",
      "Search notes by text or regex. Returns ranked snippets and supports tag and folder filters.",
      {
        vault: vaultArg,
        query: z.string().default(""),
        tag: z.string().optional(),
        pathPrefix: z.string().optional(),
        regex: z.boolean().optional().default(false),
        caseSensitive: z.boolean().optional().default(false),
        includeContent: z.boolean().optional().default(false),
        contextChars: z.number().int().min(20).max(2000).optional().default(160),
        limit: z.number().int().min(1).max(500).optional(),
        offset: z.number().int().min(0).optional().default(0),
      },
  • Handler function for obsidian_search: loads notes, applies search/filter logic via searchNotes(), paginates results with limit/offset.
      async (args) => {
        const notes = await loadNotes(vaults, args.vault);
        const pageLimit = Math.min(args.limit ?? config.maxSearchResults, config.maxSearchResults);
        const all = searchNotes(notes, { ...args, limit: args.offset + pageLimit });
        return { total: all.length, offset: args.offset, hits: all.slice(args.offset, args.offset + pageLimit) };
      },
      { readOnlyHint: true },
    );
  • loadNotes() helper: caches and loads all markdown notes from a vault, used by the obsidian_search handler.
    export async function loadNotes(vaults: VaultManager, vault?: string | null): Promise<NoteRecord[]> {
      const vaultName = vaults.getVault(vault).name;
      const cached = notesCache.get(vaultName);
      if (cached && Date.now() - cached.timestamp < NOTES_CACHE_TTL) return cached.notes;
      const files = await vaults.markdownFiles(vault);
      const records: NoteRecord[] = [];
      for (const file of files) {
        const read = await vaults.readText(file, vault);
        const parsed = parseFrontmatter(read.text);
        records.push({
          path: read.path,
          title: titleFor(read.path, read.text, parsed.data),
          content: read.text,
          frontmatter: parsed.data,
          tags: extractAllTags(read.text),
          headings: extractHeadings(read.text),
          mtime: read.stat.mtime.toISOString(),
          size: read.stat.size,
        });
      }
      notesCache.set(vaultName, { notes: records, timestamp: Date.now() });
      return records;
    }
  • searchNotes() helper: filters notes by tag/pathPrefix, builds matcher for regex or tokenized text search, returns ranked SearchHit results with snippets.
    export function searchNotes(
      notes: NoteRecord[],
      options: {
        query: string;
        limit: number;
        contextChars: number;
        caseSensitive?: boolean;
        regex?: boolean;
        tag?: string;
        pathPrefix?: string;
        includeContent?: boolean;
      },
    ): SearchHit[] {
      const tag = options.tag?.replace(/^#/, "").toLowerCase();
      const prefix = options.pathPrefix?.replace(/^\/+/, "").toLowerCase();
      const filtered = notes.filter((note) => {
        if (tag && !note.tags.some((t) => t.toLowerCase() === tag || t.toLowerCase().startsWith(`${tag}/`))) return false;
        if (prefix && !note.path.toLowerCase().startsWith(prefix)) return false;
        return true;
      });
      const query = options.query.trim();
      if (!query && tag) {
        return filtered.slice(0, options.limit).map((note) => ({
          path: note.path,
          title: note.title,
          score: 1,
          matches: 1,
          tags: note.tags,
          snippet: note.content.slice(0, options.contextChars * 2),
          mtime: note.mtime,
        }));
      }
      const matcher = buildMatcher(query, options);
      const hits: SearchHit[] = [];
      for (const note of filtered) {
        const result = matcher(note);
        if (!result) continue;
        hits.push({
          path: note.path,
          title: note.title,
          score: result.score,
          matches: result.matches,
          tags: note.tags,
          snippet: options.includeContent ? note.content : result.snippet,
          mtime: note.mtime,
        });
      }
      return hits.sort((a, b) => b.score - a.score || b.matches - a.matches || a.path.localeCompare(b.path)).slice(0, options.limit);
    }
Behavior4/5

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

Annotations already mark it as read-only and non-destructive. The description adds that results are 'ranked snippets' and supports filtering, providing behavioral context beyond annotations. No contradiction.

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

Conciseness5/5

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

The description is a single concise sentence that front-loads the core action and key features. Every word adds value.

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?

With 10 parameters and no output schema, the description is too brief. It does not explain ranked snippets behavior, pagination (limit/offset), or parameter interactions like regex flag.

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

Parameters3/5

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

Schema coverage is low (10%). The description adds meaning for query (text/regex), tag, and folder filters, but does not cover parameters like caseSensitive, includeContent, contextChars, etc. Partially compensates.

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 tool searches notes by text or regex, returns ranked snippets, and supports tag and folder filters. This differentiates it from sibling search tools like obsidian_search_dataview or obsidian_search_paths.

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

Usage Guidelines3/5

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

The description implies usage for text/regex search with filters, but does not explicitly contrast with other search tools or specify when to use this over alternatives like smart_search or dataview.

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