Skip to main content
Glama
minami110

GDScript Code Analyzer

by minami110

find_references

Locate all uses of a specific symbol in GDScript code to understand dependencies and track variable or function usage across your Godot project.

Instructions

Find all references to a symbol across the project or in a specific file.

Input Schema

NameRequiredDescriptionDefault
symbol_nameYesName of the symbol to find references for
file_pathNoOptional: Limit search to a specific file. If not provided, searches entire project.

Input Schema (JSON Schema)

{ "properties": { "file_path": { "description": "Optional: Limit search to a specific file. If not provided, searches entire project.", "type": "string" }, "symbol_name": { "description": "Name of the symbol to find references for", "type": "string" } }, "required": [ "symbol_name" ], "type": "object" }

Implementation Reference

  • Main execution logic for the 'find_references' tool: determines files to search (specific or project-wide), parses each GDScript file, uses parser to find symbol references, aggregates locations with file info, returns JSON-formatted CallToolResult.
    def _find_references(self, symbol_name: str, file_path: Optional[str] = None) -> CallToolResult: """Find references to a symbol. Args: symbol_name: Name of the symbol to find file_path: Optional specific file to search in Returns: CallToolResult with references """ try: files_to_search: list[Path] = [] if file_path: # Search in specific file path = Path(file_path) if not path.exists(): return CallToolResult( content=[TextContent(type="text", text=f"File not found: {file_path}")], isError=True, ) files_to_search = [path] elif self.project_root: # Search in project files_to_search = self._gdscript_files else: return CallToolResult( content=[TextContent(type="text", text="No project root set and no specific file provided")], isError=True, ) all_references = [] for file in files_to_search: try: code = file.read_text(encoding="utf-8") tree = self.parser.parse(code) references = self.parser.find_references(tree, symbol_name) for ref in references: all_references.append({ "file": str(file.relative_to(self.project_root) if self.project_root else file), "line": ref["line"], "column": ref["column"], "end_line": ref["end_line"], "end_column": ref["end_column"], }) except Exception as e: # Skip files that can't be parsed continue result = { "symbol": symbol_name, "total_references": len(all_references), "references": all_references, } return CallToolResult( content=[TextContent(type="text", text=json.dumps(result, indent=2))], isError=False, ) except Exception as e: return CallToolResult( content=[TextContent(type="text", text=f"Error finding references: {str(e)}")], isError=True, )
  • Tool registration in get_tools(): defines name 'find_references', description, and input schema (symbol_name required, file_path optional).
    Tool( name="find_references", description="Find all references to a symbol across the project or in a specific file.", inputSchema={ "type": "object", "properties": { "symbol_name": { "type": "string", "description": "Name of the symbol to find references for", }, "file_path": { "type": "string", "description": "Optional: Limit search to a specific file. If not provided, searches entire project.", }, }, "required": ["symbol_name"], }, ),
  • Dispatch in handle_tool_call() that routes 'find_references' calls to the _find_references handler method.
    elif tool_name == "find_references": return self._find_references(tool_input["symbol_name"], tool_input.get("file_path"))
  • Supporting parser method 'find_references' and recursive helper: traverses tree-sitter AST to locate all 'identifier' and 'name' nodes matching the symbol_name, collects line/column positions.
    def find_references(self, tree: Tree, symbol_name: str) -> list[dict[str, Any]]: """Find all references to a symbol in the code. Args: tree: The parsed syntax tree symbol_name: Name of the symbol to find references for Returns: List of reference locations with context """ references = [] self._find_references_recursive(tree.root_node, symbol_name, references) return references def _find_references_recursive( self, node: Node, symbol_name: str, references: list[dict[str, Any]], depth: int = 0 ) -> None: """Recursively find symbol references in tree nodes. Args: node: Current tree node symbol_name: Name of the symbol to find references: List to populate with references depth: Current recursion depth """ if depth > 20: # Prevent infinite recursion return node_type = node.type # Check if this is an identifier or name node matching the symbol if node_type in ("identifier", "name"): text = node.text.decode("utf-8") if isinstance(node.text, bytes) else str(node.text) if text == symbol_name: references.append( { "line": node.start_point[0] + 1, "column": node.start_point[1], "end_line": node.end_point[0] + 1, "end_column": node.end_point[1], } ) # Recursively process child nodes for child in node.children: self._find_references_recursive(child, symbol_name, references, depth + 1)

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