Skip to main content
Glama

navigate_to_line

Jump to specific lines in large files with surrounding context. Quickly locate and highlight target lines without loading entire files into memory.

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

  • Main handler function that implements the navigate_to_line tool logic: verifies file, computes context range, reads lines, formats output with line numbers and arrow marker on target line, returns structured 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'), }; }
  • Server-side wrapper handler for navigate_to_line: extracts arguments, calls FileHandler.navigateToLine, formats response as MCP tool output.
    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), }, ], }; }
  • src/server.ts:177-197 (registration)
    Tool registration in getTools(): defines name, description, and input schema for navigate_to_line.
    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 requirements.
    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'],

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