analyze_file_changes
Analyze specific file changes across git branches to track modifications and generate detailed reports for repository forensic analysis.
Instructions
Analyze changes to specific files across branches
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repoPath | Yes | Path to git repository | |
| branches | Yes | Branches to analyze | |
| files | Yes | Files to analyze | |
| outputPath | Yes | Path to write analysis output |
Implementation Reference
- src/index.ts:294-322 (handler)The primary handler function for the 'analyze_file_changes' tool. Processes input arguments to analyze changes in specified files across branches: retrieves git history, analyzes conflicts, generates summary, writes JSON output, and returns success message.
private async handleFileChangesAnalysis(args: FileChangesArgs) { const analysis = args.files.map(file => { const changes = args.branches.map(branch => ({ branch, history: this.getFileHistory(args.repoPath, branch, file), })); return { file, changes, conflicts: this.analyzeConflicts(changes), }; }); const result = { analysis, summary: this.generateFileChangesSummary(analysis), }; writeFileSync(args.outputPath, JSON.stringify(result, null, 2)); return { content: [ { type: 'text', text: `File changes analysis written to ${args.outputPath}`, }, ], }; - src/index.ts:125-152 (registration)Registration of the 'analyze_file_changes' tool in the ListToolsRequestHandler response, including name, description, and complete input schema.
{ name: 'analyze_file_changes', description: 'Analyze changes to specific files across branches', inputSchema: { type: 'object', properties: { repoPath: { type: 'string', description: 'Path to git repository', }, branches: { type: 'array', items: { type: 'string' }, description: 'Branches to analyze', }, files: { type: 'array', items: { type: 'string' }, description: 'Files to analyze', }, outputPath: { type: 'string', description: 'Path to write analysis output', }, }, required: ['repoPath', 'branches', 'files', 'outputPath'], }, }, - src/index.ts:30-35 (schema)TypeScript interface defining the input arguments structure for the 'analyze_file_changes' tool handler.
interface FileChangesArgs { repoPath: string; branches: string[]; files: string[]; outputPath: string; } - src/index.ts:196-202 (handler)Dispatcher case in CallToolRequestHandler for 'analyze_file_changes': validates parameters and delegates to the main handler method.
case 'analyze_file_changes': { const args = request.params.arguments as FileChangesArgs; if (!args?.repoPath || !args?.branches || !args?.files || !args?.outputPath) { throw new McpError(ErrorCode.InvalidParams, 'Missing required parameters'); } return await this.handleFileChangesAnalysis(args); } - src/index.ts:387-397 (helper)Key helper function used by the handler to fetch git commit history for a specific file on a given branch.
private getFileHistory(repoPath: string, branch: string, file: string) { const output = execSync( `cd "${repoPath}" && git log --format="%H|%aI|%s" ${branch} -- ${file}`, { encoding: 'utf8' } ); return output.trim().split('\n').filter(Boolean).map(line => { const [hash, date, message] = line.split('|'); return { hash, date, message, branch }; }); }