Skip to main content
Glama

Find Referencing Symbols

find_referencing_symbols
Read-only

Locates all references to a specific symbol in code, providing metadata and context snippets to understand usage patterns and dependencies.

Instructions

Finds references to the symbol at the given name_path. The result will contain metadata about the referencing symbols as well as a short code snippet around the reference. Returns a list of JSON objects with the symbols referencing the requested symbol.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
name_pathYesFor finding the symbol to find references for, same logic as in the `find_symbol` tool.
relative_pathYesThe relative path to the file containing the symbol for which to find references. Note that here you can't pass a directory but must pass a file.
include_kindsNoSame as in the `find_symbol` tool.
exclude_kindsNoSame as in the `find_symbol` tool.
max_answer_charsNoSame as in the `find_symbol` tool.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler implementation for the 'find_referencing_symbols' tool. The apply method orchestrates the retrieval of referencing symbols using the LanguageServerSymbolRetriever, processes the results, adds context snippets, and returns JSON.
    class FindReferencingSymbolsTool(Tool, ToolMarkerSymbolicRead):
        """
        Finds symbols that reference the given symbol using the language server backend
        """
    
        # noinspection PyDefaultArgument
        def apply(
            self,
            name_path: str,
            relative_path: str,
            include_kinds: list[int] = [],  # noqa: B006
            exclude_kinds: list[int] = [],  # noqa: B006
            max_answer_chars: int = -1,
        ) -> str:
            """
            Finds references to the symbol at the given `name_path`. The result will contain metadata about the referencing symbols
            as well as a short code snippet around the reference.
    
            :param name_path: for finding the symbol to find references for, same logic as in the `find_symbol` tool.
            :param relative_path: the relative path to the file containing the symbol for which to find references.
                Note that here you can't pass a directory but must pass a file.
            :param include_kinds: same as in the `find_symbol` tool.
            :param exclude_kinds: same as in the `find_symbol` tool.
            :param max_answer_chars: same as in the `find_symbol` tool.
            :return: a list of JSON objects with the symbols referencing the requested symbol
            """
            include_body = False  # It is probably never a good idea to include the body of the referencing symbols
            parsed_include_kinds: Sequence[SymbolKind] | None = [SymbolKind(k) for k in include_kinds] if include_kinds else None
            parsed_exclude_kinds: Sequence[SymbolKind] | None = [SymbolKind(k) for k in exclude_kinds] if exclude_kinds else None
            symbol_retriever = self.create_language_server_symbol_retriever()
            references_in_symbols = symbol_retriever.find_referencing_symbols(
                name_path,
                relative_file_path=relative_path,
                include_body=include_body,
                include_kinds=parsed_include_kinds,
                exclude_kinds=parsed_exclude_kinds,
            )
            reference_dicts = []
            for ref in references_in_symbols:
                ref_dict = ref.symbol.to_dict(kind=True, location=True, depth=0, include_body=include_body)
                ref_dict = _sanitize_symbol_dict(ref_dict)
                if not include_body:
                    ref_relative_path = ref.symbol.location.relative_path
                    assert ref_relative_path is not None, f"Referencing symbol {ref.symbol.name} has no relative path, this is likely a bug."
                    content_around_ref = self.project.retrieve_content_around_line(
                        relative_file_path=ref_relative_path, line=ref.line, context_lines_before=1, context_lines_after=1
                    )
                    ref_dict["content_around_reference"] = content_around_ref.to_display_string()
                reference_dicts.append(ref_dict)
            result = self._to_json(reference_dicts)
            return self._limit_length(result, max_answer_chars)
  • Helper method in LanguageServerSymbolRetriever that resolves the symbol by name_path and calls find_referencing_symbols_by_location.
    def find_referencing_symbols(
        self,
        name_path: str,
        relative_file_path: str,
        include_body: bool = False,
        include_kinds: Sequence[SymbolKind] | None = None,
        exclude_kinds: Sequence[SymbolKind] | None = None,
    ) -> list[ReferenceInLanguageServerSymbol]:
        """
        Find all symbols that reference the specified symbol, which is assumed to be unique.
    
        :param name_path: the name path of the symbol to find. (While this can be a matching pattern, it should
            usually be the full path to ensure uniqueness.)
        :param relative_file_path: the relative path of the file in which the referenced symbol is defined.
        :param include_body: whether to include the body of all symbols in the result.
            Not recommended, as the referencing symbols will often be files, and thus the bodies will be very long.
        :param include_kinds: which kinds of symbols to include in the result.
        :param exclude_kinds: which kinds of symbols to exclude from the result.
        """
        symbol = self.find_unique(name_path, substring_matching=False, within_relative_path=relative_file_path)
        return self.find_referencing_symbols_by_location(
            symbol.location, include_body=include_body, include_kinds=include_kinds, exclude_kinds=exclude_kinds
        )
  • Core helper method in LanguageServerSymbolRetriever that performs the actual language server request_referencing_symbols call to fetch references, applies kind filters, and returns processed references.
    def find_referencing_symbols_by_location(
        self,
        symbol_location: LanguageServerSymbolLocation,
        include_body: bool = False,
        include_kinds: Sequence[SymbolKind] | None = None,
        exclude_kinds: Sequence[SymbolKind] | None = None,
    ) -> list[ReferenceInLanguageServerSymbol]:
        """
        Find all symbols that reference the symbol at the given location.
    
        :param symbol_location: the location of the symbol for which to find references.
            Does not need to include an end_line, as it is unused in the search.
        :param include_body: whether to include the body of all symbols in the result.
            Not recommended, as the referencing symbols will often be files, and thus the bodies will be very long.
            Note: you can filter out the bodies of the children if you set include_children_body=False
            in the to_dict method.
        :param include_kinds: an optional sequence of ints representing the LSP symbol kind.
            If provided, only symbols of the given kinds will be included in the result.
        :param exclude_kinds: If provided, symbols of the given kinds will be excluded from the result.
            Takes precedence over include_kinds.
        :return: a list of symbols that reference the given symbol
        """
        if not symbol_location.has_position_in_file():
            raise ValueError("Symbol location does not contain a valid position in a file")
        assert symbol_location.relative_path is not None
        assert symbol_location.line is not None
        assert symbol_location.column is not None
        lang_server = self.get_language_server(symbol_location.relative_path)
        references = lang_server.request_referencing_symbols(
            relative_file_path=symbol_location.relative_path,
            line=symbol_location.line,
            column=symbol_location.column,
            include_imports=False,
            include_self=False,
            include_body=include_body,
            include_file_symbols=True,
        )
    
        if include_kinds is not None:
            references = [s for s in references if s.symbol["kind"] in include_kinds]
    
        if exclude_kinds is not None:
            references = [s for s in references if s.symbol["kind"] not in exclude_kinds]
    
        return [ReferenceInLanguageServerSymbol.from_lsp_reference(r) for r in references]
Behavior3/5

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

Annotations already declare readOnlyHint=true and destructiveHint=false, indicating a safe read operation. The description adds useful behavioral context beyond annotations by specifying what the result contains (metadata about referencing symbols and short code snippets) and that it returns a list of JSON objects. However, it doesn't mention potential limitations like performance impacts or result size constraints.

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 efficiently structured in two sentences with zero waste. The first sentence states the core functionality and result format, while the second clarifies the return type. Every word contributes to understanding the tool's purpose and output.

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

Completeness5/5

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

Given the presence of annotations (readOnlyHint, destructiveHint), 100% schema coverage, and an output schema (implied by 'Returns a list of JSON objects'), the description provides complete contextual information. It adequately explains what the tool does, what it returns, and references sibling tools where appropriate, making it sufficient for agent understanding.

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?

With 100% schema description coverage, the input schema already documents all 5 parameters thoroughly, including references to the 'find_symbol' tool for parameter behavior. The description doesn't add significant semantic information beyond what's in the schema, maintaining the baseline score of 3 for adequate but not enhanced parameter documentation.

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

Purpose5/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 ('Finds references') and resource ('the symbol at the given name_path'), and distinguishes it from sibling tools by specifying it returns referencing symbols rather than finding symbols themselves. It explicitly mentions what the result contains (metadata and code snippets), making the purpose unambiguous.

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

Usage Guidelines4/5

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

The description implies usage context by mentioning the tool finds references to a symbol, suggesting it should be used when you need to know where a symbol is referenced. However, it doesn't explicitly state when to use this tool versus alternatives like 'find_symbol' or provide exclusion criteria, though the parameter descriptions reference 'find_symbol' for some parameters.

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/oraios/serena'

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