Skip to main content
Glama

Grep

grep

Search cached files for exact strings or regex patterns, returning line-numbered matches with optional path and limit filters.

Instructions

Search cached file contents for an exact string or regex.

Fast, exact, line-numbered matching over files already in the cache — it does NOT touch disk, so index files first with warm, which costs a few dozen tokens however many files it covers (empty results usually mean the files aren't cached). A pattern that is not a valid regex is an error, never an empty result, so zero matches always means zero matches. For concept-level questions where you don't know the exact term, use search instead.

Counts are complete unless the response says otherwise: if a cap stops the scan, complete comes back false with limit_reached naming which one, so total_matches is never mistaken for the total that exists.

Each file's hits come back as "<line>:<text>" strings under lines, with context lines using - instead of :. Paths are relative to the root the response names, when there is one worth naming. The cache is shared across projects, so a relative path — or none — searches only the current project; an absolute path reaches files anywhere.

A repeated group wrapping an unbounded quantifier ((a+)+) is rejected rather than run — it can take exponential time and cannot be interrupted once started. Drop the redundant repeat, or pass fixed_string=true.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoOptional filter — an exact path, a path suffix, a directory (matching every cached file beneath it), or a glob.
outputNoHow much to return — `matches` (default), `paths` for the matching files without their lines, or `count` for the totals alone.matches
patternYesA regular expression, or a literal string when `fixed_string=true`.
max_filesNoCap on the number of files returned.
max_matchesNoCap on total matches returned across all files.
fixed_stringNoMatch `pattern` literally instead of as a regex.
context_linesNoLines of surrounding context to include around each match. Overlapping windows are merged, so no line is sent twice.
case_sensitiveNoMatch case-sensitively.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv0.6.0
    • changedInput schema / properties / context_lines / description
      Previous value: -"Lines of surrounding context to include per match."New value: +"Lines of surrounding context to include around each\nmatch. Overlapping windows are merged, so no line is sent twice."
    • addedInput schema / properties / output
      Added value: +{
      +  "default": "matches",
      +  "description": "How much to return — `matches` (default), `paths` for the\nmatching files without their lines, or `count` for the totals\nalone.",
      +  "type": "string"
      +}
    • changedInput schema / properties / path / description
      Previous value: -"Optional filter — an exact path, a path suffix, or a glob."New value: +"Optional filter — an exact path, a path suffix, a directory\n(matching every cached file beneath it), or a glob."
    • changedOutput schema / (root)
      Previous value: -{
      -  "properties": {
      -    "case_sensitive": {
      -      "anyOf": [
      -        {
      -          "type": "boolean"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Case Sensitive"
      -    },
      -    "context_lines": {
      -      "anyOf": [
      -        {
      -          "type": "integer"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Context Lines"
      -    },
      -    "files": {
      -      "anyOf": [
      -        {
      -          "items": {
      -            "properties": {
      -              "count": {
      -                "anyOf": [
      -                  {
      -                    "type": "integer"
      -                  },
      -                  {
      -                    "type": "null"
      -                  }
      -                ],
      -                "default": null,
      -                "title": "Count"
      -              },
      -              "matches": {
      -                "anyOf": [
      -                  {
      -                    "items": {
      -                      "properties": {
      -                        "after": {
      -                          "anyOf": [
      -                            {
      -                              "items": {
      -                                "type": "string"
      -                              },
      -                              "type": "array"
      -                            },
      -                            {
      -                              "type": "null"
      -                            }
      -                          ],
      -                          "default": null,
      -                          "title": "After"
      -                        },
      -                        "before": {
      -                          "anyOf": [
      -                            {
      -                              "items": {
      -                                "type": "string"
      -                              },
      -                              "type": "array"
      -                            },
      -                            {
      -                              "type": "null"
      -                            }
      -                          ],
      -                          "default": null,
      -                          "title": "Before"
      -                        },
      -                        "line": {
      -                          "anyOf": [
      -                            {
      -                              "type": "string"
      -                            },
      -                            {
      -                              "type": "null"
      -                            }
      -                          ],
      -                          "default": null,
      -                          "title": "Line"
      -                        },
      -                        "line_number": {
      -                          "anyOf": [
      -                            {
      -                              "type": "integer"
      -                            },
      -                            {
      -                              "type": "null"
      -                            }
      -                          ],
      -                          "default": null,
      -                          "title": "Line Number"
      -                        },
      -                        "truncated": {
      -                          "anyOf": [
      -                            {
      -                              "type": "boolean"
      -                            },
      -                            {
      -                              "type": "null"
      -                            }
      -                          ],
      -                          "default": null,
      -                          "title": "Truncated"
      -                        }
      -                      },
      -                      "title": "GrepMatch",
      -                      "type": "object"
      -                    },
      -                    "type": "array"
      -                  },
      -                  {
      -                    "type": "null"
      -                  }
      -                ],
      -                "default": null,
      -                "title": "Matches"
      -              },
      -              "path": {
      -                "anyOf": [
      -                  {
      -                    "type": "string"
      -                  },
      -                  {
      -                    "type": "null"
      -                  }
      -                ],
      -                "default": null,
      -                "title": "Path"
      -              },
      -              "truncated": {
      -                "anyOf": [
      -                  {
      -                    "type": "boolean"
      -                  },
      -                  {
      -                    "type": "null"
      -                  }
      -                ],
      -                "default": null,
      -                "title": "Truncated"
      -              }
      -            },
      -            "title": "GrepFile",
      -            "type": "object"
      -          },
      -          "type": "array"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Files"
      -    },
      -    "files_matched": {
      -      "anyOf": [
      -        {
      -          "type": "integer"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Files Matched"
      -    },
      -    "fixed_string": {
      -      "anyOf": [
      -        {
      -          "type": "boolean"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Fixed String"
      -    },
      -    "path": {
      -      "anyOf": [
      -        {
      -          "type": "string"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Path"
      -    },
      -    "pattern": {
      -      "anyOf": [
      -        {
      -          "type": "string"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Pattern"
      -    },
      -    "total_matches": {
      -      "anyOf": [
      -        {
      -          "type": "integer"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Total Matches"
      -    },
      -    "truncated": {
      -      "anyOf": [
      -        {
      -          "type": "boolean"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Truncated"
      -    },
      -    "truncated_files": {
      -      "anyOf": [
      -        {
      -          "type": "integer"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Truncated Files"
      -    },
      -    "truncated_matches": {
      -      "anyOf": [
      -        {
      -          "type": "integer"
      -        },
      -        {
      -          "type": "null"
      -        }
      -      ],
      -      "default": null,
      -      "title": "Truncated Matches"
      -    }
      -  },
      -  "title": "GrepResponse",
      -  "type": "object"
      -}New value: +null
  2. Changed7 schema fields changedv0.5.1
    • addedInput schema / properties / case_sensitive / description
      Added value: +"Match case-sensitively."
    • addedInput schema / properties / context_lines / description
      Added value: +"Lines of surrounding context to include per match."
    • addedInput schema / properties / fixed_string / description
      Added value: +"Match `pattern` literally instead of as a regex."
    • addedInput schema / properties / max_files / description
      Added value: +"Cap on the number of files returned."
    • addedInput schema / properties / max_matches / description
      Added value: +"Cap on total matches returned across all files."
    • addedInput schema / properties / path / description
      Added value: +"Optional filter — an exact path, a path suffix, or a glob."
    • addedInput schema / properties / pattern / description
      Added value: +"A regular expression, or a literal string when\n`fixed_string=true`."
  3. Changed2 schema fields changedv0.4.8
    • addedOutput schema / properties / truncated_files
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "integer"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "title": "Truncated Files"
      +}
    • addedOutput schema / properties / truncated_matches
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "integer"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ],
      +  "default": null,
      +  "title": "Truncated Matches"
      +}
  4. Addedv0.4.5

TDQS

A5/5.0
Behavior5/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It explains that the tool does not touch disk, that invalid regexes are errors rather than empty results, that capped results are reported via `complete` and `limit_reached`, and that catastrophic regex patterns are rejected to avoid hangs. This is exceptionally thorough.

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

Conciseness5/5

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

The description is long but every paragraph earns its place: cache behavior, error semantics, alternative tool routing, output format, path scoping, and security-related regex rejection are all covered without redundancy. The first sentence immediately states the primary purpose, and subsequent paragraphs are logically organized.

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

Completeness5/5

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

Given that there is no output schema and no annotations, the description compensates fully by explaining the response structure (`lines`, `"<line>:<text>"`, context lines using `-`), completeness guarantees, error behavior, path semantics, and the need for pre-warming. An agent has everything necessary to invoke this tool correctly.

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

Parameters5/5

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

Schema coverage is 100%, so the baseline is already strong, but the description adds substantial meaning: the line-numbered output format, the distinction between relative and absolute `path` with respect to the shared cache, the semantics of `fixed_string`, and the behavior of caps. It goes well beyond simply restating schema fields.

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?

The description opens with a specific verb and resource: 'Search cached file contents for an exact string or regex.' It then reinforces the tool's identity with 'Fast, exact, line-numbered matching over files already in the cache' and explicitly contrasts itself with the sibling `search`, so an agent can distinguish grep from related tools.

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

Usage Guidelines5/5

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

The description gives concrete usage conditions: it only works over cached files, so it directs the agent to first index with `warm`; it advises using `search` for concept-level questions where the exact term is unknown; and it even explains path-scoping behavior for current vs. other projects. This is explicit when-to-use and when-not-to-use guidance.

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