Skip to main content
Glama
c0sc0s
by c0sc0s

Get References

get_references

Find all definition and usage references for symbols in TypeScript projects by specifying file location, enabling code navigation and analysis without IDE integration.

Instructions

Resolve project-aware definition and usage references for the symbol at a 1-based line and column in a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes
workspaceRootNo
projectTsconfigPathNo
lineYes
columnYes

Implementation Reference

  • The handler for the 'get_references' tool, which calls `cache.getReferences` and formats the output.
    async (args: PositionArgs) => {
      const { references, project } = cache.getReferences(args.file, args.line, args.column, args);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({ file: args.file, line: args.line, column: args.column, references, project }, null, 2),
          },
        ],
        structuredContent: {
          file: args.file,
          line: args.line,
          column: args.column,
          references,
          project,
        },
      };
    },
  • The core logic for fetching references using the TypeScript Language Service.
    public getReferences(filePath: string, line: number, column: number): ReferenceItem[] {
      const normalizedFile = this.prepareFile(filePath);
      const sourceFile = this.languageService.getProgram()?.getSourceFile(normalizedFile);
      if (!sourceFile) {
        throw new Error(`TypeScript program did not include ${normalizedFile}`);
      }
    
      const offset = toOffset(sourceFile, line, column);
      const references = this.languageService.getReferencesAtPosition(normalizedFile, offset) ?? [];
      const definitionKeys = new Set(
        (this.languageService.getDefinitionAtPosition(normalizedFile, offset) ?? [])
          .map((definition) => this.toDefinitionItem(definition.fileName, definition.textSpan.start, definition.textSpan.length))
          .map((definition) => `${canonicalPath(definition.file)}:${definition.line}:${definition.column}`),
      );
    
      return references.map((reference) => {
        const item = this.toDefinitionItem(reference.fileName, reference.textSpan.start, reference.textSpan.length);
        return {
          ...item,
          isDefinition: definitionKeys.has(`${canonicalPath(item.file)}:${item.line}:${item.column}`),
        };
      });
    }
  • src/server.ts:105-130 (registration)
    Registration of the 'get_references' tool in the McpServer instance.
    server.registerTool(
      "get_references",
      {
        title: "Get References",
        description: "Resolve project-aware definition and usage references for the symbol at a 1-based line and column in a file.",
        inputSchema: definitionSchema,
      },
      async (args: PositionArgs) => {
        const { references, project } = cache.getReferences(args.file, args.line, args.column, args);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({ file: args.file, line: args.line, column: args.column, references, project }, null, 2),
            },
          ],
          structuredContent: {
            file: args.file,
            line: args.line,
            column: args.column,
            references,
            project,
          },
        };
      },
    );
Behavior3/5

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

Specifies '1-based' coordinate system (critical for line/column parameters) and 'project-aware' scope. However, with no annotations and no output schema, it omits what gets returned (locations? symbols?), error behavior when symbol not found, and whether results include the definition site or only usages.

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

Conciseness4/5

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

Single sentence with no waste. Front-loaded with the action and target. However, excessive brevity given the need to explain 5 parameters with zero schema documentation.

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

Completeness2/5

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

Inadequate for a 5-parameter tool with 0% schema coverage, no annotations, and no output schema. Missing: optional parameter semantics, return value structure, prerequisites (e.g., project initialization), and sibling differentiation.

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

Parameters2/5

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

With 0% schema coverage, the description must compensate fully. It successfully adds semantics for line/column (1-based) and file, but leaves workspaceRoot and projectTsconfigPath completely undocumented despite being important for the 'project-aware' behavior mentioned.

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?

Clear verb ('Resolve') and resource ('definition and usage references'), with scope ('project-aware', specific file location). Distinguishes from sibling get_definition by implying both definitions and usages are returned. Slight ambiguity in whether 'definition and usage references' means definitions plus usages, or just references.

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

Usage Guidelines2/5

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

No explicit guidance on when to use versus get_definition (which likely returns just the definition) or get_symbol_summary. No mention that workspaceRoot and projectTsconfigPath are optional or when to provide them.

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/c0sc0s/agent-workspace-mcp'

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