get_file_info
Retrieve file metadata like size and line count without accessing file contents. Helps determine optimal reading strategies for large files by analyzing file characteristics first.
Instructions
Get file metadata without reading contents. Useful to check size/line count before reading. For large files, provides reading strategy recommendations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path to get info about |
Implementation Reference
- index.ts:452-499 (handler)Main handler for 'get_file_info' tool. Validates input, retrieves file stats, detects if binary, identifies language, counts lines, and provides reading strategy for large files using imported helpers.case 'get_file_info': { const schema = z.object({ path: z.string() }); const { path } = schema.parse(args); const validatedPath = await validatePath(path); const stats = await getFileStats(validatedPath); const isBinary = await isBinaryFile(validatedPath); const language = detectLanguage(validatedPath); let lines: number | undefined; let readingStrategy: any = undefined; if (!isBinary && stats.isFile) { try { const content = await readFileContent(validatedPath); lines = countLines(content); if (shouldPaginate(lines)) { readingStrategy = { recommendation: `File is large (${lines} lines). Suggested approach:`, options: generateReadingSuggestions(lines) }; } } catch { // Ignore read errors } } return { content: [{ type: 'text', text: JSON.stringify({ path: validatedPath, size: { bytes: stats.size, readable: `${stats.size} bytes` }, lines, type: stats.isDirectory ? 'directory' : 'file', language, isBinary, lastModified: stats.modified.toISOString(), permissions: stats.permissions, readingStrategy }, null, 2) }] }; }
- index.ts:235-248 (registration)Registration of the 'get_file_info' tool in the tools array, including name, description, and input schema definition.{ name: 'get_file_info', description: 'Get file metadata without reading contents. Useful to check size/line count before reading. For large files, provides reading strategy recommendations.', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'File path to get info about' } }, required: ['path'] } },
- index.ts:238-247 (schema)Input schema definition for the 'get_file_info' tool.inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'File path to get info about' } }, required: ['path'] }