Skip to main content
Glama
ast-grep

ast-grep MCP Server

by ast-grep

find_code

Search code in a project folder using AST patterns to locate specific code structures across multiple programming languages.

Instructions

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] <project_folder>

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_folderYesThe absolute path to the project folder. It must be absolute path.
patternYesThe ast-grep pattern to search for. Note, the pattern must have valid AST structure.
languageNoThe language of the code. Supported: bash, c, cpp, csharp, css, elixir, go, haskell, html, java, javascript, json, jsx, kotlin, lua, nix, php, python, ruby, rust, scala, solidity, swift, tsx, typescript, yaml. If not specified, will be auto-detected based on file extensions.
max_resultsNoMaximum results to return
output_formatNo'text' or 'json'text
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: the tool internally calls 'ast-grep run', explains output formats (text and JSON) with examples, clarifies that 'max_results' limits complete matches (not lines), and shows how limited results are displayed. It covers execution, output, and limitations well, though it doesn't mention error handling or performance aspects like rate limits.

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 well-structured and appropriately sized, with clear sections for purpose, usage guidelines, internal details, output formats, and examples. It uses bullet points and examples effectively, though it could be slightly more concise by integrating some details (e.g., internal call info) more seamlessly. Every sentence adds value, but minor trimming is possible.

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?

Given the tool's complexity (5 parameters, no annotations, no output schema), the description is largely complete. It covers purpose, usage, behavior, and outputs in detail, compensating for the lack of annotations and output schema. However, it doesn't explicitly address potential errors (e.g., invalid patterns or paths) or prerequisites (e.g., tool installation), leaving a small gap in contextual coverage.

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?

The input schema has 100% description coverage, so the schema already documents all parameters thoroughly. The description adds minimal parameter semantics beyond the schema, such as noting that the pattern is for 'simple and single-AST node result' and providing example usage with 'pattern' and 'max_results'. However, it doesn't significantly enhance understanding of parameters like 'project_folder' or 'language' beyond what the schema provides, meeting the baseline for high schema coverage.

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?

The description clearly states the tool's purpose: 'Find code in a project folder that matches the given ast-grep pattern.' It specifies the verb ('Find'), resource ('code'), and scope ('project folder'), and distinguishes it from sibling tools by noting that 'find_code_by_rule' is for more complex usage. This is specific and avoids tautology.

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?

The description provides explicit guidance on when to use this tool versus alternatives: 'Pattern is good for simple and single-AST node result. For more complex usage, please use YAML by `find_code_by_rule`.' It also mentions internal implementation details and includes example usage, clearly defining the context and exclusions.

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

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