Skip to main content
Glama
thrawn01

ast-grep MCP Server

by thrawn01

ast_grep

Search, replace, or count code patterns using syntax-aware AST matching across 20+ programming languages.

Instructions

A powerful AST-based code search and refactoring tool that understands code structure across 20+ programming languages. Performs syntax-aware pattern matching and transformations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
globNoGlob pattern to filter files (e.g. '*.js', '**/*.{ts,tsx}')
modeNoOperation modesearch
pathNoFile or directory to search in. Defaults to current working directory.
contextNoNumber of lines to show around matches (like grep -C)
dry_runNoPreview changes without modifying files (default: true for replace mode)
patternYesAST pattern to search for using ast-grep syntax (e.g., 'console.log($MSG)', 'function $NAME($ARGS) { $$$BODY }')
languageNoTarget language for parsing. Auto-detected if not specified.
head_limitNoLimit output to first N matches
replacementNoReplacement pattern (optional). If provided, performs replacement instead of search. Uses same variable syntax as pattern.
Behavior3/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It explains the core behavior (syntax-aware, cross-language), but fails to mention important traits: whether it modifies files outside dry_run, error handling when pattern doesn't match anything, or performance implications on large codebases. It does highlight AST-based operation and 20+ language support, which adds some valuable behavioral context beyond the schema.

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 description is two dense sentences (44 words) with no fluff. Every phrase adds value: 'AST-based,' '20+ programming languages,' 'syntax-aware,' 'pattern matching and transformations.' It's front-loaded with the most critical differentiator ('AST-based'). Minor deduction for not including a brief usage scenario or caveat, but overall very concise.

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

Completeness3/5

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

Given 9 parameters, 3 operation modes (mode enum), and no output schema, the description is moderately complete. It covers the what and general how (AST pattern matching, cross-language) but misses when-not-to-use, output format expectations (e.g., returns matches with line numbers?), and side effects like file modification in replace mode. For a complex code transformation tool, an agent would benefit from knowing that ast-grep uses Tree-sitter grammars for parsing, which is not mentioned.

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% (all 9 parameters have descriptions), but the tool description adds contextual meaning beyond those individual definitions. It explains the overarching purpose (AST-based, structural matching) which helps an agent understand that parameters like 'pattern' use ast-grep's special syntax (e.g., '$MSG', '$$$BODY') – a concept not fully explained in the pattern parameter's own description. This cross-parameter justification earns a high score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it's an 'AST-based code search and refactoring tool' that 'understands code structure across 20+ programming languages' and performs 'syntax-aware pattern matching and transformations.' This is specific, uses a verb+resource structure, and distinguishes it from simple grep-like tools. However, it doesn't differentiate it from sibling tools because none are listed.

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

Usage Guidelines2/5

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

The description provides no guidance on when or when not to use this tool, nor does it mention any alternatives. It gives a general functional overview but lacks explicit context signals like prerequisites (e.g., project root setup) or situations where regex might be preferred over AST matching. Some usage context is implied through the parameter enum 'mode' (search/replace/count), but the description itself says nothing about usage boundaries.

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

Install Server

Other Tools

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/thrawn01/mcp-ast-grep'

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