Skip to main content
Glama

navigate_to_line

Jump to a specific line in large files with surrounding context lines for efficient code review and debugging.

Instructions

Jump to a specific line in a large file with surrounding context lines. Highlights the target line.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file
lineNumberYesLine number to navigate to (1-indexed)
contextLinesNoNumber of context lines before and after (default: 5)

Implementation Reference

  • Core implementation of the navigate_to_line tool: verifies file, calculates context lines, reads lines, formats with markers and numbers, returns FileChunk.
    static async navigateToLine(
      filePath: string,
      lineNumber: number,
      contextLines: number = 5
    ): Promise<FileChunk> {
      await this.verifyFile(filePath);
    
      const metadata = await this.getMetadata(filePath);
    
      if (lineNumber < 1 || lineNumber > metadata.totalLines) {
        throw new Error(`Line number ${lineNumber} out of range (1-${metadata.totalLines})`);
      }
    
      const startLine = Math.max(1, lineNumber - contextLines);
      const endLine = Math.min(metadata.totalLines, lineNumber + contextLines);
    
      const lines = await this.readLines(filePath, startLine, endLine);
      const content = lines
        .map((line, idx) => {
          const num = startLine + idx;
          const marker = num === lineNumber ? '→ ' : '  ';
          return `${marker}${num}: ${line}`;
        })
        .join('\n');
    
      return {
        content,
        startLine,
        endLine,
        totalLines: metadata.totalLines,
        chunkIndex: Math.floor((lineNumber - 1) / 500),
        totalChunks: Math.ceil(metadata.totalLines / 500),
        filePath,
        byteOffset: 0,
        byteSize: Buffer.byteLength(content, 'utf-8'),
      };
    }
  • src/server.ts:176-197 (registration)
    Registration of the 'navigate_to_line' tool in the MCP server's tool list, including name, description, and input schema definition.
    {
      name: 'navigate_to_line',
      description: 'Jump to a specific line in a large file with surrounding context lines. Highlights the target line.',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Absolute path to the file',
          },
          lineNumber: {
            type: 'number',
            description: 'Line number to navigate to (1-indexed)',
          },
          contextLines: {
            type: 'number',
            description: 'Number of context lines before and after (default: 5)',
          },
        },
        required: ['filePath', 'lineNumber'],
      },
    },
  • Input schema definition for the navigate_to_line tool, specifying parameters and types for MCP validation.
    inputSchema: {
      type: 'object',
      properties: {
        filePath: {
          type: 'string',
          description: 'Absolute path to the file',
        },
        lineNumber: {
          type: 'number',
          description: 'Line number to navigate to (1-indexed)',
        },
        contextLines: {
          type: 'number',
          description: 'Number of context lines before and after (default: 5)',
        },
      },
      required: ['filePath', 'lineNumber'],
  • MCP server wrapper handler that extracts arguments, calls FileHandler.navigateToLine, and formats response as MCP content.
    private async handleNavigateToLine(
      args: Record<string, unknown>
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const filePath = args.filePath as string;
      const lineNumber = args.lineNumber as number;
      const contextLines = (args.contextLines as number) || this.config.defaultContextLines;
    
      const chunk = await FileHandler.navigateToLine(filePath, lineNumber, contextLines);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(chunk, null, 2),
          },
        ],
      };
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses key behaviors like providing surrounding context lines and highlighting the target line, which are useful beyond basic navigation. However, it does not mention potential issues like file access permissions, error handling for invalid line numbers, or performance implications for very large files.

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, efficient sentence that front-loads the core functionality ('Jump to a specific line') and adds essential details ('with surrounding context lines' and 'Highlights the target line') without any wasted words. Every part earns its place.

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 (navigation with context) and no annotations or output schema, the description is adequate but has gaps. It covers the basic operation but lacks details on return values (e.g., what is returned when navigating), error conditions, or how highlighting is implemented, which could be important for an AI agent.

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?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds minimal value beyond the schema by implying context lines are displayed around the target line, but does not provide additional syntax or format details. This meets the baseline for high schema coverage.

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 specific action ('Jump to a specific line') and resource ('in a large file'), distinguishing it from siblings like 'read_large_file_chunk' or 'search_in_large_file'. It specifies the unique functionality of navigating to a line with surrounding context and highlighting.

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 for line navigation in large files, but does not explicitly state when to use this tool versus alternatives like 'read_large_file_chunk' for reading chunks or 'search_in_large_file' for searching. It provides some context but lacks clear exclusions or named alternatives.

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/willianpinho/large-file-mcp'

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