Skip to main content
Glama

update_last_editor

Updates the last editor field in files using Git author data to maintain accurate contributor records for project tracking.

Instructions

Update @last-editor field in a file with Git author information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the file to update

Implementation Reference

  • MCP server tool handler for 'update_last_editor' that delegates to GitUtils.updateLastEditorInFile and returns success/error response
    case 'update_last_editor': {
      const filePath = args.filePath as string;
      const result = await this.gitUtils.updateLastEditorInFile(filePath);
      if (result.success) {
        return { content: [{ type: 'text', text: `Last editor updated successfully for: ${filePath}. New editor: ${result.newEditor}` }] };
      } else {
        return { content: [{ type: 'text', text: `Failed to update last editor for: ${filePath}. Reason: ${result.reason}` }] };
      }
    }
  • Core implementation of updateLastEditorInFile: gets last editor from Git, updates @last-editor metadata comment in file, writes if changed
    async updateLastEditorInFile(filePath: string): Promise<{success: boolean, newEditor?: string, reason?: string}> {
      try {
        const relativePath = path.relative(this.projectRoot, filePath);
        const lastEditor = await this.getFileLastEditor(relativePath);
        
        if (lastEditor === 'unknown') {
          return { success: false, reason: 'Could not determine last editor from Git' };
        }
        
        const content = await fs.readFile(filePath, 'utf8');
        const updatedContent = content.replace(
          /^(\s*\*\s*@last-editor:\s*).*$/m,
          `$1${lastEditor}`
        );
        
        if (content !== updatedContent) {
          await fs.writeFile(filePath, updatedContent, 'utf8');
          return { success: true, newEditor: lastEditor };
        }
        
        return { success: false, reason: 'File already up to date' };
      } catch (error) {
        console.error(`Error updating last editor in ${filePath}:`, error);
        return { success: false, reason: `Error: ${error}` };
      }
    }
  • src/index.ts:746-756 (registration)
    Tool registration in ListTools response, including name, description, and input schema
    {
      name: 'update_last_editor',
      description: 'Update @last-editor field in a file with Git author information',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: { type: 'string', description: 'Path to the file to update' }
        },
        required: ['filePath']
      }
    },
  • Helper method getLastEditor that runs 'git log -1 --pretty=format:%an' to get the last commit author name for a file
    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';
      }
    }

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/keleshteri/mcp-memory'

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