Skip to main content
Glama
c0sc0s
by c0sc0s

Get Definition

get_definition

Find where symbols are defined in code files by specifying file path, line, and column positions for navigation and analysis.

Instructions

Resolve the definition locations for a symbol at a 1-based line and column in a file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYes
workspaceRootNo
projectTsconfigPathNo
lineYes
columnYes

Implementation Reference

  • The tool registration for "get_definition" in MCP server.
    server.registerTool(
      "get_definition",
      {
        title: "Get Definition",
        description: "Resolve the definition locations for a symbol at a 1-based line and column in a file.",
        inputSchema: definitionSchema,
      },
      async (args: DefinitionArgs) => {
        const { definitions, project } = cache.getDefinitionWithMetadata(args.file, args.line, args.column, args);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  file: args.file,
                  line: args.line,
                  column: args.column,
                  definitions,
                  project,
                },
                null,
                2,
              ),
            },
          ],
          structuredContent: {
            file: args.file,
            line: args.line,
            column: args.column,
            definitions,
            project,
          },
        };
      },
    );
  • The actual implementation of getDefinition in ProjectService.
    public getDefinition(filePath: string, line: number, column: number): DefinitionItem[] {
      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 definitions = this.languageService.getDefinitionAtPosition(normalizedFile, offset) ?? [];
    
      return definitions.map((definition) => {
        return this.toDefinitionItem(definition.fileName, definition.textSpan.start, definition.textSpan.length);
      });
    }
  • Helper function in ProjectServiceCache that fetches definition and metadata.
    public getDefinitionWithMetadata(
      filePath: string,
      line: number,
      column: number,
      options: ProjectLookupOptions,
    ): { definitions: DefinitionItem[]; project: ProjectMetadata } {
      const service = this.getOrCreate({ ...options, file: filePath });
      return {
        definitions: service.getDefinition(filePath, line, column),
        project: service.getProjectMetadata(),
      };
    }
Behavior3/5

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

Annotations are absent, so the description carries the full disclosure burden. It adds crucial behavioral context by specifying '1-based' indexing for coordinates, which prevents off-by-one errors. However, it omits other important behaviors: whether it returns multiple locations (overloads), what happens when no definition is found, or whether it triggers project reload/analysis.

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?

The single sentence is front-loaded with the action ('Resolve') and avoids redundancy. However, given the lack of schema documentation and annotations, the brevity may be excessive rather than efficient—it leaves significant gaps that require inference.

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?

With 5 parameters (2 optional), 0% schema coverage, no annotations, and no output schema, the description is insufficient. It ignores the workspace configuration parameters which are likely critical for monorepo or multi-project contexts, and provides no indication of return value structure or error conditions.

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?

Schema description coverage is 0%, requiring the description to compensate. It partially explains semantics for 'line' and 'column' (1-based) and implies 'file', but completely omits explanation of the two optional parameters 'workspaceRoot' and 'projectTsconfigPath' which likely control project resolution scope and TypeScript configuration.

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 resolves definition locations for symbols using specific coordinates (line/column) in a file. The verb 'Resolve' and resource 'definition locations' are specific, though it doesn't explicitly contrast with the sibling tool 'get_references' (which finds usages rather than declarations).

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 guidance provided on when to use this versus alternatives like 'get_references' or 'get_symbol_summary'. No prerequisites mentioned (e.g., requiring a valid project configuration or when the optional workspaceRoot/projectTsconfigPath parameters should be used).

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