Skip to main content
Glama
orzcls

Gemini CLI MCP Server

by orzcls

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

NameRequiredDescriptionDefault
cacheKeyYesThe cache key provided in the initial changeMode response
chunkIndexYesWhich 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

  • 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}` }] }; }
  • 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"] }
  • 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"] } },
  • 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; } }
  • 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) || []; }

Other Tools

Related 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/orzcls/gemini-mcp-tool-windows-fixed'

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