get_file_last_editor
Retrieve the most recent editor of a file by examining its Git commit history. Use this tool to identify who last modified a specific file path for tracking changes and accountability.
Instructions
Get the last editor of a file from Git history
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Path to the file |
Implementation Reference
- src/index.ts:934-942 (handler)MCP tool handler for 'get_file_last_editor' that extracts filePath argument, calls GitUtils.getFileLastEditor, and returns formatted response.case 'get_file_last_editor': { const filePath = args.filePath as string; const lastEditor = await this.gitUtils.getFileLastEditor(filePath); if (lastEditor) { return { content: [{ type: 'text', text: `Last editor of ${filePath}: ${lastEditor}` }] }; } else { return { content: [{ type: 'text', text: `Could not determine last editor for: ${filePath}` }] }; } }
- src/index.ts:766-775 (registration)Tool registration in listTools response, defining name, description, and input schema for get_file_last_editor.name: 'get_file_last_editor', description: 'Get the last editor of a file from Git history', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the file' } }, required: ['filePath'] } }
- src/git-utils.ts:119-124 (helper)GitUtils class method getFileLastEditor that checks if git repo and delegates to getLastEditor.async getFileLastEditor(filePath: string): Promise<string> { if (!this.isGitRepository()) { return 'unknown'; } return await this.getLastEditor(filePath); }
- src/git-utils.ts:34-52 (helper)Core implementation in GitUtils.getLastEditor that runs 'git log -1 --pretty=format:%an' to get the last author name from git history.async getLastEditor(filePath: string): Promise<string> { try { const absolutePath = path.resolve(this.projectRoot, filePath); const relativePath = path.relative(this.projectRoot, absolutePath); // Use git log to get the last author who modified the file const command = `git log -1 --pretty=format:"%an" -- "${relativePath}"`; const result = execSync(command, { cwd: this.projectRoot, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim(); return result || 'unknown'; } catch (error) { console.warn(`Could not get git information for ${filePath}:`, error); return 'unknown'; } }