fetch-chunk
Retrieve specific cached chunks from a changeMode response using a cache key and chunk index. Ensures consistent access to partial responses in the Gemini CLI MCP Server environment.
Instructions
Retrieves cached chunks from a changeMode response. Use this to get subsequent chunks after receiving a partial changeMode response.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cacheKey | Yes | The cache key provided in the initial changeMode response | |
| chunkIndex | Yes | Which chunk to retrieve (1-based index) |
Input Schema (JSON Schema)
{
"properties": {
"cacheKey": {
"description": "The cache key provided in the initial changeMode response",
"type": "string"
},
"chunkIndex": {
"description": "Which chunk to retrieve (1-based index)",
"minimum": 1,
"type": "number"
}
},
"required": [
"cacheKey",
"chunkIndex"
],
"type": "object"
}
Implementation Reference
- lib/fixed-mcp-tool.js:353-387 (handler)Main execution handler for the 'fetch-chunk' tool. Parses arguments, calls getChunkedEdits helper, formats the chunk response with instructions for fetching more chunks if available.case "fetch-chunk": const { cacheKey, chunkIndex: fetchChunkIndex } = args; console.error('[GMCPT] fetch-chunk tool called with cacheKey: ' + cacheKey + ', chunkIndex: ' + fetchChunkIndex); try { const chunkResult = getChunkedEdits(cacheKey, parseInt(fetchChunkIndex)); // Format the chunk information const chunkInfo = `CHUNK ${chunkResult.chunk}/${chunkResult.totalChunks} (Cache Key: ${chunkResult.cacheKey})\n\n${chunkResult.content}`; if (chunkResult.hasMore) { const nextChunk = chunkResult.chunk + 1; const remainingChunks = chunkResult.totalChunks - chunkResult.chunk; return { content: [{ type: "text", text: chunkInfo + `\n\n[Use fetch-chunk tool with cacheKey "${chunkResult.cacheKey}" and chunkIndex ${nextChunk}-${chunkResult.totalChunks} to get remaining ${remainingChunks} chunks]` }] }; } else { return { content: [{ type: "text", text: chunkInfo + "\n\n[This is the final chunk]" }] }; } } catch (error) { return { content: [{ type: "text", text: `Error retrieving chunk: ${error.message}` }] }; }
- lib/fixed-mcp-tool.js:183-197 (schema)Input schema definition for the fetch-chunk tool, specifying required cacheKey (string) and chunkIndex (number >=1).inputSchema: { type: "object", properties: { cacheKey: { type: "string", description: "The cache key provided in the initial changeMode response" }, chunkIndex: { type: "number", minimum: 1, description: "Which chunk to retrieve (1-based index)" } }, required: ["cacheKey", "chunkIndex"] }
- lib/fixed-mcp-tool.js:180-198 (registration)Tool registration object including name, description, and schema, added to the tools array returned by ListToolsRequestHandler.{ name: "fetch-chunk", description: "Retrieves cached chunks from a changeMode response. Use this to get subsequent chunks after receiving a partial changeMode response.", inputSchema: { type: "object", properties: { cacheKey: { type: "string", description: "The cache key provided in the initial changeMode response" }, chunkIndex: { type: "number", minimum: 1, description: "Which chunk to retrieve (1-based index)" } }, required: ["cacheKey", "chunkIndex"] } },
- lib/fixed-geminiExecutor.js:368-391 (helper)Helper function that retrieves the specific chunk from the in-memory chunkCache based on cacheKey and 1-based chunkIndex, returning chunk details including if more chunks available.export function getChunkedEdits(cacheKey, chunkIndex) { try { const chunks = getChunks(cacheKey); if (!chunks || chunks.length === 0) { throw new Error('No cached chunks found for the provided cache key'); } const chunk = chunks[chunkIndex - 1]; // Convert to 0-based index if (!chunk) { throw new Error(`Chunk ${chunkIndex} not found. Available chunks: 1-${chunks.length}`); } return { content: chunk, chunk: chunkIndex, totalChunks: chunks.length, cacheKey: cacheKey, hasMore: chunkIndex < chunks.length }; } catch (error) { console.error(`Failed to retrieve chunk: ${error.message}`); throw error; } }
- lib/fixed-geminiExecutor.js:15-68 (helper)In-memory chunkCache (Map) and supporting functions cacheChunks/getChunks used by getChunkedEdits and chunking logic in executeGeminiCLI.const chunkCache = new Map(); // Function to get PowerShell executable based on platform function getPowerShellExecutable(customPath = null) { // If custom path is provided, use it directly if (customPath) { console.log(`[GMCPT] Using custom PowerShell path: ${customPath}`); return customPath; } if (process.platform === 'win32') { // Try multiple PowerShell paths to ensure compatibility const possiblePaths = [ 'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', 'powershell.exe', 'pwsh.exe' ]; // Try to find a working PowerShell executable for (const path of possiblePaths) { try { if (path.includes(':\\')) { // Use full path directly console.log(`[GMCPT] Using full path: ${path}`); return path; } else { // Use relative path console.log(`[GMCPT] Will try relative path: ${path}`); return path; } } catch (error) { console.log(`[GMCPT] Failed to check path ${path}: ${error.message}`); continue; } } // Fallback to the first full path console.log(`[GMCPT] Using fallback PowerShell path: ${possiblePaths[0]}`); return possiblePaths[0]; } // On other platforms, use pwsh (PowerShell Core) return 'pwsh'; } const POWERSHELL_EXECUTABLE = getPowerShellExecutable(); console.log(`[GMCPT] Using PowerShell executable: ${POWERSHELL_EXECUTABLE}`); function cacheChunks(key, chunks) { chunkCache.set(key, chunks); } function getChunks(key) { return chunkCache.get(key) || []; }