Skip to main content
Glama

search_notes

Search all notes in your Obsidian vault using full-text queries to find relevant information quickly. Filter by folder, adjust case sensitivity, and control result count.

Instructions

Full-text search across all notes in the vault

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query string
caseSensitiveNoWhether the search should be case sensitive
maxResultsNoMaximum number of results to return
folderNoLimit search to a specific folder

Implementation Reference

  • The searchNotes function implementation which iterates over notes and finds matching lines based on a query string.
    export async function searchNotes(
      vaultPath: string,
      query: string,
      options?: {
        caseSensitive?: boolean;
        maxResults?: number;
        folder?: string;
      },
    ): Promise<SearchResult[]> {
      const caseSensitive = options?.caseSensitive ?? false;
      const maxResults = options?.maxResults ?? 100;
    
      const notes = await listNotes(vaultPath, options?.folder);
      const results: SearchResult[] = [];
    
      const searchQuery = caseSensitive ? query : query.toLowerCase();
    
      for (const notePath of notes) {
        if (results.length >= maxResults) break;
    
        let content: string;
        try {
          content = await readNote(vaultPath, notePath);
        } catch {
          console.error(`Failed to read note during search: ${notePath}`);
          continue;
        }
    
        const lines = content.split("\n");
        const matches: SearchMatch[] = [];
    
        for (let i = 0; i < lines.length; i++) {
          const line = lines[i];
          const compareLine = caseSensitive ? line : line.toLowerCase();
          let startIndex = 0;
    
          while (true) {
            const col = compareLine.indexOf(searchQuery, startIndex);
            if (col === -1) break;
    
            matches.push({
              line: i + 1,
              content: line.trim(),
              column: col,
            });
            startIndex = col + searchQuery.length;
          }
        }
    
        if (matches.length > 0) {
          results.push({
            path: resolveVaultPath(vaultPath, notePath),
            relativePath: notePath,
            matches,
            score: matches.length,
          });
        }
      }
    
      // Sort by score descending
      results.sort((a, b) => b.score - a.score);
    
      return results.slice(0, maxResults);
    }

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/rps321321/obsidian-mcp-pro'

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