Skip to main content
Glama
minami110

GDScript Code Analyzer

by minami110

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
NameRequiredDescriptionDefault
file_pathYesPath to the GDScript file
symbol_nameYesName of the symbol to find

Implementation Reference

  • 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,
            )
  • 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"],
        },
    ),
  • 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"])
  • 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
  • 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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/minami110/mcp-gdscript'

If you have feedback or need assistance with the MCP directory API, please join our Discord server