ast-grep MCP Server
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| AST_GREP_CONFIG | No | Path 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
| Capability | Details |
|---|---|
| tools | {
"listChanged": false
} |
| prompts | {
"listChanged": false
} |
| resources | {
"subscribe": false,
"listChanged": false
} |
| experimental | {} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| 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.
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 Internally calls: ast-grep run --pattern [--json] Output formats:
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 Tip: When using relational rules (inside/has), add Internally calls: ast-grep scan --inline-rules [--json] Output formats:
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
| Name | Description |
|---|---|
No prompts | |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
No resources | |
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/ast-grep/ast-grep-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server