search_documents
Find the most relevant passages across many documents using keyword ranking or grep-style regex matching, returning ranked snippets with hit markers instead of whole files.
Instructions
Search a corpus of documents and return ranked snippets.
Instead of returning whole files, this tool returns the most relevant passages (with hit spans wrapped in << >> markers), so an agent can locate information across many documents cheaply.
Modes:
keyword: BM25 relevance ranking (requires the optional rank-bm25 dependency). Best for "find the most relevant passages" queries.
grep: literal/regex line matching. Best for "find every occurrence of X". Stateless, no extra dependencies.
Supports all formats the read tool supports (PDF, DOCX, HTML, etc.); files are converted to text before searching.
Returns a dictionary with:
results: list of {snippet, score, document_path, section_heading, chunk_id}
mode: the search mode used
total: number of results returned
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | Search mode: 'keyword' (default, BM25 relevance ranking) or 'grep' (literal/regex line matching). | keyword |
| paths | No | Files, directories, or globs to search (each must be within the read allowlist). If omitted, the server's read allowlist is searched. | |
| query | Yes | Search query. Natural language for keyword mode; a literal string (or regex) for grep mode. REQUIRED. | |
| regex | No | Treat the query as a regular expression (grep mode only). Default: false. | |
| top_k | No | Maximum number of results to return (default: 10). | |
| recursive | No | Recurse into directories when collecting input files. Default: true. | |
| ignore_case | No | Case-insensitive matching (grep mode only). Default: false. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||