clearFileCache
Clear the cached data for an Excel file by providing its absolute path. This forces the server to re-read the file on the next request.
Instructions
Clear cached data for the specified Excel file
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fileAbsolutePath | Yes | The absolute path of the Excel file to clear from cache |
Implementation Reference
- src/tools/cacheTools.ts:9-49 (handler)Handler function for clearFileCache tool. Normalizes the file path, then calls workbookCache.delete() to remove the cached workbook. Returns success/error JSON responses.
async (params: { fileAbsolutePath: string }) => { try { const normalizedPath = await normalizePath(params.fileAbsolutePath); if (normalizedPath === 'error') { return { content: [{ type: "text", text: JSON.stringify({ error: `Invalid file path: ${params.fileAbsolutePath}`, suggestion: "Please verify the file path and name" }) }] }; } const deleted = workbookCache.delete(normalizedPath); return { content: [{ type: "text", text: JSON.stringify({ success: true, message: deleted ? `Cache cleared successfully for file: ${normalizedPath}` : `No cache found for file: ${normalizedPath}` }) }] }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ error: `Failed to clear cache: ${error}`, suggestion: "Please verify the file path" }) }] }; } } - src/tools/cacheTools.ts:6-8 (schema)Input schema for clearFileCache: requires 'fileAbsolutePath' (string) describing the absolute path of the Excel file to clear from cache.
{ fileAbsolutePath: z.string().describe("The absolute path of the Excel file to clear from cache") }, - src/tools/cacheTools.ts:4-50 (registration)Registration of the 'clearFileCache' tool via server.tool() with description and input schema, exported as part of cacheTools function.
export const cacheTools = (server: any) => { server.tool("clearFileCache", 'Clear cached data for the specified Excel file', { fileAbsolutePath: z.string().describe("The absolute path of the Excel file to clear from cache") }, async (params: { fileAbsolutePath: string }) => { try { const normalizedPath = await normalizePath(params.fileAbsolutePath); if (normalizedPath === 'error') { return { content: [{ type: "text", text: JSON.stringify({ error: `Invalid file path: ${params.fileAbsolutePath}`, suggestion: "Please verify the file path and name" }) }] }; } const deleted = workbookCache.delete(normalizedPath); return { content: [{ type: "text", text: JSON.stringify({ success: true, message: deleted ? `Cache cleared successfully for file: ${normalizedPath}` : `No cache found for file: ${normalizedPath}` }) }] }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ error: `Failed to clear cache: ${error}`, suggestion: "Please verify the file path" }) }] }; } } ); - src/index.ts:25-25 (registration)Invocation of cacheTools(server) to register all cache-related tools including clearFileCache on the MCP server.
cacheTools(server); - src/utils/workbookCache.ts:66-69 (helper)The delete() method on WorkbookCache class that actually removes the cached workbook entry by file path. Returns boolean indicating whether deletion occurred.
delete(filePathWithName: string): boolean { if (!this.cache.has(filePathWithName)) return false return this.cache.delete(filePathWithName) }