Skip to main content
Glama

grep

Find lines matching a regex in files or directories. Auto-detects encoding, supports recursive search, context lines, and multiple output modes.

Instructions

Searches file contents for a regex pattern. Encoding-aware: auto-detects file encoding. Can search a single file or recursively search a directory. Output modes: content (default), files_with_matches, count. Compact content groups matches under one file header by default; use output_format=classic for path:line:text. A CRLF ending is a terminator, not content: "^foo$" matches in a CRLF file and returned lines carry no stray CR. A lone CR is not a line break (same as read), so a CR-only file is one line. Context: use before/after/context to include surrounding lines (like grep -B/-A/-C). Large result sets stay usable: max_results supports up to 100000, while max_line_chars and max_output_chars bound the text returned to the agent. has_more and a visible continuation hint report when additional grep output exists. Directory search skips binary files (extension list + NUL-byte sniff); pass a binary file directly as path to search it anyway.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
globNoGlob pattern to filter files (e.g. *.go). Only used when path is a directory
pathNoFile or directory to search. Defaults to configured workspace, MCP client root, or current directory
afterNoLines after each match. Overrides context. Default: 0, Max: 1000
beforeNoLines before each match. Overrides context. Default: 0, Max: 1000
cursorNoOpaque continuation cursor returned by a previous grep call. Not supported with context lines
contextNoLines before and after each match (like grep -C). Default: 0, Max: 1000
patternYesRegular expression pattern to search for
file_pathNoAlias for path
recursiveNoRecurse into subdirectories. Default: true
ignore_caseNoCase-insensitive search. Default: false
max_resultsNoMaximum matching lines/files per page. Default: 100, Max: 100000
output_modeNoOutput mode: content (default), files_with_matches, or count
output_formatNoContent layout: compact (group matches by file, default) or classic (path:line:text on every line)
include_hiddenNoSearch hidden directories. Explicitly provided hidden roots are always searched. Default: false
max_line_charsNoMaximum characters per matching/context line. Default: 4000, Max: 32768
relative_pathsNoReturn paths relative to the search root. Default: true for directory searches
include_ignoredNoSearch common generated/vendor directories instead of skipping them. Default: false
max_output_charsNoMaximum total result characters. Default: 32768, Max: 131072

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. Changed21 schema fields changedv0.9.5
    • changedInput schema / properties / after / description
      Previous value: -"Lines of context after each match (like grep -A). Overrides context. Default: 0"New value: +"Lines after each match. Overrides context. Default: 0, Max: 1000"
    • addedInput schema / properties / after / type
      Added value: +"integer"
    • changedInput schema / properties / before / description
      Previous value: -"Lines of context before each match (like grep -B). Overrides context. Default: 0"New value: +"Lines before each match. Overrides context. Default: 0, Max: 1000"
    • addedInput schema / properties / before / type
      Added value: +"integer"
    • changedInput schema / properties / context / description
      Previous value: -"Lines of context before and after each match (like grep -C). Default: 0"New value: +"Lines before and after each match (like grep -C). Default: 0, Max: 1000"
    • addedInput schema / properties / context / type
      Added value: +"integer"
    • addedInput schema / properties / cursor
      Added value: +{
      +  "description": "Opaque continuation cursor returned by a previous grep call. Not supported with context lines",
      +  "type": "string"
      +}
    • changedInput schema / properties / ignore_case / description
      Previous value: -"Case insensitive search: true or false. Default: false"New value: +"Case-insensitive search. Default: false"
    • addedInput schema / properties / ignore_case / type
      Added value: +"boolean"
    • addedInput schema / properties / include_hidden
      Added value: +{
      +  "description": "Search hidden directories. Explicitly provided hidden roots are always searched. Default: false",
      +  "type": "boolean"
      +}
    • addedInput schema / properties / include_ignored
      Added value: +{
      +  "description": "Search common generated/vendor directories instead of skipping them. Default: false",
      +  "type": "boolean"
      +}
    • addedInput schema / properties / max_line_chars
      Added value: +{
      +  "description": "Maximum characters per matching/context line. Default: 4000, Max: 32768",
      +  "type": "integer"
      +}
    • addedInput schema / properties / max_output_chars
      Added value: +{
      +  "description": "Maximum total result characters. Default: 32768, Max: 131072",
      +  "type": "integer"
      +}
    • changedInput schema / properties / max_results / description
      Previous value: -"Maximum number of matching lines/files to return. Default: 100"New value: +"Maximum matching lines/files per page. Default: 100, Max: 100000"
    • addedInput schema / properties / max_results / type
      Added value: +"integer"
    • addedInput schema / properties / output_format
      Added value: +{
      +  "description": "Content layout: compact (group matches by file, default) or classic (path:line:text on every line)",
      +  "type": "string"
      +}
    • changedInput schema / properties / output_mode / description
      Previous value: -"Output mode: 'content' (matching lines with path:line:text, default), 'files_with_matches' (file paths only), 'count' (match count per file)"New value: +"Output mode: content (default), files_with_matches, or count"
    • changedInput schema / properties / path / description
      Previous value: -"File or directory to search in (absolute path). Defaults to current directory"New value: +"File or directory to search. Defaults to configured workspace, MCP client root, or current directory"
    • changedInput schema / properties / recursive / description
      Previous value: -"Recurse into subdirectories: true or false. Default: true"New value: +"Recurse into subdirectories. Default: true"
    • addedInput schema / properties / recursive / type
      Added value: +[
      +  "null",
      +  "boolean"
      +]
    • addedInput schema / properties / relative_paths
      Added value: +{
      +  "description": "Return paths relative to the search root. Default: true for directory searches",
      +  "type": [
      +    "null",
      +    "boolean"
      +  ]
      +}
  2. Addedv0.8.7
  3. Removed
  4. Changed6 schema fields changedv0.7.12
    • addedInput schema / properties / after
      Added value: +{
      +  "description": "Lines of context after each match (like grep -A). Overrides context. Default: 0",
      +  "type": "integer"
      +}
    • addedInput schema / properties / before
      Added value: +{
      +  "description": "Lines of context before each match (like grep -B). Overrides context. Default: 0",
      +  "type": "integer"
      +}
    • addedInput schema / properties / context
      Added value: +{
      +  "description": "Lines of context before and after each match (like grep -C). Default: 0",
      +  "type": "integer"
      +}
    • changedInput schema / properties / max_results / description
      Previous value: -"Maximum number of matching lines to return. Default: 100"New value: +"Maximum number of matching lines/files to return. Default: 100"
    • addedInput schema / properties / output_mode
      Added value: +{
      +  "description": "Output mode: 'content' (matching lines with path:line:text, default), 'files_with_matches' (file paths only), 'count' (match count per file)",
      +  "type": "string"
      +}
    • changedOutput schema / (root)
      Previous value: -{
      -  "additionalProperties": false,
      -  "properties": {
      -    "count": {
      -      "type": "integer"
      -    },
      -    "matches": {
      -      "items": {
      -        "type": "string"
      -      },
      -      "type": [
      -        "null",
      -        "array"
      -      ]
      -    }
      -  },
      -  "required": [
      -    "matches",
      -    "count"
      -  ],
      -  "type": "object"
      -}New value: +null
  5. First observedv0.4.2

TDQS

A4.7/5.0
Behavior5/5

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

With no annotations supplied, the description fully carries the behavioral burden and does so thoroughly. It discloses encoding detection, CRLF/CR line-ending semantics, output modes and their defaults, context behavior, binary-file skipping and the exception when passed directly, and large-result continuation behavior through has_more. These are exactly the non-obvious behaviors an agent needs to predict side effects and output.

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 densely packed with useful, non-redundant information. It leads with the main action, then systematically covers output modes, edge cases, context, large results, and binary handling. Every sentence provides behavioral or parameter knowledge that would be hard to discover from the schema alone, earning its place.

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 the 18 parameters, high schema coverage, and no output schema, the description is exceptionally complete. It explains result-limiting and pagination-related behavior (has_more, max_output_chars, continuation), which is crucial for an agent calling a search tool that may return a lot of text. It also covers boundary-case semantics like CRLF and binary files, making the tool surprisingly predictable without an output schema.

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, but the description adds genuinely useful parameter semantics beyond the schema, including 'like grep -B/-A/-C' for context terms, the default compact output format versus output_format=classic, binary-file bypass when path points directly to a file, and the max_results/max_line_chars/max_output_chars caps. This helps agents understand how parameters combine without inspecting JSON examples.

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 the specific verb-resource pair 'Searches file contents for a regex pattern,' which precisely identifies what the tool does and differentiates it from siblings like read, glob, and listdir. It further clarifies scope ('single file or recursively search a directory') and output modes, leaving no ambiguity about the tool's purpose.

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?

The description gives clear context for using the tool: when searching file contents by regex, by file or directory, with context-line behavior, and with binary-file handling. It does not explicitly name alternatives or state 'use this instead of X,' but the purpose is concrete enough that an agent can infer when to select grep over read/glob/listdir. The reference to 'same as read' subtly ties behavior to a sibling tool, adding context.

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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/knewstimek/agent-tool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server