Skip to main content
Glama
xxczaki

Local History MCP Server

by xxczaki

get_history_stats

Retrieve statistics about local file history, including total files and entries, to monitor version tracking and data recovery capabilities.

Instructions

Get statistics about the local history (total files, entries, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function for the 'get_history_stats' tool. It delegates to the history parser for stats computation and formats the response as MCP-compliant content with statistics display.
    private async getHistoryStats() {
    	const stats = this.historyParser.getHistoryStats();
    
    	return {
    		content: [
    			{
    				type: 'text',
    				text:
    					'📊 Local History Statistics\n\n' +
    					`History directory: ${stats.historyDirPath}\n` +
    					`Directory exists: ${stats.historyDirExists ? '✅' : '❌'}\n` +
    					`Total files with history: ${stats.totalFiles}\n` +
    					`Total history entries: ${stats.totalEntries}\n` +
    					`Average entries per file: ${stats.totalFiles > 0 ? (stats.totalEntries / stats.totalFiles).toFixed(1) : 'N/A'}`,
    			},
    		],
    	};
    }
  • Core helper method in VSCodeHistoryParser class that calculates the actual history statistics by aggregating all file histories.
    public getHistoryStats(): {
    	totalFiles: number;
    	totalEntries: number;
    	historyDirExists: boolean;
    	historyDirPath: string;
    } {
    	const histories = this.getAllFileHistories();
    	const totalEntries = histories.reduce(
    		(sum, history) => sum + history.entries.length,
    		0,
    	);
    
    	return {
    		totalFiles: histories.length,
    		totalEntries,
    		historyDirExists: this.historyDirectoryExists(),
    		historyDirPath: this.historyDir,
    	};
    }
  • Input schema and metadata (name, description) for the 'get_history_stats' tool, defined in the ListTools response. No input parameters required.
    {
    	name: 'get_history_stats',
    	description:
    		'Get statistics about the local history (total files, entries, etc.)',
    	inputSchema: {
    		type: 'object',
    		properties: {},
    		additionalProperties: false,
    	},
    },
  • src/index.ts:162-272 (registration)
    Registration of the CallTool request handler, including the switch case that dispatches 'get_history_stats' calls to the handler method.
    	this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
    		try {
    			const { name, arguments: args } = request.params;
    
    			switch (name) {
    				case 'list_history_files':
    					return await this.listHistoryFiles();
    
    				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);
    				}
    
    				case 'get_history_entry': {
    					if (
    						!args ||
    						typeof args !== 'object' ||
    						!('filePath' in args) ||
    						!('entryIndex' in args)
    					) {
    						throw new McpError(
    							ErrorCode.InvalidParams,
    							'Missing required parameters: filePath, entryIndex',
    						);
    					}
    					const filePathEntry = args.filePath as string;
    					if (!path.isAbsolute(filePathEntry)) {
    						throw new McpError(
    							ErrorCode.InvalidParams,
    							'filePath must be an absolute path',
    						);
    					}
    					return await this.getHistoryEntry(
    						filePathEntry,
    						args.entryIndex as number,
    					);
    				}
    
    				case 'restore_from_history': {
    					if (
    						!args ||
    						typeof args !== 'object' ||
    						!('filePath' in args) ||
    						!('entryIndex' in args)
    					) {
    						throw new McpError(
    							ErrorCode.InvalidParams,
    							'Missing required parameters: filePath, entryIndex',
    						);
    					}
    					const filePathRestore = args.filePath as string;
    					if (!path.isAbsolute(filePathRestore)) {
    						throw new McpError(
    							ErrorCode.InvalidParams,
    							'filePath must be an absolute path',
    						);
    					}
    					return await this.restoreFromHistory(
    						filePathRestore,
    						args.entryIndex as number,
    						((args as Record<string, unknown>).createBackup as boolean) ??
    							true,
    					);
    				}
    
    				case 'get_history_stats':
    					return await this.getHistoryStats();
    
    				case 'search_history_content':
    					if (!args || typeof args !== 'object' || !('searchTerm' in args)) {
    						throw new McpError(
    							ErrorCode.InvalidParams,
    							'Missing required parameter: searchTerm',
    						);
    					}
    					return await this.searchHistoryContent(
    						args.searchTerm as string,
    						((args as Record<string, unknown>).caseSensitive as boolean) ??
    							false,
    					);
    
    				default:
    					throw new McpError(
    						ErrorCode.MethodNotFound,
    						`Unknown tool: ${name}`,
    					);
    			}
    		} catch (error) {
    			if (error instanceof McpError) {
    				throw error;
    			}
    
    			throw new McpError(
    				ErrorCode.InternalError,
    				`Tool execution failed: ${error instanceof Error ? error.message : String(error)}`,
    			);
    		}
    	});
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions 'Get statistics' but doesn't disclose behavioral traits such as whether this is a read-only operation, performance characteristics (e.g., fast aggregation vs. slow computation), or potential side effects (e.g., caching). For a tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Get statistics about the local history') and adds specific examples ('total files, entries, etc.') without unnecessary elaboration. Every word earns its place, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 0 parameters, no annotations, and no output schema, the description is minimally adequate. It states what the tool does but lacks details on return format (e.g., what 'etc.' includes), behavioral context, or usage guidelines. For a simple stats tool, this is borderline viable but leaves gaps in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description adds value by specifying what statistics are retrieved ('total files, entries, etc.'), which clarifies the output semantics beyond the empty schema. This compensates adequately for the lack of parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('statistics about the local history'), specifying what kind of data is retrieved (total files, entries, etc.). It distinguishes from siblings like 'get_file_history' or 'get_history_entry' by focusing on aggregated statistics rather than individual records. However, it doesn't explicitly contrast with all siblings (e.g., 'search_history_content' might also return statistical data).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives is provided. The description implies usage for statistical overviews, but it doesn't state when to prefer this over 'list_history_files' for file counts or 'search_history_content' for filtered statistics. There's no mention of prerequisites, timing considerations, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/xxczaki/local-history-mcp'

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