MCPcopy Create free account
hub / github.com/FSoft-AI4Code/HyperAgent / GetAllSymbolsTool

Class GetAllSymbolsTool

src/hyperagent/tools/nav_tools.py:204–243  ·  view source on GitHub ↗

A tool for finding all symbols (functions, classes, methods) of a Python/Rust/C#/Java file. Args: path (str): The path to the source file. language (str, optional): The language of the file. Defaults to "python".

Source from the content-addressed store, hash-verified

202 keyword: Optional[str] = Field(None, description="The keyword we want to search among the symbols. Optional.")
203
204class GetAllSymbolsTool(BaseTool):
205 """
206 A tool for finding all symbols (functions, classes, methods) of a Python/Rust/C#/Java file.
207
208 Args:
209 path (str): The path to the source file.
210 language (str, optional): The language of the file. Defaults to "python".
211 """
212
213 name = "get_all_symbols"
214 description = "Useful when you want to find all symbols (functions, classes, methods) of source files. If you want to look for a specific keyword inside the name of the symbol, specify it, otherwise if you want to see all the symbols, do not provide the keyword. Prioritize using keyword to shorten the search."
215 args_schema = GetAllSymbolsArgs
216 lsptoolkit: LSPToolKit = None
217 path = ""
218 verbose = False
219 language = "python"
220
221 def __init__(self, path: str, language: str ="python"):
222 super().__init__()
223 self.path = path
224
225 def _run(self, path_to_file: str, keyword: Optional[str] = None):
226 """
227 Run the tool to get all symbols of a Python file.
228
229 Args:
230 path_to_file (str): The path to the Python file.
231 preview_size (int, optional): The number of symbols to preview. Defaults to 5.
232
233 Returns:
234 Union[List[str], str]: The list of symbols or an error message.
235 """
236 try:
237 return get_symbol_verbose(osp.join(self.path, path_to_file), self.path, keyword)
238 except IsADirectoryError:
239 return "The relative path is a folder, please specify the file path instead. Consider using get_tree_structure to find the file name then use this tool one file path at a time"
240 except FileNotFoundError:
241 return "The file is not found, please check the path again"
242 except lsp_protocol_handler.server.Error:
243 return "Internal error, please use other tool"
244
245class GetTreeStructureArgs(BaseModel):
246 relative_path: str = Field(..., description="The relative path of the folder we want to explore")

Callers 1

nav_tools.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected