Skip to main content
Glama

find_references

Locate all references to a symbol in Godot projects using LSP or text search to track code usage and dependencies.

Instructions

Find all references to a symbol at a given position. LSP-only (returns error without LSP). Falls back to text search.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesPath to the file containing the symbol
lineYesLine number (1-based)
characterNoCharacter offset (0-based)

Implementation Reference

  • Handler for find_references tool. Uses LSP for accurate reference finding or falls back to basic regex-based text search if LSP is unavailable.
    name: "find_references",
    description:
      "Find all references to a symbol at a given position. LSP-only (returns error without LSP). Falls back to text search.",
    schema: {
      file: z.string().describe("Path to the file containing the symbol"),
      line: z.number().int().min(1).describe("Line number (1-based)"),
      character: z
        .number()
        .int()
        .min(0)
        .optional()
        .default(0)
        .describe("Character offset (0-based)"),
    },
    handler: async (ctx) => {
      const { file, line, character = 0 } = ctx.args;
      validatePath(file);
      const lsp = getLspClient();
      const cache = getLspCache();
    
      if (lsp?.connected) {
        const uri = `file://${file}`;
        const lspLine = line - 1; // Convert 1-based to 0-based
        const cacheKey = `${uri}:${lspLine}:${character}`;
    
        // Check cache first
        if (cache) {
          const cached = cache.getReferences(cacheKey);
          if (cached) {
            return makeTextResponse({
              data: cached.map((l) => ({
                file: l.uri.replace("file://", ""),
                line: l.range.start.line + 1,
                character: l.range.start.character,
              })),
              totalCount: cached.length,
              metadata: { source: "lsp-cache" },
            });
          }
        }
    
        try {
          const locations = await lsp.findReferences(uri, lspLine, character);
    
          // Cache the result
          if (cache) {
            cache.setReferences(cacheKey, locations);
          }
    
          return makeTextResponse({
            data: locations.map((l) => ({
              file: l.uri.replace("file://", ""),
              line: l.range.start.line + 1,
              character: l.range.start.character,
            })),
            totalCount: locations.length,
            metadata: { source: "lsp" },
          });
        } catch (err) {
          return makeTextResponse({
            error: `LSP error: ${(err as Error).message}`,
            data: null,
            metadata: { source: "lsp" },
          });
        }
      }
    
      // Fallback: grep-style text search for the symbol name
      try {
        const source = readFileSync(file, "utf-8");
        const lines = source.split("\n");
        const targetLine = lines[line - 1] ?? "";
        // Extract symbol name at position
        const wordMatch = targetLine.slice(character).match(/^(\w+)/);
        const symbolName = wordMatch?.[1];
    
        if (!symbolName) {
          return makeTextResponse({
            error: "Could not determine symbol name at position",
            data: null,
          });
        }
    
        // Search all scripts for this symbol name
        const refs: Array<{
          file: string;
          line: number;
          context: string;
        }> = [];
    
        for (const [scriptPath, _script] of await index.scriptIndex.all()) {
          try {
            const scriptSource = readFileSync(scriptPath, "utf-8");
            const scriptLines = scriptSource.split("\n");
            for (let i = 0; i < scriptLines.length; i++) {
              if (scriptLines[i].includes(symbolName)) {
                refs.push({
                  file: scriptPath,
                  line: i + 1,
                  context: scriptLines[i].trim(),
                });
              }
            }
          } catch {
            // Skip unreadable files
          }
        }
    
        return makeTextResponse({
          data: refs,
          totalCount: refs.length,
          metadata: { source: "fallback", note: "Text search only. LSP unavailable." },
        });
      } catch (err) {
        return makeTextResponse({
          error: `Failed: ${(err as Error).message}`,
          data: null,
        });
      }
    },
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key traits: the tool's dependency on LSP ('LSP-only'), error behavior ('returns error without LSP'), and fallback mechanism ('Falls back to text search'). This adds valuable context beyond the input schema, though it could mention output format or limitations like rate limits.

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 highly concise and front-loaded: a single sentence states the core purpose, followed by two brief clauses for behavioral context. Every part earns its place with no wasted words, making it easy for an agent to parse quickly.

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 (symbol reference finding), no annotations, and no output schema, the description is partially complete. It covers purpose and key behaviors but lacks details on output format, error handling specifics, or prerequisites. This leaves gaps for an agent to fully understand the tool's operation.

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, so the schema already documents all parameters (file, line, character). The description doesn't add any parameter-specific details beyond what the schema provides, such as explaining how 'character' interacts with 'line' for symbol positioning. Thus, it meets the baseline of 3 without compensating further.

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: 'Find all references to a symbol at a given position.' It specifies the verb ('find'), resource ('references'), and scope ('symbol at a given position'). However, it doesn't explicitly differentiate from sibling tools like 'find_symbol' or 'find_resources_of_type', which prevents a score of 5.

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 provides some usage context: 'LSP-only (returns error without LSP). Falls back to text search.' This implies when to use it (with LSP support) and hints at an alternative behavior (text search fallback). However, it doesn't explicitly state when to choose this tool over similar siblings like 'find_symbol' or provide clear exclusions, keeping it at an implied level.

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/woohq/godette-mcp'

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