Skip to main content
Glama
sureshsankaran

Obsidian Tools MCP Server

search_notes

Find notes in your Obsidian vault using partial names or regex patterns to locate specific information quickly.

Instructions

Search for notes by name pattern (case-insensitive, supports regex)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query - can be a partial name or regex pattern
limitNoMaximum number of results to return. Default: 20

Implementation Reference

  • The handler function that implements the core logic of the 'search_notes' tool. It retrieves all note paths using getAllNotes, creates a case-insensitive regex from the query (handling invalid regex by escaping), filters matching notes, limits results, and returns a JSON string of matching paths.
    async function handleSearchNotes(args: {
      query: string;
      limit?: number;
    }): Promise<string> {
      const limit = args.limit ?? 20;
      const allNotes = await getAllNotes();
    
      let regex: RegExp;
      try {
        regex = new RegExp(args.query, "i");
      } catch {
        regex = new RegExp(args.query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
      }
    
      const matches = allNotes.filter((note) => regex.test(note)).slice(0, limit);
    
      return JSON.stringify(matches, null, 2);
    }
  • The input schema defining the parameters for the 'search_notes' tool: a required 'query' string and optional 'limit' number.
    inputSchema: {
      type: "object",
      properties: {
        query: {
          type: "string",
          description: "Search query - can be a partial name or regex pattern",
        },
        limit: {
          type: "number",
          description: "Maximum number of results to return. Default: 20",
          default: 20,
        },
      },
      required: ["query"],
  • src/index.ts:163-182 (registration)
    The registration of the 'search_notes' tool in the tools array, which is returned by the ListToolsRequestSchema handler. Includes name, description, and inputSchema.
    {
      name: "search_notes",
      description:
        "Search for notes by name pattern (case-insensitive, supports regex)",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query - can be a partial name or regex pattern",
          },
          limit: {
            type: "number",
            description: "Maximum number of results to return. Default: 20",
            default: 20,
          },
        },
        required: ["query"],
      },
    },
  • src/index.ts:896-900 (registration)
    The dispatch case in the CallToolRequestSchema handler that routes calls to 'search_notes' to the handleSearchNotes function.
    case "search_notes":
      result = await handleSearchNotes(
        args as { query: string; limit?: number }
      );
      break;
  • Helper function used by handleSearchNotes to recursively collect all .md note paths relative to the vault root.
    async function getAllNotes(dir: string = VAULT_PATH): Promise<string[]> {
      const notes: string[] = [];
      const entries = await fs.readdir(dir, { withFileTypes: true });
    
      for (const entry of entries) {
        const fullPath = path.join(dir, entry.name);
        if (entry.isDirectory() && !entry.name.startsWith(".")) {
          notes.push(...(await getAllNotes(fullPath)));
        } else if (entry.isFile() && entry.name.endsWith(".md")) {
          notes.push(path.relative(VAULT_PATH, fullPath));
        }
      }
    
      return notes;
    }

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/sureshsankaran/obsidian-tools-mcp'

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