Skip to main content
Glama

get_file_summary

Generate statistical summaries for files by analyzing line counts, character statistics, and word frequencies to understand file structure and content metrics.

Instructions

Get comprehensive statistical summary of a file including line stats, character stats, and word count.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file

Implementation Reference

  • Core handler implementing the get_file_summary tool logic. Streams the file to compute line statistics (empty/non-empty, max/avg length), character type counts (alphabetic, numeric, whitespace, special), and word count for text/markdown files. Returns structured FileSummary.
    static async getSummary(filePath: string): Promise<FileSummary> { await this.verifyFile(filePath); const metadata = await this.getMetadata(filePath); let emptyLines = 0; let maxLength = 0; let totalLength = 0; let alphabetic = 0; let numeric = 0; let whitespace = 0; let special = 0; let wordCount = 0; return new Promise((resolve, reject) => { const stream = fs.createReadStream(filePath); const rl = readline.createInterface({ input: stream, crlfDelay: Infinity, }); rl.on('line', (line) => { if (line.trim() === '') { emptyLines++; } else { wordCount += line.split(/\s+/).filter(w => w.length > 0).length; } maxLength = Math.max(maxLength, line.length); totalLength += line.length; // Character analysis for (const char of line) { if (/[a-zA-Z]/.test(char)) alphabetic++; else if (/\d/.test(char)) numeric++; else if (/\s/.test(char)) whitespace++; else special++; } }); rl.on('close', () => { const total = alphabetic + numeric + whitespace + special; resolve({ metadata, lineStats: { total: metadata.totalLines, empty: emptyLines, nonEmpty: metadata.totalLines - emptyLines, maxLength, avgLength: metadata.totalLines > 0 ? Math.round(totalLength / metadata.totalLines) : 0, }, charStats: { total, alphabetic, numeric, whitespace, special, }, wordCount: metadata.fileType === FileType.TEXT || metadata.fileType === FileType.MARKDOWN ? wordCount : undefined, }); }); rl.on('error', reject); }); }
  • MCP server wrapper handler for get_file_summary. Extracts filePath from arguments, calls FileHandler.getSummary, and formats the result as JSON text content response.
    private async handleGetSummary( args: Record<string, unknown> ): Promise<{ content: Array<{ type: string; text: string }> }> { const filePath = args.filePath as string; const summary: FileSummary = await FileHandler.getSummary(filePath); return { content: [ { type: 'text', text: JSON.stringify(summary, null, 2), }, ], }; }
  • src/server.ts:198-211 (registration)
    Tool registration in getTools() method, defining name, description, and input schema (requires filePath string).
    { name: 'get_file_summary', description: 'Get comprehensive statistical summary of a file including line stats, character stats, and word count.', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Absolute path to the file', }, }, required: ['filePath'], }, },
  • Output schema definition for the tool result: FileSummary interface specifying structure of metadata, lineStats, charStats, optional wordCount and patterns.
    export interface FileSummary { /** File metadata */ metadata: FileMetadata; /** Line statistics */ lineStats: { total: number; empty: number; nonEmpty: number; maxLength: number; avgLength: number; }; /** Character statistics */ charStats: { total: number; alphabetic: number; numeric: number; whitespace: number; special: number; }; /** Word count (for text files) */ wordCount?: number; /** Top file patterns (e.g., most common lines) */ patterns?: Array<{ pattern: string; count: number }>; }
  • src/server.ts:258-259 (registration)
    Dispatcher switch case in handleToolCall that routes 'get_file_summary' calls to the handleGetSummary method.
    case 'get_file_summary': return this.handleGetSummary(args);

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