Skip to content

Commit d23a4c1

Browse files
feat: add yaml support
1 parent b9f8bc1 commit d23a4c1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,26 @@
1010
@mcp.tool()
1111
def find_code(
1212
project_folder: str = Field(description="The path to the project folder"),
13-
pattern: str = Field(description="The ast-grep pattern to search for"),
13+
pattern: str = Field(description="The ast-grep pattern to search for. Note the pattern must has valid AST structure."),
1414
language: str = Field(description="The language of the query", default=""),
1515
) -> List[dict[str, Any]]:
16-
"""Find code in a project folder that matches the given ast-grep pattern"""
16+
"""
17+
Find code in a project folder that matches the given ast-grep pattern.
18+
Pattern is good for simple and single-AST node result.
19+
For more complex usage, please use YAML by `find_code_by_rule`.
20+
"""
1721
return run_ast_grep_command(pattern, project_folder, language)
1822

1923
@mcp.tool()
2024
def find_code_by_rule(
2125
project_folder: str = Field(description="The path to the project folder"),
22-
yaml: str = Field(description="The ast-grep pattern to search for"),
26+
yaml: str = Field(description="The ast-grep YAML rule to search. It must have id, language, rule fields."),
2327
) -> List[dict[str, Any]]:
24-
"""Find code using ast-grep's YAML rule in a project folder"""
28+
"""
29+
Find code using ast-grep's YAML rule in a project folder.
30+
YAML rule is more powerful than simple pattern and can perform complex search like find AST inside/having another AST.
31+
It is a more advanced search tool than the simple `find_code`.
32+
"""
2533
return run_ast_grep_yaml(yaml, project_folder)
2634

2735
def run_ast_grep_command(pattern: str, project_folder: str, language: Optional[str]) -> List[dict[str, Any]]:

0 commit comments

Comments
 (0)