get_file_history
Retrieve the full history of a specific file to track changes, restore previous versions, or enhance context awareness. Provide the file's absolute path for accurate results.
Instructions
Get the complete history for a specific file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | The path to the file. Please provide an absolute path (e.g., "/Users/user/project/biome.json") for reliable matching. |
Implementation Reference
- src/index.ts:62-77 (registration)Registration of the 'get_file_history' tool in the ListToolsRequestSchema handler, including the tool name, description, and input schema definition.{ name: 'get_file_history', description: 'Get the complete history for a specific file', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'The path to the file. Please provide an absolute path (e.g., "/Users/user/project/biome.json") for reliable matching.', }, }, required: ['filePath'], additionalProperties: false, }, },
- src/index.ts:170-185 (handler)Dispatch handler in the CallToolRequestSchema switch statement: validates the filePath argument and delegates to the private getFileHistory method.case 'get_file_history': { if (!args || typeof args !== 'object' || !('filePath' in args)) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameter: filePath', ); } const filePathHistory = args.filePath as string; if (!path.isAbsolute(filePathHistory)) { throw new McpError( ErrorCode.InvalidParams, 'filePath must be an absolute path', ); } return await this.getFileHistory(filePathHistory); }
- src/index.ts:302-336 (handler)Primary handler function that executes the tool logic: retrieves the file history using the parser, formats a textual summary of all entries, or reports no history found.private async getFileHistory(filePath: string) { const history = this.historyParser.findHistoryByFilePath(filePath); if (!history) { return { content: [ { type: 'text', text: `No local history found for: ${filePath}`, }, ], }; } const entriesText = history.entries .map( (entry, index) => `[${index}] ${new Date(entry.timestamp).toLocaleString()}\n` + ` File: ${entry.relativePath}\n` + ` Size: ${entry.content.length} characters`, ) .join('\n\n'); return { content: [ { type: 'text', text: `History for: ${history.originalFilePath}\n` + `Total entries: ${history.entries.length}\n\n` + `History entries (most recent first):\n\n${entriesText}`, }, ], }; }
- src/history-parser.ts:231-254 (helper)Supporting utility method in VSCodeHistoryParser that finds and returns the FileHistory object matching the given file path (with URI handling and normalization).public findHistoryByFilePath(targetFilePath: string): FileHistory | null { const histories = this.getAllFileHistories(); // Convert URI to path if needed const cleanTargetPath = uriToPath(targetFilePath); const normalizedTarget = path.resolve(cleanTargetPath); for (const history of histories) { const cleanHistoryPath = uriToPath(history.originalFilePath); const normalizedHistory = path.resolve(cleanHistoryPath); // Exact match if (normalizedTarget === normalizedHistory) { return history; } // Case-insensitive match (for case-insensitive filesystems) if (normalizedTarget.toLowerCase() === normalizedHistory.toLowerCase()) { return history; } } return null; }