Skip to main content
Glama

grep_files

Search file contents with regex to find matching lines, counts, or filenames, with optional context and filters.

Instructions

Search text patterns within file contents using regex. Returns matching line numbers and context - use with read_file/read_multiple_files to retrieve actual content. Supports: regex patterns, case-insensitive (-i), context lines (-A/-B/-C), file type filters (type: js/py/ts/etc), glob patterns, multiline mode. Output modes: content (lines+context), files_with_matches (paths only), count (match counts). Respects ignored folders. Use head_limit to cap results. Only searches within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
-ANoLines after match
-BNoLines before match
-CNoLines before+after match
-iNoCase insensitive
globNoGlob filter. Without a slash it matches file names at any depth (*.md, *.test.ts); with a slash it matches the path relative to the search root (src/**/*.ts)
pathNoDirectory/file to search (optional)
typeNoFile type filter: js, py, ts, etc
patternYesRegex pattern to search for
multilineNoAllow . to match newlines
head_limitNoLimit results to N
output_modeNocontent|files_with_matches|countcontent

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.3.0
    • changedInput schema / properties / glob / description
      Previous value: -"Glob filter: *.js, **/*.test.ts"New value: +"Glob filter. Without a slash it matches file names at any depth (*.md, *.test.ts); with a slash it matches the path relative to the search root (src/**/*.ts)"
  2. First observedv1.2.14

TDQS

A4.3/5.0
Behavior4/5

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

With no annotations, the description carries the full burden and largely succeeds: it discloses scoping constraints ('Respects ignored folders', 'Only searches within allowed directories'), result capping via head_limit, and the shape of the return (matching line numbers and context). It omits error behavior for invalid regex and any performance/pagination caveats.

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?

Front-loaded with the core action, then organized into capability and output-mode clusters; every sentence is relevant. It is slightly list-like and repeats some schema-level detail, but for an 11-parameter tool the length is justified.

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?

No output schema and no annotations, yet the description covers the return shape (line numbers/context vs. paths vs. counts), the safety scoping (allowed directories, ignored folders), and result limiting. It stops short of covering error cases or search-root defaults, but an agent has enough to invoke it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the baseline is 3; the description adds genuine meaning for output_mode by spelling out what 'content', 'files_with_matches', and 'count' actually yield, which the bare enum values do not. The flags (-i, -A/-B/-C, type, glob, multiline) largely restate schema descriptions rather than extending them.

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

Purpose5/5

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

States a specific verb and resource ('Search text patterns within file contents using regex') and clarifies its role in the workflow by pointing to read_file/read_multiple_files for retrieving content, implicitly distinguishing it from file-name-based tools like glob_files.

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

Usage Guidelines4/5

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

Explicitly tells the agent how this tool pairs with read_file/read_multiple_files ('use with ... to retrieve actual content'), which is real routing guidance. However, it never states when NOT to use it (e.g., use glob_files for locating files by name), so no explicit exclusion is offered.

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