Skip to main content
Glama

stream_large_file

Process large files efficiently by streaming them in manageable chunks without loading entire files into memory, enabling step-by-step handling of oversized data.

Instructions

Stream a large file in chunks. Returns multiple chunks for processing very large files efficiently.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the file
chunkSizeNoChunk size in bytes (default: 65536 - 64KB)
startOffsetNoStarting byte offset (default: 0)
maxBytesNoMaximum bytes to stream (optional)
maxChunksNoMaximum number of chunks to return (default: 10)

Implementation Reference

  • The primary handler function for the 'stream_large_file' tool. It extracts parameters from arguments, uses FileHandler.streamFile to generate chunks, limits to maxChunks, and formats the response as MCP tool content.
    private async handleStreamFile(
      args: Record<string, unknown>
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const filePath = args.filePath as string;
      const chunkSize = (args.chunkSize as number) || 64 * 1024;
      const startOffset = args.startOffset as number | undefined;
      const maxBytes = args.maxBytes as number | undefined;
      const maxChunks = (args.maxChunks as number) || 10;
    
      const chunks: string[] = [];
      let chunkCount = 0;
    
      for await (const chunk of FileHandler.streamFile(filePath, {
        chunkSize,
        startOffset,
        maxBytes,
      })) {
        chunks.push(chunk);
        chunkCount++;
        if (chunkCount >= maxChunks) break;
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              totalChunks: chunks.length,
              chunks,
              note: chunks.length >= maxChunks
                ? 'Reached maxChunks limit. Increase maxChunks or use startOffset to continue.'
                : 'All chunks returned.',
            }, null, 2),
          },
        ],
      };
    }
  • The input schema and metadata for the 'stream_large_file' tool, defining parameters, descriptions, and requirements. This is returned by getTools() for tool discovery.
    {
      name: 'stream_large_file',
      description: 'Stream a large file in chunks. Returns multiple chunks for processing very large files efficiently.',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Absolute path to the file',
          },
          chunkSize: {
            type: 'number',
            description: 'Chunk size in bytes (default: 65536 - 64KB)',
          },
          startOffset: {
            type: 'number',
            description: 'Starting byte offset (default: 0)',
          },
          maxBytes: {
            type: 'number',
            description: 'Maximum bytes to stream (optional)',
          },
          maxChunks: {
            type: 'number',
            description: 'Maximum number of chunks to return (default: 10)',
          },
        },
        required: ['filePath'],
      },
    },
  • src/server.ts:260-261 (registration)
    The switch case in handleToolCall that routes calls to the 'stream_large_file' tool to its handler function.
    case 'stream_large_file':
      return this.handleStreamFile(args);
  • The core streaming utility in FileHandler class. Creates a Node.js ReadStream with configurable chunk size, offset, and limits, yielding chunks as an async generator.
    static async *streamFile(
      filePath: string,
      options: StreamOptions = {}
    ): AsyncGenerator<string> {
      await this.verifyFile(filePath);
    
      const chunkSize = options.chunkSize || 64 * 1024; // 64KB default
      const encoding = options.encoding || 'utf-8';
    
      const stream = fs.createReadStream(filePath, {
        encoding,
        start: options.startOffset,
        end: options.maxBytes ?
          (options.startOffset || 0) + options.maxBytes :
          undefined,
        highWaterMark: chunkSize,
      });
    
      for await (const chunk of stream) {
        yield chunk;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool streams files in chunks and returns multiple chunks, but lacks details on permissions, error handling, rate limits, or whether it's read-only or destructive. For a tool handling large files, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise with two sentences that efficiently convey the core functionality and benefit. It's front-loaded with the main purpose, though it could be slightly more structured by explicitly mentioning key parameters or use cases. Overall, it avoids unnecessary verbosity.

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 5 parameters, no annotations, and no output schema, the description is moderately complete. It covers the basic purpose and output format (multiple chunks) but lacks details on behavioral traits, error cases, or how to handle the streamed data. For a tool with this complexity, it should provide more context to guide effective use.

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 description adds no parameter-specific information beyond what's in the input schema, which has 100% coverage. It implies chunking behavior but doesn't explain parameter interactions or semantics like how 'maxBytes' and 'maxChunks' relate. With high schema coverage, the baseline is 3, as the schema does the heavy lifting.

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: 'Stream a large file in chunks' specifies the verb (stream) and resource (large file), and 'Returns multiple chunks for processing very large files efficiently' explains the output and efficiency benefit. However, it doesn't explicitly differentiate from sibling tools like 'read_large_file_chunk' or 'get_file_structure', which might handle similar file operations.

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 mentions processing 'very large files efficiently' but doesn't specify scenarios, prerequisites, or exclusions compared to siblings like 'read_large_file_chunk' or 'search_in_large_file'. This lack of contextual direction leaves the agent to infer usage.

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