Skip to main content
Glama

get_diff_stats

Retrieve diff statistics—files changed, lines added/removed—for staged changes, a specific file, or between two commits.

Instructions

Get diff statistics (files changed, lines added/removed)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stagedNoShow stats for staged changes
fileNoSpecific file stats
commit1NoFirst commit for comparison
commit2NoSecond commit for comparison
cwdNoWorking directory

Implementation Reference

  • src/index.ts:446-447 (registration)
    Routes the 'get_diff_stats' tool call to GitService.getDiffStats() in the main server handler switch statement.
    case 'get_diff_stats':
      return await this.gitService.getDiffStats(args);
  • Defines the input schema for the 'get_diff_stats' tool, including staged, file, commit1, commit2, and cwd parameters.
    {
      name: 'get_diff_stats',
      description: 'Get diff statistics (files changed, lines added/removed)',
      inputSchema: {
        type: 'object',
        properties: {
          staged: { type: 'boolean', description: 'Show stats for staged changes' },
          file: { type: 'string', description: 'Specific file stats' },
          commit1: { type: 'string', description: 'First commit for comparison' },
          commit2: { type: 'string', description: 'Second commit for comparison' },
          cwd: { type: 'string', description: 'Working directory' }
        }
      }
    },
  • Main implementation of getDiffStats: builds git diff --stat command, parses the output (files changed, insertions, deletions), formats header based on context (staged/commit comparison), and returns result with metadata.
    async getDiffStats(options: { 
      staged?: boolean; 
      file?: string; 
      commit1?: string; 
      commit2?: string; 
      cwd?: string; 
    } = {}): Promise<ToolResult> {
      try {
        const { staged = false, file, commit1, commit2, cwd } = options;
        
        const diffArgs = ['diff', '--stat'];
        
        if (staged) {
          diffArgs.push('--staged');
        }
        
        if (commit1 && commit2) {
          diffArgs.push(`${commit1}..${commit2}`);
        } else if (commit1) {
          diffArgs.push(commit1);
        }
        
        if (file) {
          diffArgs.push('--', file);
        }
        
        const result = await this.gitCommand(diffArgs, cwd);
        
        if (result.isError) {
          return result;
        }
        
        // Parse the stats
        const statsText = result.content[0]?.text || '';
        const lines = statsText.split('\n').filter(line => line.trim());
        
        if (lines.length === 0) {
          const header = staged ? 'Staged Changes Statistics:\n\n' : 
                        (commit1 && commit2) ? `Commit Comparison Statistics (${commit1}..${commit2}):\n\n` :
                        'Diff Statistics:\n\n';
          return {
            content: [{
              type: 'text',
              text: header + 'No changes found',
              _meta: {
                filesChanged: 0,
                insertions: 0,
                deletions: 0
              }
            }]
          };
        }
        
        // Extract summary line (usually the last line)
        const summaryLine = lines[lines.length - 1];
        const filesChanged = (summaryLine.match(/(\d+) files? changed/) || [])[1] || '0';
        const insertions = (summaryLine.match(/(\d+) insertions?\(\+\)/) || [])[1] || '0';
        const deletions = (summaryLine.match(/(\d+) deletions?\(\-\)/) || [])[1] || '0';
        
        // Add appropriate header
        let header = '';
        if (staged) {
          header = 'Staged Changes Statistics:\n\n';
        } else if (commit1 && commit2) {
          header = `Commit Comparison Statistics (${commit1}..${commit2}):\n\n`;
        } else {
          header = 'Diff Statistics:\n\n';
        }
        
        // Format the output with additional analysis
        let output = header;
        output += `Files changed: ${filesChanged}\n`;
        output += `Lines added: ${insertions}\n`;  
        output += `Lines removed: ${deletions}\n\n`;
        output += `Detailed Breakdown:\n${statsText}`;
        
        return {
          content: [{
            type: 'text',
            text: output,
            _meta: {
              filesChanged: parseInt(filesChanged),
              insertions: parseInt(insertions),
              deletions: parseInt(deletions),
              summary: summaryLine
            }
          }]
        };
        
      } catch (error) {
        return {
          isError: true,
          content: [{
            type: 'text',
            text: `Diff stats failed: ${error instanceof Error ? error.message : String(error)}`
          }]
        };
      }
    }
Behavior2/5

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

No annotations provided, so description must carry burden. Only states it gets diff statistics; no mention of side effects, required infrastructure (git repo), or behavior with missing parameters.

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?

Single sentence, front-loaded, no extraneous words. Efficient and to the point.

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 5 optional parameters, no required params, and no output schema, the description is too brief. Default behavior when no parameters are provided is unclear. Return format not described.

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 100%, so baseline is 3. Description adds no additional meaning beyond the schema's parameter descriptions.

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

Purpose5/5

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

Clearly states 'Get diff statistics' with parenthetical specifying 'files changed, lines added/removed'. Verb+resource is specific and distinguishable from sibling tools like git_diff or enhanced_git_diff.

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?

No guidance on when to use this versus siblings like git_diff or compare_commits. No mention of prerequisites or context for usage.

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/agentics-ai/code-mcp'

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