Skip to main content
Glama
minami110

GDScript Code Analyzer

by minami110

find_references

Locate all occurrences of a symbol in GDScript code to understand usage patterns and dependencies across your Godot project or specific files.

Instructions

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

Input Schema

TableJSON 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.

Implementation Reference

  • Main handler function that implements the core logic of the 'find_references' tool: determines search scope (file or project), parses relevant files, invokes parser.find_references on each, aggregates results, and returns formatted JSON output.
    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,
            )
  • JSON schema defining the input parameters for the 'find_references' tool: required 'symbol_name' string and optional 'file_path' string.
    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"],
  • MCP Tool object registration in get_tools(), defining name, description, and input schema for 'find_references'.
    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"],
        },
    ),
  • Helper method in GDScriptParser invoked by the tool handler. Recursively traverses the Tree-sitter AST to locate all 'identifier' or 'name' nodes matching the symbol_name, collecting their 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)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the search scope (project-wide or file-specific) but fails to describe key behaviors such as the return format (e.g., list of locations, counts), performance characteristics (e.g., speed, limitations), or error handling (e.g., what happens if the symbol isn't found). For a search tool with zero annotation coverage, this leaves significant gaps in understanding how the tool operates beyond its basic purpose.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently conveys the core functionality and scope without any wasted words. It is front-loaded with the main action ('Find all references'), making it easy for an agent to quickly grasp the tool's purpose. Every part of the sentence earns its place by adding clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (search operation with 2 parameters), no annotations, and no output schema, the description is minimally adequate. It covers the basic what and where but lacks details on behavioral aspects like output format, error cases, or performance. While it meets the minimum for a simple search tool, it doesn't provide enough context for an agent to fully predict the tool's behavior in all scenarios, especially without annotations to fill gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with clear documentation for both parameters ('symbol_name' and 'file_path'). The description adds marginal value by reinforcing that 'file_path' is optional and specifying the search scope implications, but does not provide additional semantics beyond what the schema already states, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate with extra insights.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Find') and resource ('references to a symbol'), and specifies the scope ('across the project or in a specific file'). It distinguishes itself from siblings like 'find_gdscript_symbol' by focusing on references rather than the symbol itself. However, it doesn't explicitly differentiate from other tools like 'analyze_gdscript_code' or 'get_gdscript_dependencies', which might also involve reference-like operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by mentioning the optional 'file_path' parameter to limit searches, suggesting when to use it for project-wide vs. file-specific queries. However, it lacks explicit guidance on when to choose this tool over alternatives like 'find_gdscript_symbol' or 'get_gdscript_dependencies', and does not state any prerequisites or exclusions, leaving the agent to infer context from parameter descriptions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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