Skip to main content
Glama

fetch-chunk

Retrieves cached data chunks from Google Gemini CLI responses to access complete analysis results when initial responses are partial.

Instructions

Retrieves cached chunks from a changeMode response. Use this to get subsequent chunks after receiving a partial changeMode response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cacheKeyYesThe cache key provided in the initial changeMode response
chunkIndexYesWhich chunk to retrieve (1-based index)

Implementation Reference

  • The main handler function for the 'fetch-chunk' tool. It retrieves cached code edit chunks using the provided cacheKey and chunkIndex, validates inputs, formats the response, and handles errors like cache misses or invalid indices.
      execute: async (args: any, onProgress?: (newOutput: string) => void): Promise<string> => {
        const { cacheKey, chunkIndex } = args;
        
        Logger.toolInvocation('fetch-chunk', args);
        Logger.debug(`Fetching chunk ${chunkIndex} with cache key: ${cacheKey}`);
        
        // Retrieve cached chunks
        const chunks = getChunks(cacheKey);
        
        if (!chunks) {
          return `❌ Cache miss: No chunks found for cache key "${cacheKey}". 
    
      Possible reasons:
      1. The cache key is incorrect, Have you ran ask-gemini with changeMode enabled?
      2. The cache has expired (10 minute TTL)
      3. The MCP server was restarted and the file-based cache was cleared
    
    Please re-run the original changeMode request to regenerate the chunks.`;
        }
        
        // Validate chunk index
        if (chunkIndex < 1 || chunkIndex > chunks.length) {
          return `❌ Invalid chunk index: ${chunkIndex}
    
    Available chunks: 1 to ${chunks.length}
    You requested: ${chunkIndex}
    
    Please use a valid chunk index.`;
        }
        
        // Get the requested chunk
        const chunk = chunks[chunkIndex - 1];
        
        // Format the response
        let result = formatChangeModeResponse(
          chunk.edits,
          { current: chunkIndex, total: chunks.length, cacheKey }
        );
        
        // Add summary for first chunk
        if (chunkIndex === 1 && chunks.length > 1) {
          const allEdits = chunks.flatMap(c => c.edits);
          result = summarizeChangeModeEdits(allEdits, true) + '\n\n' + result;
        }
        
        Logger.debug(`Returning chunk ${chunkIndex} of ${chunks.length} with ${chunk.edits.length} edits`);
        
        return result;
      }
  • Zod input schema defining the parameters for the fetch-chunk tool: cacheKey (string) and chunkIndex (number >=1). This schema is used for input validation in the tool definition.
    const inputSchema = z.object({
      cacheKey: z.string().describe("The cache key provided in the initial changeMode response"),
      chunkIndex: z.number().min(1).describe("Which chunk to retrieve (1-based index)")
    });
  • Registration of the fetchChunkTool into the central toolRegistry array, making it available for use in the MCP server.
    toolRegistry.push(
      askGeminiTool,
      pingTool,
      helpTool,
      brainstormTool,
      fetchChunkTool,
      timeoutTestTool
    );
  • src/tools/index.ts:6-6 (registration)
    Import statement that brings the fetchChunkTool definition into the index file for registration.
    import { fetchChunkTool } from './fetch-chunk.tool.js';

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/jamubc/gemini-mcp-tool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server