Skip to main content
Glama

search_notes

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

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 handler logic for searching notes within a vault.
    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);
    }
  • Tool registration for 'search_notes' and its tool call handler.
    server.registerTool(
      "search_notes",
      {
        description: "Full-text search across all notes in the vault",
        inputSchema: {
          query: z.string().describe("Search query string"),
          caseSensitive: z
            .boolean()
            .optional()
            .default(false)
            .describe("Whether the search should be case sensitive"),
          maxResults: z
            .number()
            .optional()
            .default(20)
            .describe("Maximum number of results to return"),
          folder: z
            .string()
            .optional()
            .describe("Limit search to a specific folder"),
        },
      },
      async ({ query, caseSensitive, maxResults, folder }) => {
        try {
          const results = await searchNotes(vaultPath, query, {
            caseSensitive,
            maxResults,
            folder,
          });
    
          if (results.length === 0) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: `No results found for "${query}"`,
                },
              ],
            };
          }
    
          const lines: string[] = [
            `Found ${results.length} result(s) for "${query}":`,
            "",
          ];
    
          for (const result of results) {
            lines.push(`## ${result.relativePath}`);
            for (const match of result.matches) {
              lines.push(`  Line ${match.line}: ${match.content}`);
            }
            lines.push("");
          }
    
          return {
            content: [{ type: "text" as const, text: lines.join("\n") }],
          };
        } catch (err) {
          console.error("search_notes error:", err);
          return errorResult(`Error searching notes: ${err instanceof Error ? err.message : String(err)}`);
        }
      },
    );
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'full-text search' but doesn't explain what that entails (e.g., tokenization, stemming, ranking), whether it's read-only, what permissions are needed, or how results are structured. This leaves significant gaps for a search operation.

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, efficient sentence that gets straight to the point with no wasted words. It's appropriately sized and front-loaded with the core functionality.

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 search tool with 4 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain the return format, result ordering, pagination behavior, or error conditions. Given the complexity and lack of structured data, more context is needed.

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 description coverage is 100%, so the schema already documents all parameters thoroughly. The description doesn't add any additional meaning about parameters beyond implying a 'query' is needed. This meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('full-text search') and target resource ('across all notes in the vault'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'search_by_frontmatter' or 'search_by_tag', which would require a more specific comparison.

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?

No guidance is provided on when to use this tool versus alternatives like 'search_by_frontmatter' or 'search_by_tag'. The description only states what it does, not when it's appropriate or when other tools might be better suited.

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

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