Skip to main content
Glama

diff

Read-only

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';
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true, so the agent knows this is a safe read operation. The description adds no behavioral context beyond what annotations provide—it doesn't mention output format, pagination, rate limits, or authentication needs. With annotations covering safety, this meets baseline expectations but adds minimal extra value.

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 extremely concise—a single, clear sentence that front-loads the core purpose without any wasted words. Every part of the sentence earns its place by specifying what the tool does, making it efficient and well-structured.

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

Completeness3/5

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

Given the tool's moderate complexity (8 parameters, no output schema) and rich schema coverage, the description is minimally adequate. It states the purpose but lacks context on output format, error handling, or integration with siblings. With annotations covering read-only safety, it meets basic needs but could be more complete for effective agent use.

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%, meaning all parameters are well-documented in the schema itself. The description adds no additional parameter semantics beyond implying the tool compares two states (from/to). Baseline score of 3 is appropriate since the schema handles parameter documentation effectively.

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 with the verb 'Show' and resource 'differences between commits, branches, files', making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'log' (which shows commit history) or 'status' (which shows working directory state), missing full sibling distinction.

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. It doesn't mention when to choose 'diff' over 'log' for viewing changes, 'status' for current state, or other siblings, leaving the agent without contextual usage instructions.

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

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