Skip to main content
Glama
davidorex

Git File Forensics MCP

by davidorex

analyze_file_diff

Compare file versions in Git repositories to identify specific changes between commits and generate detailed analysis reports.

Instructions

Analyze specific changes between any two versions of a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoPathYesPath to git repository
fileYesFile to analyze
versionsYes
outputPathYesPath to write analysis output

Implementation Reference

  • The primary handler function for the 'analyze_file_diff' tool. It retrieves the git diff between two versions, detects moved code blocks, generates a summary, writes the analysis to the specified output path, and returns a success message.
    private async handleFileDiff(args: FileDiffArgs) {
      const diff = this.getFileDiff(args.repoPath, args.file, args.versions);
      const movedBlocks = this.findMovedBlocks(diff);
      
      const analysis = {
        diff,
        movedBlocks,
        summary: this.generateDiffSummary(diff),
      };
    
      writeFileSync(args.outputPath, JSON.stringify(analysis, null, 2));
    
      return {
        content: [
          {
            type: 'text',
            text: `File diff analysis written to ${args.outputPath}`,
          },
        ],
      };
  • src/index.ts:168-197 (registration)
    Tool registration in the ListTools response, including name, description, and complete input schema definition.
    {
      name: 'analyze_file_diff',
      description: 'Analyze specific changes between any two versions of a file',
      inputSchema: {
        type: 'object',
        properties: {
          repoPath: {
            type: 'string',
            description: 'Path to git repository',
          },
          file: {
            type: 'string',
            description: 'File to analyze',
          },
          versions: {
            type: 'object',
            properties: {
              from: { type: 'string' },
              to: { type: 'string' },
            },
            required: ['from', 'to'],
          },
          outputPath: {
            type: 'string',
            description: 'Path to write analysis output',
          },
        },
        required: ['repoPath', 'file', 'versions', 'outputPath'],
      },
    },
  • src/index.ts:260-266 (registration)
    Dispatch handler in the CallToolRequestSchema that validates input using isFileDiffArgs and invokes the main handleFileDiff method.
    case 'analyze_file_diff': {
      const args = request.params.arguments as unknown;
      if (!this.isFileDiffArgs(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Missing required parameters');
      }
      return await this.handleFileDiff(args);
    }
  • Type guard function for validating the input arguments against the FileDiffArgs interface used in the tool.
    private isFileDiffArgs(args: unknown): args is FileDiffArgs {
      return (
        typeof args === 'object' &&
        args !== null &&
        'repoPath' in args &&
        'file' in args &&
        'versions' in args &&
        'outputPath' in args &&
        typeof (args as FileDiffArgs).repoPath === 'string' &&
        typeof (args as FileDiffArgs).file === 'string' &&
        typeof (args as FileDiffArgs).outputPath === 'string' &&
        typeof (args as FileDiffArgs).versions === 'object' &&
        (args as FileDiffArgs).versions !== null &&
        'from' in (args as FileDiffArgs).versions &&
        'to' in (args as FileDiffArgs).versions &&
        typeof (args as FileDiffArgs).versions.from === 'string' &&
        typeof (args as FileDiffArgs).versions.to === 'string'
      );
  • Helper function that executes the git diff command to retrieve the raw diff between two file versions.
    private getFileDiff(
      repoPath: string,
      file: string,
      versions: { from: string; to: string }
    ) {
      return execSync(
        `cd "${repoPath}" && git diff ${versions.from} ${versions.to} -- "${file}"`,
        { encoding: 'utf8' }
      );
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states what the tool does but doesn't disclose behavioral traits like whether it's read-only vs. destructive (though 'analyze' implies read-only), what format the output takes, whether it writes to disk (implied by 'outputPath'), or any rate limits or error conditions. This leaves significant gaps for an agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose with zero waste. Every word earns its place, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters, nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain the analysis output format, error handling, or how to interpret results, leaving the agent with insufficient context to use the tool effectively beyond basic invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 75% (3 of 4 parameters have descriptions), so the baseline is 3. The description adds no additional parameter semantics beyond what's in the schema—it doesn't explain what 'versions' object should contain (e.g., commit hashes, tags) or clarify the 'outputPath' format. It relies entirely on the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Analyze specific changes between any two versions of a file'. It uses specific verbs ('analyze') and identifies the resource ('file'), but doesn't explicitly differentiate from sibling tools like 'analyze_file_context' or 'track_file_versions', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'analyze_file_context' and 'track_file_versions' available, there's no indication of when this diff analysis is preferred over those other tools, nor any mention of prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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-file-forensics'

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