Skip to main content
Glama
Search Code MCP

Search Code MCP

by joutvhu

Count Matches

count
Read-onlyIdempotent

Tally matching lines or regex, literal, and AST occurrences without returning match content to gauge blast radius and save context tokens before searching or replacing.

Instructions

Count matching lines or occurrences of a regex, literal text, or AST pattern without returning match content. Use before 'search' or 'replace' to gauge blast radius and save context tokens.

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": {
      "query": "<query>"
    },
    "name": "count"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathNoFile or directory to count matches in (relative or absolute; default: '.')..
typeNoCounting engine: 'regex' (default), 'text' (literal), or 'ast' (structural pattern).regex
queryYesPattern to count (regex, literal text, or AST pattern).
perFileNoIf true, returns match counts broken down per file.
languageNo[ast only] Target language (e.g. 'typescript', 'python'). Recommended when 'path' is a directory.
noIgnoreNoIf true, include gitignored files. Default: false.
filePatternNoGlob pattern(s) to include, comma-separated, e.g. '*.{ts,tsx}'.
caseSensitiveNo[regex/text] Force case-sensitive (true) or case-insensitive (false). Omitting uses smart-case (insensitive unless query has uppercase).
includeHiddenNoIf true, include hidden dotfiles and dot-directories (excludes .git unless noIgnore is true). Default: false.
excludePatternNoComma-separated glob patterns to exclude, e.g. '**/dist/**,**/*.spec.ts'.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed12 schema fields changedv1.1.0
    • addedInput schema / properties / caseSensitive
      Added value: +{
      +  "description": "[regex/text] Force case-sensitive (true) or case-insensitive (false). Omitting uses smart-case (insensitive unless query has uppercase).",
      +  "type": "boolean"
      +}
    • removedInput schema / properties / countLines
      Removed value: -{
      -  "default": true,
      -  "description": "Count matching lines (true) or total occurrences (false)",
      -  "type": "boolean"
      -}
    • changedInput schema / properties / excludePattern / description
      Previous value: -"Glob pattern to exclude"New value: +"Comma-separated glob patterns to exclude, e.g. '**/dist/**,**/*.spec.ts'."
    • changedInput schema / properties / filePattern / description
      Previous value: -"Glob pattern to filter files"New value: +"Glob pattern(s) to include, comma-separated, e.g. '*.{ts,tsx}'."
    • removedInput schema / properties / fileType
      Removed value: -{
      -  "description": "File type filter",
      -  "type": "string"
      -}
    • addedInput schema / properties / includeHidden
      Added value: +{
      +  "default": false,
      +  "description": "If true, include hidden dotfiles and dot-directories (excludes .git unless noIgnore is true). Default: false.",
      +  "type": "boolean"
      +}
    • changedInput schema / properties / language / description
      Previous value: -"Language for AST mode"New value: +"[ast only] Target language (e.g. 'typescript', 'python'). Recommended when 'path' is a directory."
    • changedInput schema / properties / noIgnore / description
      Previous value: -"Whether to count inside gitignored files"New value: +"If true, include gitignored files. Default: false."
    • changedInput schema / properties / path / description
      Previous value: -"Directory or file to count matches in. Accepts relative or absolute paths (default: '.')"New value: +"File or directory to count matches in (relative or absolute; default: '.')."
    • changedInput schema / properties / perFile / description
      Previous value: -"If true, shows breakdown of matches per file"New value: +"If true, returns match counts broken down per file."
    • changedInput schema / properties / query / description
      Previous value: -"Search pattern to count"New value: +"Pattern to count (regex, literal text, or AST pattern)."
    • changedInput schema / properties / type / description
      Previous value: -"Engine mode: 'regex' (default), 'text', 'ast'"New value: +"Counting engine: 'regex' (default), 'text' (literal), or 'ast' (structural pattern)."
  2. Changed1 schema field changedv1.0.2
    • changedInput schema / properties / path / description
      Previous value: -"Directory or file to count matches in (default: '.')"New value: +"Directory or file to count matches in. Accepts relative or absolute paths (default: '.')"
  3. First observedv1.0.0

TDQS

A4.2/5.0
Behavior4/5

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

Annotations already declare readOnly, idempotent, non-destructive, and closed-world, so the safety profile is covered. The description adds genuinely useful behavioral context beyond that: no match content is returned and the call is cheap enough to use as a pre-flight check. It does not describe the returned shape (total vs per-file), which would have completed the picture.

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?

Two sentences, zero filler, with the core definition front-loaded and the usage guidance following immediately. Nothing is redundant with the title or schema.

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 a 10-parameter read-only counting tool with no output schema, the description covers purpose, cost profile, and routing to alternatives adequately. The one gap is that the return value (a single count vs per-file breakdown) is left to the perFile parameter description rather than the tool description.

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 parameters such as type, language, and perFile are already fully documented with defaults and constraints. The description only echoes the engine vocabulary (regex, literal, AST) without adding syntax, format, or interaction details beyond the schema, making baseline 3 appropriate.

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 (count) and resource (matching lines/occurrences) across three named engines, and the phrase 'without returning match content' cleanly separates it from a sibling like 'search' that returns content.

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 prescribes usage before 'search' or 'replace' with a stated rationale (gauge blast radius, save context tokens). The when-not case is only implied via 'without returning match content' rather than stated outright, so it falls short of the top mark.

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

Deploy Server

Other Tools