search_history_content
Find specific text across all file history snapshots to locate previous versions or recover content from Cursor/VS Code Local History.
Instructions
Search for specific content across all history entries
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| searchTerm | Yes | The text to search for in history entries | |
| caseSensitive | No | Whether the search should be case sensitive |
Implementation Reference
- src/index.ts:489-548 (handler)The handler function that searches for the given term across all local history entries, collects matches with details like file path, entry index, timestamp, and match count, and formats the results.private async searchHistoryContent( searchTerm: string, caseSensitive: boolean, ) { const histories = this.historyParser.getAllFileHistories(); const results: Array<{ file: string; entryIndex: number; timestamp: string; matchCount: number; }> = []; const searchRegex = new RegExp( searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), caseSensitive ? 'g' : 'gi', ); for (const history of histories) { history.entries.forEach((entry, index) => { const matches = entry.content.match(searchRegex); if (matches) { results.push({ file: history.originalFilePath, entryIndex: index, timestamp: new Date(entry.timestamp).toLocaleString(), matchCount: matches.length, }); } }); } if (results.length === 0) { return { content: [ { type: 'text', text: `No matches found for "${searchTerm}" in local history.`, }, ], }; } const resultsText = results .map( (result) => `📄 ${result.file}\n` + ` └── Entry ${result.entryIndex} (${result.timestamp})\n` + ` └── ${result.matchCount} match${result.matchCount === 1 ? '' : 'es'}`, ) .join('\n\n'); return { content: [ { type: 'text', text: `🔍 Found ${results.length} entries containing "${searchTerm}":\n\n${resultsText}`, }, ], }; }
- src/index.ts:137-157 (registration)Registration of the tool in the listTools response, including name, description, and input schema definition.{ name: 'search_history_content', description: 'Search for specific content across all history entries', inputSchema: { type: 'object', properties: { searchTerm: { type: 'string', description: 'The text to search for in history entries', }, caseSensitive: { type: 'boolean', description: 'Whether the search should be case sensitive', default: false, }, }, required: ['searchTerm'], additionalProperties: false, }, },
- src/index.ts:141-156 (schema)Input schema defining parameters: searchTerm (required string) and caseSensitive (optional boolean).inputSchema: { type: 'object', properties: { searchTerm: { type: 'string', description: 'The text to search for in history entries', }, caseSensitive: { type: 'boolean', description: 'Whether the search should be case sensitive', default: false, }, }, required: ['searchTerm'], additionalProperties: false, },
- src/index.ts:242-253 (handler)Dispatch handler in the CallToolRequestSchema switch case: validates input arguments and invokes the searchHistoryContent method.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, );