Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
repoPathYesPath to git repository
branchesYesBranches to analyze
filesYesFiles to analyze
outputPathYesPath to write analysis output

Implementation Reference

  • 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'], }, },
  • TypeScript interface defining the input arguments structure for the 'analyze_file_changes' tool handler.
    interface FileChangesArgs { repoPath: string; branches: string[]; files: string[]; outputPath: string; }
  • 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); }
  • 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 }; }); }

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/davidorex/git-forensics-mcp'

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