Skip to main content
Glama

get_git_diff

Retrieve the full unified diff between two git refs, returning diff text, file list, and addition/deletion counts. Use to review changes before logging them to the ledger.

Instructions

Get the full unified diff between two refs (default: HEAD~1..HEAD). Returns diff text, file list, and addition/deletion counts. Use to review changes before logging them to the ledger.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
baseNoBase git ref to diff against. Defaults to HEAD~1 (last commit). Use "HEAD" for uncommitted changes.
fileNoOptional file path to scope the diff to a single file.

Implementation Reference

  • Core implementation of getDiff that executes `git diff --stat` and `git diff` commands, parses additions/deletions, file list, and truncates output at 80,000 chars.
    async function getDiff(
      repoDir: string,
      base?: string,
      filePath?: string,
    ): Promise<DiffResult> {
      const MAX_DIFF = 80_000;
      const ref = base ?? 'HEAD~1';
    
      // Stat summary: additions/deletions + file list
      const statArgs = ['-C', repoDir, 'diff', '--stat', ref, 'HEAD'];
      if (filePath) statArgs.push('--', filePath);
    
      // Full diff
      const diffArgs = ['-C', repoDir, 'diff', ref, 'HEAD'];
      if (filePath) diffArgs.push('--', filePath);
    
      const [statResult, diffResult] = await Promise.all([
        execFileAsync('git', statArgs),
        execFileAsync('git', diffArgs),
      ]);
    
      const raw = diffResult.stdout;
      const truncated = raw.length > MAX_DIFF;
      const diff = truncated ? raw.slice(0, MAX_DIFF) + '\n\n[...truncated]' : raw;
    
      // Parse additions/deletions from stat
      const addMatch = statResult.stdout.match(/(\d+) insertion/);
      const delMatch = statResult.stdout.match(/(\d+) deletion/);
    
      // File list from stat lines
      const files = statResult.stdout
        .split('\n')
        .filter((l) => l.includes('|'))
        .map((l) => (l.split('|')[0] ?? '').trim());
    
      return {
        diff,
        files,
        additions: addMatch?.[1] != null ? parseInt(addMatch[1], 10) : 0,
        deletions: delMatch?.[1] != null ? parseInt(delMatch[1], 10) : 0,
        truncated,
      };
    }
  • Zod schema for get_git_diff: optional 'base' (default HEAD~1) and 'file' (single file scope) params.
    export const GetGitDiffSchema = z.object({
      base: z
        .string()
        .optional()
        .describe(
          'Base git ref to diff against. Defaults to HEAD~1 (last commit). Use "HEAD" for uncommitted changes.',
        ),
      file: z
        .string()
        .optional()
        .describe('Optional file path to scope the diff to a single file.'),
    });
  • MCP tool registration of 'get_git_diff' with schema and handler that delegates to manager.getDiff.
      server.tool(
        'get_git_diff',
        'Get the full unified diff between two refs (default: HEAD~1..HEAD). Returns diff text, file list, and addition/deletion counts. Use to review changes before logging them to the ledger.',
        GetGitDiffSchema.shape,
        async (args) => {
          const result = await manager.getDiff(args.base, args.file);
          return {
            content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],
          };
        },
      );
    }
  • DevLifecycleManager interface declaring getDiff method.
    export interface DevLifecycleManager {
      runTypecheck(servicePath: string): Promise<TypecheckResult>;
      runTests(servicePath: string, pattern?: string): Promise<TestResult>;
      getDiff(base?: string, filePath?: string): Promise<DiffResult>;
  • Manager getDiff method that delegates to GitAccess.getDiff with the repo directory.
    async function getDiff(base?: string, filePath?: string): Promise<DiffResult> {
      return git.getDiff(repoDir, base, filePath);
    }
Behavior4/5

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

With no annotations provided, the description carries full burden. It discloses the operation type (read), default behavior, and return structure. However, it does not explicitly state that it is non-destructive or mention any side effects, though the nature of git diff suggests none.

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?

Two sentences with no redundant words. The first sentence defines the action and inputs, the second provides the usage context. Information is front-loaded and efficient.

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

Completeness5/5

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

For a simple tool with two optional parameters and no output schema, the description fully explains inputs, defaults, return values, and suggested usage. No additional information is needed for an agent to use it correctly.

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

Parameters4/5

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

Schema coverage is 100%, and the description adds value by explaining defaults (base defaults to HEAD~1) and special values ('Use HEAD for uncommitted changes'). This provides context beyond the schema 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?

The description clearly states the tool gets the full unified diff between two refs with a default of HEAD~1..HEAD, and lists the return types (diff text, file list, counts). This distinguishes it from siblings like get_changed_files or get_all_changes which focus on file lists rather than the full diff.

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

Usage Guidelines4/5

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

The description specifies when to use the tool: 'Use to review changes before logging them to the ledger.' This provides clear context, but it does not explicitly mention when not to use it or compare with alternative sibling tools, leaving some ambiguity.

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/2loch-ness6/mempalace-mcp-dev'

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