Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

git_diff

Compare code changes between commits, working directory, and staging area to track modifications and review differences in your development workflow.

Instructions

Show changes between commits, working tree, and staging area

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdNoRepository directory
cachedNoShow staged changes
filesNoSpecific file(s) to diff
commitNoCompare against specific commit/branch

Implementation Reference

  • The main handler function that constructs and executes the 'git diff' command based on provided arguments, returning the ToolResponse.
    export async function gitDiff(args: z.infer<typeof gitDiffSchema>): Promise<ToolResponse> { const cachedFlag = args.cached ? '--cached' : ''; const files = args.files || ''; const commit = args.commit || ''; return executeGitCommand(`git diff ${cachedFlag} ${commit} ${files}`.trim(), args.cwd); }
  • Zod schema defining the input parameters for the git_diff tool, used for validation.
    export const gitDiffSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), cached: z.boolean().optional().default(false).describe('Show staged changes'), files: z.string().optional().describe('Specific file(s) to diff'), commit: z.string().optional().describe('Compare against specific commit/branch') });
  • src/index.ts:369-371 (registration)
    Dispatch logic in the main MCP server handler that matches the tool name, validates arguments, and invokes the gitDiff handler.
    if (name === 'git_diff') { const validated = gitDiffSchema.parse(args); return await gitDiff(validated);
  • MCP tool registration definition including name, description, and JSON input schema, part of the gitTools array used for listing available tools.
    name: 'git_diff', description: 'Show changes between commits, working tree, and staging area', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, cached: { type: 'boolean', default: false, description: 'Show staged changes' }, files: { type: 'string', description: 'Specific file(s) to diff' }, commit: { type: 'string', description: 'Compare against specific commit/branch' } } } },
  • Helper function that executes git commands via child_process.exec, formats output as ToolResponse, and handles errors.
    async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }

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/ConnorBoetig-dev/mcp2'

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