search_content
Find notes containing specific text in your Obsidian vault by searching note contents with customizable options for case sensitivity and result limits.
Instructions
Search for notes containing specific text in their content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Text to search for in note contents | |
| caseSensitive | No | Whether search is case-sensitive. Default: false | |
| limit | No | Maximum number of results to return. Default: 20 |
Implementation Reference
- src/index.ts:571-604 (handler)The handler function that implements the search_content tool logic: gets all notes, searches content with regex (case insensitive by default), finds up to 3 matching lines per note, limits results, returns JSON.async function handleSearchContent(args: { query: string; caseSensitive?: boolean; limit?: number; }): Promise<string> { const limit = args.limit ?? 20; const caseSensitive = args.caseSensitive ?? false; const allNotes = await getAllNotes(); const results: { path: string; matches: string[] }[] = []; const regex = new RegExp( args.query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), caseSensitive ? "g" : "gi" ); for (const notePath of allNotes) { if (results.length >= limit) break; const fullPath = path.join(VAULT_PATH, notePath); const content = await fs.readFile(fullPath, "utf-8"); if (regex.test(content)) { // Find matching lines const lines = content.split("\n"); const matchingLines = lines .filter((line) => regex.test(line)) .slice(0, 3); results.push({ path: notePath, matches: matchingLines }); } } return JSON.stringify(results, null, 2); }
- src/index.ts:184-205 (schema)The input schema definition for the search_content tool, specifying query (required), caseSensitive, and limit parameters.name: "search_content", description: "Search for notes containing specific text in their content", inputSchema: { type: "object", properties: { query: { type: "string", description: "Text to search for in note contents", }, caseSensitive: { type: "boolean", description: "Whether search is case-sensitive. Default: false", default: false, }, limit: { type: "number", description: "Maximum number of results to return. Default: 20", default: 20, }, }, required: ["query"], },
- src/index.ts:901-905 (registration)The switch case in the main tool dispatcher that registers and calls the handleSearchContent handler for the "search_content" tool.case "search_content": result = await handleSearchContent( args as { query: string; caseSensitive?: boolean; limit?: number } ); break;