Skip to content

Commit 8b5628c

Browse files
Merge pull request #9 from sebthom/patch-1
Improve tool documentation
2 parents b6f0cd0 + 6766947 commit 8b5628c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def dump_syntax_tree(
2222
"""
2323
Dump code's syntax structure or dump a query's pattern structure.
2424
This is useful to discover correct syntax kind and syntax tree structure. Call it when debugging a rule.
25-
The tool requires three argument: code, language and format. The first two are self-explanatory.
25+
The tool requires three arguments: code, language and format. The first two are self-explanatory.
2626
`format` is the output format of the syntax tree.
2727
use `format=cst` to inspect the code's concrete syntax tree structure, useful to debug target code.
2828
use `format=pattern` to inspect how ast-grep interprets a pattern, useful to debug pattern rule.
@@ -59,7 +59,7 @@ def test_match_code_rule(
5959
@mcp.tool()
6060
def find_code(
6161
project_folder: str = Field(description="The absolute path to the project folder. It must be absolute path."),
62-
pattern: str = Field(description="The ast-grep pattern to search for. Note the pattern must has valid AST structure."),
62+
pattern: str = Field(description="The ast-grep pattern to search for. Note, the pattern must have valid AST structure."),
6363
language: str = Field(description="The language of the query", default=""),
6464
) -> List[dict[str, Any]]:
6565
"""
@@ -71,13 +71,15 @@ def find_code(
7171

7272
@mcp.tool()
7373
def find_code_by_rule(
74-
project_folder: str = Field(description="The path to the project folder"),
74+
project_folder: str = Field(description="The absolute path to the project folder. It must be absolute path."),
7575
yaml: str = Field(description="The ast-grep YAML rule to search. It must have id, language, rule fields."),
7676
) -> List[dict[str, Any]]:
7777
"""
7878
Find code using ast-grep's YAML rule in a project folder.
7979
YAML rule is more powerful than simple pattern and can perform complex search like find AST inside/having another AST.
8080
It is a more advanced search tool than the simple `find_code`.
81+
82+
Tip: When using relational rules (inside/has), add `stopBy: end` to ensure complete traversal.
8183
"""
8284
return run_ast_grep_yaml(yaml, project_folder)
8385

0 commit comments

Comments
 (0)