diff
Compare changes between commits, branches, or files in a Git repository. Identify modifications, track file statuses, and generate diff stats for version control analysis.
Instructions
Show differences between commits, branches, files.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from | No | Source commit, branch, or tag (defaults to working directory) | |
| nameOnly | No | Show only names of changed files (--name-only) | |
| nameStatus | No | Show names and status of changed files (--name-status) | |
| pathspec | No | Limit diff to specific paths | |
| repoPath | Yes | Absolute path to the git repository | |
| staged | No | Show staged changes (--cached) | |
| stat | No | Show diffstat (--stat) | |
| to | No | Target commit, branch, or tag (defaults to HEAD) |
Implementation Reference
- packages/mcp-git/src/tools/diff.ts:40-99 (handler)The private handler method that implements the core logic of the 'diff' tool by executing git diff via simple-git based on the provided input parameters.readonly #handle: ToolCallback<typeof GIT_DIFF_INPUT_SCHEMA> = async (input) => { const sg = simpleGit(input.repoPath); const isRepo = await sg.checkIsRepo(); if (!isRepo) { return { isError: true, content: [ { type: 'text', text: 'Not a git repository', }, ], }; } const options: string[] = []; if (input.staged) { options.push('--cached'); } if (input.nameOnly) { options.push('--name-only'); } if (input.nameStatus) { options.push('--name-status'); } if (input.stat) { options.push('--stat'); } // Build diff arguments const args: string[] = [...options]; if (input.from && input.to) { args.push(`${input.from}..${input.to}`); } else if (input.from) { args.push(input.from); } else if (input.to) { args.push(input.to); } if (input.pathspec && input.pathspec.length > 0) { args.push('--', ...input.pathspec); } const result = await sg.diff(args); return { content: [ { type: 'text', text: result || 'No differences found', }, ], }; };
- Zod schema defining the input parameters for the 'diff' tool.export const GIT_DIFF_INPUT_SCHEMA = { repoPath: z.string().describe('Absolute path to the git repository'), from: z.string().optional().describe('Source commit, branch, or tag (defaults to working directory)'), to: z.string().optional().describe('Target commit, branch, or tag (defaults to HEAD)'), pathspec: z.array(z.string()).optional().describe('Limit diff to specific paths'), staged: z.boolean().optional().describe('Show staged changes (--cached)'), nameOnly: z.boolean().optional().describe('Show only names of changed files (--name-only)'), nameStatus: z.boolean().optional().describe('Show names and status of changed files (--name-status)'), stat: z.boolean().optional().describe('Show diffstat (--stat)'), };
- packages/mcp-git/src/tools/diff.ts:36-38 (registration)The register method of GitDiffTool that calls srv.registerTool with the tool's name, config, and handler.register(srv: McpServer) { srv.registerTool(this.name, this.config, this.#handle); }
- packages/mcp-git/src/index.ts:27-27 (registration)Instantiation and registration of the GitDiffTool with the MCP server in the main index file.new GitDiffTool().register(server);
- packages/mcp-git/src/tools/diff.ts:32-34 (registration)Getter that returns the tool name 'diff'.get name() { return 'diff'; }