Skip to main content
Glama

Search Content

search_text
Read-onlyIdempotent

Search file contents for literal text or an RE2 regex to find files and lines containing specific text.

Instructions

Search file contents under the roots for literal text or an RE2 regex. Use when you need the files and lines that contain some text. Do not use it to find files by name; use find_files instead. A regex may span lines; the hit is on its first line. Skips hidden entries, .gitignore matches, and build folders unless includeHidden or includeIgnored. Lines over 1000 chars are clipped around the match. Stops early at 10000 matching lines or the timeout, setting stoppedReason. Returns root, file:line: text rows (a named file prints its path once), matches with column and context, totals, and skip counts. A multi-page or stopped first page also returns nextCursor, valid about 5 min after its last page, and resourceUri, valid about 60 s.

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": {
      "searchPattern": "<searchPattern>"
    },
    "name": "search_text"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathNoFile or directory to search (default: the only root). A named file is searched alone: pattern, maxDepth, and hidden/ignored filtering do not apply. Result paths are relative to the root, not to path.
cursorNoOpaque pagination cursor. Pass it unchanged for the next page. Pages come from one snapshot taken on the first call. It lasts 5 min past its last page; on refusal, retry without it.
contextNoLines shown before and after each match, like grep -C.
excludeNoGlobs for entries to leave out, with everything under a matching folder. Without / a pattern matches a name at any depth (vendor, *.test.ts); with / it matches the path relative to path.
isRegexNoTreat searchPattern as an RE2 regex
patternNoGlob limiting which files are searched: *.ts matches names at any depth, src/**/*.ts matches paths relative to path. Default: all files.
maxDepthNoMax directory depth. 0 scans only the base directory. Omit for no limit.
maxResultsNoMatching lines per page; context lines do not count. Later pages come via cursor.
caseSensitiveNoMatch case exactly. replace_text matches case by default, so pass true to preview what it will replace.
includeHiddenNoInclude hidden items (starting with .)
searchPatternYesText to find, literal unless isRegex is true. RE2 has no lookahead, lookbehind, or backreferences.
includeIgnoredNoInclude ignored items (node_modules, .git, etc).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv2.22.0
    • changedInput schema / properties / cursor / description
      Previous value: -"Opaque pagination cursor. Pass it unchanged for the next page. Pages come from one snapshot taken on the first call. It expires after ~60s; if rejected, retry without a cursor."New value: +"Opaque pagination cursor. Pass it unchanged for the next page. Pages come from one snapshot taken on the first call. It lasts 5 min past its last page; on refusal, retry without it."
    • addedInput schema / properties / exclude
      Added value: +{
      +  "description": "Globs for entries to leave out, with everything under a matching folder. Without / a pattern matches a name at any depth (vendor, *.test.ts); with / it matches the path relative to path.",
      +  "items": {
      +    "description": "Relative glob pattern under the search root (e.g. \"**/*.ts\", \"src/**/*.js\").",
      +    "examples": [
      +      "**/*.ts",
      +      "src/**/*.js",
      +      "**/*.{ts,tsx}"
      +    ],
      +    "maxLength": 1000,
      +    "minLength": 1,
      +    "type": "string"
      +  },
      +  "maxItems": 20,
      +  "minItems": 1,
      +  "type": "array"
      +}
  2. Changed9 schema fields changedv2.20.0
    • changedInput schema / properties / caseSensitive / description
      Previous value: -"Enable case-sensitive matching (default: case-insensitive). Replacements match case by default, so matches found here can go unreplaced there."New value: +"Match case exactly. replace_text matches case by default, so pass true to preview what it will replace."
    • changedInput schema / properties / context / description
      Previous value: -"Lines of context to return either side of each match, like grep -C (default: 0, max: 10)"New value: +"Lines shown before and after each match, like grep -C."
    • changedInput schema / properties / cursor / description
      Previous value: -"Opaque pagination cursor; pass unchanged for the next page. Pages slice one snapshot taken on the first call; it expires after ~60s — re-request without a cursor if rejected."New value: +"Opaque pagination cursor. Pass it unchanged for the next page. Pages come from one snapshot taken on the first call. It expires after ~60s; if rejected, retry without a cursor."
    • changedInput schema / properties / isRegex / description
      Previous value: -"Treat searchPattern as a regex (default: literal text match)"New value: +"Treat searchPattern as an RE2 regex"
    • changedInput schema / properties / maxDepth / description
      Previous value: -"Max directory depth to scan; 0 = base directory only, omit for unlimited"New value: +"Max directory depth. 0 scans only the base directory. Omit for no limit."
    • changedInput schema / properties / maxResults / description
      Previous value: -"Maximum number of matching lines to return per page"New value: +"Matching lines per page; context lines do not count. Later pages come via cursor."
    • changedInput schema / properties / path / description
      Previous value: -"File to search, or directory to search under (default: the only root). Naming a file searches that file alone: pattern is ignored and hidden/ignored filtering does not apply."New value: +"File or directory to search (default: the only root). A named file is searched alone: pattern, maxDepth, and hidden/ignored filtering do not apply. Result paths are relative to the root, not to path."
    • changedInput schema / properties / pattern / description
      Previous value: -"Glob to restrict search to specific file types (e.g. **/*.ts); default: all text files"New value: +"Glob limiting which files are searched: *.ts matches names at any depth, src/**/*.ts matches paths relative to path. Default: all files."
    • changedInput schema / properties / searchPattern / description
      Previous value: -"Exact literal text or RE2 regex pattern to search for in file contents. When isRegex=true, uses RE2 syntax (no lookahead, lookbehind, or backreferences). Cannot be empty or whitespace-only."New value: +"Text to find, literal unless isRegex is true. RE2 has no lookahead, lookbehind, or backreferences."
  3. Changed1 schema field changedv2.18.2
    • changedInput schema / properties / caseSensitive / description
      Previous value: -"Enable case-sensitive matching (default: case-insensitive)"New value: +"Enable case-sensitive matching (default: case-insensitive). Replacements match case by default, so matches found here can go unreplaced there."
  4. Changed1 schema field changedv2.17.0
    • changedInput schema / properties / path / description
      Previous value: -"File to search, or directory to search under (default: the whole first allowed root). Naming a file searches that file alone: pattern is ignored and hidden/ignored filtering does not apply."New value: +"File to search, or directory to search under (default: the only root). Naming a file searches that file alone: pattern is ignored and hidden/ignored filtering does not apply."
  5. Changed1 schema field changedv2.8.1
    • removedInput schema / properties / searchPattern / examples
      Removed value: -[
      -  "TODO",
      -  "function\\s+(\\w+)",
      -  "import.*from"
      -]
  6. Changed1 schema field changedv2.5.0
    • changedInput schema / properties / pattern / examples
      Previous value: -[
      -  "**/*.ts",
      -  "src/**/*.js",
      -  "*.{ts,tsx}"
      -]New value: +[
      +  "**/*.ts",
      +  "src/**/*.js",
      +  "**/*.{ts,tsx}"
      +]
  7. Changed3 schema fields changedv2.4.1
    • addedInput schema / $schema
      Added value: +"https://json-schema.org/draft/2020-12/schema"
    • addedInput schema / properties / pattern / examples
      Added value: +[
      +  "**/*.ts",
      +  "src/**/*.js",
      +  "*.{ts,tsx}"
      +]
    • addedInput schema / properties / searchPattern / examples
      Added value: +[
      +  "TODO",
      +  "function\\s+(\\w+)",
      +  "import.*from"
      +]
  8. Changed1 schema field changedv2.3.0
    • addedInput schema / properties / context
      Added value: +{
      +  "default": 0,
      +  "description": "Lines of context to return either side of each match, like grep -C (default: 0, max: 10)",
      +  "maximum": 10,
      +  "minimum": 0,
      +  "type": "integer"
      +}
  9. Addedv2.0.0

TDQS

A4.6/5.0
Behavior5/5

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

Annotations already cover safety (readOnly, idempotent, non-destructive, closed-world), yet the description goes well beyond them: default skip rules for hidden entries, .gitignore matches and build folders, line clipping at 1000 chars, early termination at 10000 matching lines or the timeout with `stoppedReason`, and the differing lifetimes of `nextCursor` (~5 min past its last page) and `resourceUri` (~60 s). These are decision-relevant traits an agent could not infer from structured fields.

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?

The text is front-loaded: purpose first, then the sibling exclusion, then the behavioral caveats about filtering, clipping and pagination. Sentences are dense but each carries a distinct fact; the only mild redundancy is the fairly long recounting of the return shape, which is nonetheless necessary since no output schema exists.

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?

For a 12-parameter tool with no output schema, the description fills the gaps an agent needs: filtering defaults, truncation and stopping behavior, pagination semantics with expiry windows, and the shape of returned rows, matches, totals and skip counts. Nothing required to call it correctly or interpret results is left to inference.

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 every one of the 12 parameters is already documented in the schema, including defaults, bounds and glob semantics; baseline is 3. The description adds a little meaning not in the schema, notably that a regex may span lines while the hit is reported on its first line, and that a named file prints its path once, but most parameter behavior is already in the structured data rather than newly contributed.

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 file contents under the roots') plus the matching mode ('literal text or an RE2 regex'), which tells an agent exactly what the tool returns: files and lines containing text. It explicitly distinguishes itself from `find_files` for name-based lookup, so the boundary with the closest sibling is unambiguous.

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?

Usage is stated positively ('use when you need the files and lines that contain some text') and negatively ('Do not use it to find files by name; use `find_files` instead'), naming the alternative and the condition that selects it. It also flags a cross-tool interaction by noting `replace_text` matches case by default so `caseSensitive: true` previews what a replacement will hit.

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