Skip to main content
Glama

search_directory

Read-only

Searches for a text pattern across all files in a directory, returning matches grouped by file with line numbers and context while respecting ignore rules and optional file filters.

Instructions

Search for a text pattern across all files in a directory.

Returns results grouped by file with line numbers and context. Use
include_pattern to filter by file extension (e.g. '*.py'). Automatically
ignores __pycache__, node_modules, and .git, plus nested .gitignore/
.ignore rules. Prefer fuzzy=False (default) for multi-file search
performance.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "absolute_dir_path": "<absolute_dir_path>",
      "pattern": "<pattern>"
    },
    "name": "search_directory"
  }
}

Input Schema

NameRequiredDescriptionDefault
fuzzyNoEnable fuzzy matching (null = false; expensive for many files). Explicit true together with regex=true is ignored and a warning is returned.
regexNoEnable Python regex matching (default: false).
invertNoReturn non-matching lines, like grep -v (default: false).
patternYesText pattern to search for.
max_resultsNoTotal match cap across all files (1-500). Defaults to server config (100).
context_linesNoLines of context before/after each match (default: 2).
case_sensitiveNoCase-sensitive search (default: false).
include_hiddenNoInclude dot-files and dot-dirs (default: false).
include_patternNofnmatch glob matched against file names (default: '*'). Examples: '*.py', '*.md', '*.ts'.*
absolute_dir_pathYesThe absolute path to the directory to search.
respect_gitignoreNoHonor nested .gitignore/.ignore files when filtering files (default: server default, true). Set false to search ignored files too.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed7 schema fields changedv1.0.0
    • addedInput schema / properties / fuzzy / anyOf
      Added value: +[
      +  {
      +    "type": "boolean"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • changedInput schema / properties / fuzzy / default
      Previous value: -falseNew value: +null
    • changedInput schema / properties / fuzzy / description
      Previous value: -"Enable fuzzy matching (default: false, expensive for many files)."New value: +"Enable fuzzy matching (null = false; expensive for many files). Explicit true together with regex=true is ignored and a warning is returned."
    • removedInput schema / properties / fuzzy / type
      Removed value: -"boolean"
    • changedInput schema / properties / max_results / anyOf
      Previous value: -[
      -  {
      -    "maximum": 100,
      -    "minimum": 1,
      -    "type": "integer"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "maximum": 500,
      +    "minimum": 1,
      +    "type": "integer"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • changedInput schema / properties / max_results / description
      Previous value: -"Total match cap across all files. Defaults to server config (100)."New value: +"Total match cap across all files (1-500). Defaults to server config (100)."
    • addedInput schema / properties / respect_gitignore
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "boolean"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "description": "Honor nested .gitignore/.ignore files when filtering files (default: server default, true). Set false to search ignored files too.",
      +  "title": "Respect Gitignore"
      +}
  2. First observedv0.3.0

TDQS

A3.7/5.0
Behavior4/5

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

Annotations already establish readOnlyHint=true and destructiveHint=false, so safety is covered. The description adds genuinely new behavior: a hard-coded default ignore list (__pycache__, node_modules, .git), nested .gitignore/.ignore handling, and a performance warning on fuzzy matching. It does not mention result truncation or the max_results cap, which is the main remaining gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Short, front-loaded with purpose and return format, then filtering then performance. No filler, though the include_pattern example duplicates the schema and the sentences are slightly choppy as an unstructured paragraph.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an 11-parameter read-only search tool with full schema coverage and annotations, the description covers purpose, return shape, ignore behavior, and a performance caveat. Missing only output-volume behavior (truncation at max_results) and binary/large-file handling, which are minor for a search tool.

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 11 parameters thoroughly, including glob examples and the fuzzy/regex interaction. The description mostly restates schema content ('example *.py') and only adds a mild preference hint for fuzzy=False, so baseline 3 applies.

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?

States a specific verb and resource with scope ('Search for a text pattern across all files in a directory') and even sketches the return shape ('results grouped by file with line numbers and context'). It does not explicitly differentiate itself from the sibling search_content, so an agent must infer the directory-wide vs. content distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Offers parameter-level advice ('Use include_pattern to filter by file extension', 'Prefer fuzzy=False for multi-file search performance') but never states when to pick this tool over search_content, find_files, or list_directory. Usage is implied by the tool's scope rather than spelled out.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.