Skip to main content
Glama

get_file_structure

Analyze file structure to obtain metadata including line statistics, chunk size recommendations, and sample content from file start and end.

Instructions

Analyze file structure and get comprehensive metadata including line statistics, recommended chunk size, and samples from start and end.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file

Implementation Reference

  • Core handler function that implements the logic for analyzing file structure: computes metadata, line statistics (empty/non-empty, max/avg length), recommended chunk size, and samples from beginning and end of the file.
    static async getStructure(filePath: string): Promise<FileStructure> {
      await this.verifyFile(filePath);
    
      const metadata = await this.getMetadata(filePath);
    
      let emptyLines = 0;
      let maxLineLength = 0;
      let totalLineLength = 0;
      const sampleStart: string[] = [];
      let lineCount = 0;
      const endBuffer: string[] = [];
    
      return new Promise((resolve, reject) => {
        const stream = fs.createReadStream(filePath);
        const rl = readline.createInterface({
          input: stream,
          crlfDelay: Infinity,
        });
    
        rl.on('line', (line) => {
          lineCount++;
    
          if (line.trim() === '') emptyLines++;
          maxLineLength = Math.max(maxLineLength, line.length);
          totalLineLength += line.length;
    
          // Sample start
          if (sampleStart.length < this.SAMPLE_LINES) {
            sampleStart.push(line);
          }
    
          // Sample end (keep last N lines)
          endBuffer.push(line);
          if (endBuffer.length > this.SAMPLE_LINES) {
            endBuffer.shift();
          }
        });
    
        rl.on('close', () => {
          const recommendedChunkSize = this.getOptimalChunkSize(
            metadata.fileType,
            metadata.totalLines
          );
    
          resolve({
            metadata,
            lineStats: {
              total: metadata.totalLines,
              empty: emptyLines,
              nonEmpty: metadata.totalLines - emptyLines,
              maxLineLength,
              avgLineLength: lineCount > 0 ? Math.round(totalLineLength / lineCount) : 0,
            },
            recommendedChunkSize,
            estimatedChunks: Math.ceil(metadata.totalLines / recommendedChunkSize),
            sampleStart,
            sampleEnd: endBuffer,
          });
        });
    
        rl.on('error', reject);
      });
    }
  • src/server.ts:162-175 (registration)
    Registration of the 'get_file_structure' tool in the MCP server's tool list, including name, description, and input schema.
    {
      name: 'get_file_structure',
      description: 'Analyze file structure and get comprehensive metadata including line statistics, recommended chunk size, and samples from start and end.',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Absolute path to the file',
          },
        },
        required: ['filePath'],
      },
    },
  • Output type definition (FileStructure) returned by the get_file_structure tool, defining the structure of the response.
    export interface FileStructure {
      /** File metadata */
      metadata: FileMetadata;
      /** Line count distribution */
      lineStats: {
        total: number;
        empty: number;
        nonEmpty: number;
        maxLineLength: number;
        avgLineLength: number;
      };
      /** Recommended chunk size for this file */
      recommendedChunkSize: number;
      /** Total chunks with recommended size */
      estimatedChunks: number;
      /** Sample lines from start */
      sampleStart: string[];
      /** Sample lines from end */
      sampleEnd: string[];
    }
  • MCP server wrapper handler for get_file_structure: handles caching, delegates to FileHandler.getStructure, and formats response as MCP content.
    private async handleGetStructure(
      args: Record<string, unknown>
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const filePath = args.filePath as string;
    
      const cacheKey = `structure:${filePath}`;
      let structure = this.metadataCache.get(cacheKey);
    
      if (!structure) {
        structure = await FileHandler.getStructure(filePath);
        this.metadataCache.set(cacheKey, structure);
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(structure, null, 2),
          },
        ],
      };
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the tool 'analyzes' and 'gets' metadata, implying a read-only operation, but doesn't clarify if it requires specific permissions, has rate limits, or what happens with invalid file paths. It lists output components (line statistics, chunk size, samples) but doesn't describe format, depth, or potential errors, leaving significant gaps for a tool with behavioral implications.

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 action ('Analyze file structure and get comprehensive metadata') and specifies key output components. There's zero waste—every phrase earns its place by clarifying the tool's scope without redundancy or unnecessary elaboration.

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?

Given the tool's complexity (analyzing structure with metadata like line statistics and chunk size), no annotations, and no output schema, the description is incomplete. It lists output components but doesn't explain return values, error handling, or behavioral traits. For a tool that likely involves file I/O and analysis, more context on permissions, performance, or output structure is needed to be fully helpful.

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?

The input schema has 100% description coverage, with 'filePath' documented as 'Absolute path to the file'. The description adds no additional parameter semantics beyond what the schema provides, such as format examples, constraints, or edge cases. With high schema coverage, the baseline is 3, as the description doesn't compensate but doesn't detract either.

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's purpose with specific verbs ('analyze file structure', 'get comprehensive metadata') and identifies the resource ('file'). It distinguishes from siblings like 'get_file_summary' by specifying detailed metadata components (line statistics, chunk size, samples). However, it doesn't explicitly contrast with 'navigate_to_line' or 'read_large_file_chunk' for structural analysis vs. content access.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer 'get_file_summary' for high-level info, 'navigate_to_line' for specific line access, or 'read_large_file_chunk' for content reading. There are no explicit when/when-not instructions or prerequisites, leaving usage context implied at best.

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