Skip to main content
Glama
ast-grep

ast-grep MCP Server

by ast-grep

Server Configuration

Describes the environment variables required to run the server.

NameRequiredDescriptionDefault
AST_GREP_CONFIGNoPath to custom sgconfig.yaml file to configure ast-grep behavior

Instructions

Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.

This server publishes no instructions, or was last inspected before Glama recorded them.

Capabilities

Features and capabilities supported by this server

Protocol revision2025-11-25

CapabilityDetails
tools
{
  "listChanged": false
}
prompts
{
  "listChanged": false
}
resources
{
  "subscribe": false,
  "listChanged": false
}
experimental
{}

Tools

Functions exposed to the LLM to take actions

NameDescription
dump_syntax_treeA

Dump code's syntax structure or dump a query's pattern structure. This is useful to discover correct syntax kind and syntax tree structure. Call it when debugging a rule. The tool requires three arguments: code, language and format. The first two are self-explanatory. format is the output format of the syntax tree. use format=cst to inspect the code's concrete syntax tree structure, useful to debug target code. use format=pattern to inspect how ast-grep interprets a pattern, useful to debug pattern rule.

Internally calls: ast-grep run --pattern --lang --debug-query=

test_match_code_ruleA

Test a code against an ast-grep YAML rule. This is useful to test a rule before using it in a project.

Internally calls: ast-grep scan --inline-rules --json --stdin

find_codeA

Find code in a project folder that matches the given ast-grep pattern. Pattern is good for simple and single-AST node result. For more complex usage, please use YAML by find_code_by_rule.

Internally calls: ast-grep run --pattern [--json]

Output formats:

  • text (default): Compact text format with file:line-range headers and complete match text Example: Found 2 matches:

    path/to/file.py:10-15 def example_function(): # function body return result

    path/to/file.py:20-22 def another_function(): pass

  • json: Full match objects with metadata including ranges, meta-variables, etc.

The max_results parameter limits the number of complete matches returned (not individual lines). When limited, the header shows "Found X matches (showing first Y of Z)".

Example usage: find_code(pattern="class $NAME", max_results=20) # Returns text format find_code(pattern="class $NAME", output_format="json") # Returns JSON with metadata

find_code_by_ruleA

Find code using ast-grep's YAML rule in a project folder. YAML rule is more powerful than simple pattern and can perform complex search like find AST inside/having another AST. It is a more advanced search tool than the simple find_code.

Tip: When using relational rules (inside/has), add stopBy: end to ensure complete traversal.

Internally calls: ast-grep scan --inline-rules [--json]

Output formats:

  • text (default): Compact text format with file:line-range headers and complete match text Example: Found 2 matches:

    src/models.py:45-52 class UserModel: def init(self): self.id = None self.name = None

    src/views.py:12 class SimpleView: pass

  • json: Full match objects with metadata including ranges, meta-variables, etc.

The max_results parameter limits the number of complete matches returned (not individual lines). When limited, the header shows "Found X matches (showing first Y of Z)".

Example usage: find_code_by_rule(yaml="id: x\nlanguage: python\nrule: {pattern: 'class $NAME'}", max_results=20) find_code_by_rule(yaml="...", output_format="json") # For full metadata

Prompts

Interactive templates invoked by user choice

NameDescription

No prompts

Resources

Contextual data attached and managed by the client

NameDescription

No resources

TDQS

A4.1/5.0

Scored across 4 tools

Disambiguation4/5

The tools have mostly distinct purposes: dump_syntax_tree is for debugging syntax structures, find_code and find_code_by_rule are for searching code with different rule formats, and test_match_code_rule is for testing rules. However, find_code and find_code_by_rule could be confused as both search for code matches, though their descriptions clarify the pattern vs. YAML rule distinction.

Naming Consistency5/5

All tool names follow a consistent snake_case pattern with clear verb_noun structures: dump_syntax_tree, find_code, find_code_by_rule, and test_match_code_rule. This makes them predictable and easy to understand at a glance.

Tool Count5/5

With 4 tools, this server is well-scoped for ast-grep functionality. Each tool serves a specific role in code analysis and debugging, covering core operations without being overly sparse or bloated.

Completeness4/5

The toolset covers essential ast-grep operations: debugging syntax, searching with patterns and YAML rules, and testing rules. A minor gap is the lack of a tool for modifying or refactoring code based on matches, but the server's focus on analysis and testing is adequately covered.

Maintenance

ActivityMaintained
ResponsivenessSlow