find_gdscript_symbol
Locate and retrieve details of specific symbols like classes, functions, or signals within GDScript files to analyze code structure and dependencies.
Instructions
Search for a specific symbol (class, function, signal, etc.) in a GDScript file and get its details.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the GDScript file | |
| symbol_name | Yes | Name of the symbol to find |
Implementation Reference
- src/mcp_gdscript/tools.py:263-299 (handler)The handler function '_find_symbol' that implements the core logic of the 'find_gdscript_symbol' tool: reads the file, parses it, finds the symbol via parser, and serializes to JSON.def _find_symbol(self, file_path: str, symbol_name: str) -> CallToolResult: """Find a symbol in a GDScript file. Args: file_path: Path to the file symbol_name: Name of the symbol to find Returns: CallToolResult with symbol info """ try: path = Path(file_path) if not path.exists(): return CallToolResult( content=[TextContent(type="text", text=f"File not found: {file_path}")], isError=True, ) code = path.read_text(encoding="utf-8") tree = self.parser.parse(code) symbol = self.parser.find_symbol(tree, symbol_name) if symbol: return CallToolResult( content=[TextContent(type="text", text=json.dumps(symbol, indent=2))], isError=False, ) else: return CallToolResult( content=[TextContent(type="text", text=f"Symbol '{symbol_name}' not found")], isError=True, ) except Exception as e: return CallToolResult( content=[TextContent(type="text", text=f"Error finding symbol: {str(e)}")], isError=True, )
- src/mcp_gdscript/tools.py:56-73 (registration)Registration of the tool in the 'get_tools' method, defining name, description, and input schema.Tool( name="find_gdscript_symbol", description="Search for a specific symbol (class, function, signal, etc.) in a GDScript file and get its details.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "description": "Path to the GDScript file", }, "symbol_name": { "type": "string", "description": "Name of the symbol to find", }, }, "required": ["file_path", "symbol_name"], }, ),
- src/mcp_gdscript/tools.py:160-161 (registration)Dispatch/registration in the 'handle_tool_call' method that routes calls to the handler.elif tool_name == "find_gdscript_symbol": return self._find_symbol(tool_input["file_path"], tool_input["symbol_name"])
- src/mcp_gdscript/parser.py:189-209 (helper)Helper method 'find_symbol' in GDScriptParser that searches extracted symbols for the matching name and returns details.def find_symbol(self, tree: Tree, symbol_name: str) -> Optional[dict[str, Any]]: """Find a symbol by name. Args: tree: The parsed syntax tree symbol_name: Name of the symbol to find Returns: Symbol information or None if not found """ symbols = self.get_symbols(tree) for sym_type in ["classes", "functions", "signals", "variables", "enums"]: for sym in symbols[sym_type]: if sym["name"] == symbol_name: return { "type": sym_type[:-1], # Remove trailing 's' **sym, } return None
- src/mcp_gdscript/parser.py:27-46 (helper)Helper method 'get_symbols' that extracts all symbols from the parse tree by traversing nodes.def get_symbols(self, tree: Tree) -> dict[str, Any]: """Extract symbols (classes, functions, etc.) from the tree. Args: tree: The parsed syntax tree Returns: Dictionary with symbol information """ symbols = { "classes": [], "functions": [], "variables": [], "signals": [], "enums": [], } self._extract_symbols(tree.root_node, symbols) return symbols