Skip to main content
Glama

pattern

Match code by structural shape across 19 languages using AST metavariables, not text. Enables cross-language structural queries that grep cannot handle.

Instructions

Structural AST pattern matching: match code by shape, not text. Metavars: $NAME captures an identifier or balanced expression, $_ is a wildcard, $$$ is an anonymous ellipsis, $$$NAME / $$NAME is a named ellipsis that captures multi-line bodies or arg lists, repeated metavars enforce back-reference equality. Composition: space-flanked && and || join sub-patterns (AND requires both shapes in the file with shared captures agreeing; OR takes the union). Prefer over grep / ast-grep for cross-language structural queries — grep cannot match nested syntax, and ast-grep needs per-language scripts; vex pattern works on the cached tree-sitter parse with a skeleton prefilter (~10-50ms). Set why: true to inspect indexed vs live-scan mode. Supports diff scoping: since (rev), since_branched (since this branch diverged from main), changed_only (working-tree changes) — mutually exclusive.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
whyNoSurface a ScanTrace under `_meta.why` in the response: mode (indexed/live_scan), root_kind_inferred, candidate_files / total_files, fallback_reason.
langYesLanguage: rust, python, typescript, go, java, csharp, ruby, kotlin, swift, cpp, php, sql, markdown
limitNoMax matches to return
sinceNoRestrict results to files changed between `<rev>..HEAD` (accepts anything `git diff` understands: `main`, `HEAD~3`, `origin/main`, SHA). Mutually exclusive with `since_branched` and `changed_only`.
excludeNoBlacklist results by path glob; wins over include (repeatable)
includeNoWhitelist results by path glob, gitignore syntax (repeatable)
patternYesStructural pattern with $METAVARS (e.g. `fn $NAME($$ARGS) -> Result<$T, $E> { $$$BODY }`, `interface $N || class $N`). NOT regex — see grep for regex.
changed_onlyNoRestrict results to working-tree changes (staged + unstaged + untracked). Mutually exclusive with `since` and `since_branched`.
project_rootNoAbsolute path to the project root (defaults to the MCP working directory)
exclude_testsNoDrop test files from the results (tests/ dirs, *_test.*, test_*.py, *.spec.ts, __tests__/, tests.rs, ...; same set as tests_for). Composes with include/exclude. Path-based only: Rust unit tests inside a `#[cfg(test)] mod tests` block of a non-test file are not excluded.
since_branchedNoRestrict results to files changed since this branch diverged from `origin/main` (or `main`/`master`). Mutually exclusive with `since` and `changed_only`.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.27.3

TDQS

A4.5/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 does well: it discloses metavar semantics, back-reference equality, composition rules, the cached tree-sitter parse with a skeleton prefilter (~10-50ms), and mutual exclusivity of diff-scoping flags. It does not describe the response shape beyond the optional `_meta.why` trace, leaving return-format behavior unspecified.

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?

Dense but front-loaded: core concept first, then metavars, composition, sibling comparison, and scoping flags. Every sentence carries information, though the metavar/composition sentences are run-on and could be tightened.

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 an 11-parameter tool with no annotations and no output schema, the description covers the operationally critical details: pattern language, performance model, scoping exclusions, and the debug flag. It stops short of describing result structure, but the `why` trace and schema docs fill most of the remaining gap.

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 coverage is 100%, so the baseline is 3, but the description adds real meaning beyond the schema: metavar grammar ($NAME, $_, $$$, $$$NAME), composition operators with AND/OR capture semantics, and the interaction rules for the diff-scoping parameters.

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?

Opens with a specific verb+resource: 'Structural AST pattern matching: match code by shape, not text.' It immediately contrasts with grep and ast-grep, so an agent can distinguish it from the sibling grep tool without opening either schema.

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?

Explicitly names the alternatives and the conditions selecting this tool: 'Prefer over grep / ast-grep for cross-language structural queries — grep cannot match nested syntax, and ast-grep needs per-language scripts.' It also documents mutually exclusive diff-scoping parameters (since / since_branched / changed_only).

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