Skip to main content
Glama

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
NameRequiredDescriptionDefault
fromNoSource commit, branch, or tag (defaults to working directory)
nameOnlyNoShow only names of changed files (--name-only)
nameStatusNoShow names and status of changed files (--name-status)
pathspecNoLimit diff to specific paths
repoPathYesAbsolute path to the git repository
stagedNoShow staged changes (--cached)
statNoShow diffstat (--stat)
toNoTarget commit, branch, or tag (defaults to HEAD)

Implementation Reference

  • 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)'), };
  • 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); }
  • Instantiation and registration of the GitDiffTool with the MCP server in the main index file.
    new GitDiffTool().register(server);
  • Getter that returns the tool name 'diff'.
    get name() { return 'diff'; }

Other Tools

Related 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/ver0-project/mcps'

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