find_gdscript_symbol
Locate specific symbols like classes or functions in GDScript files to analyze code structure and retrieve detailed information for Godot engine development.
Instructions
Search for a specific symbol (class, function, signal, etc.) in a GDScript file and get its details.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the GDScript file | |
| symbol_name | Yes | Name of the symbol to find |
Input Schema (JSON Schema)
{
"properties": {
"file_path": {
"description": "Path to the GDScript file",
"type": "string"
},
"symbol_name": {
"description": "Name of the symbol to find",
"type": "string"
}
},
"required": [
"file_path",
"symbol_name"
],
"type": "object"
}
Implementation Reference
- src/mcp_gdscript/tools.py:263-299 (handler)Handler function that implements the core logic of the 'find_gdscript_symbol' tool: reads the file, parses it, calls parser.find_symbol, and returns JSON result or error.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 (schema)Tool schema definition including name, description, and inputSchema with required parameters file_path and symbol_name.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)Registration and dispatch of the tool in the handle_tool_call method, mapping tool_name 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 in GDScriptParser that implements the symbol search logic by iterating over extracted symbols from the parse tree.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