git_log
Display commit history with details including commit messages, authors, dates, and branch information to track code changes and project evolution.
Instructions
Show commit history with details
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Repository directory | |
| limit | No | Number of commits to show | |
| oneline | No | Show one line per commit | |
| graph | No | Show commit graph | |
| all | No | Show all branches |
Implementation Reference
- src/tools/git.ts:237-242 (handler)Core handler function for git_log tool that builds git log command with customizable flags and executes it using the shared executeGitCommand helper.export async function gitLog(args: z.infer<typeof gitLogSchema>): Promise<ToolResponse> { const onelineFlag = args.oneline ? '--oneline' : '--pretty=format:"%H | %an | %ar | %s"'; const graphFlag = args.graph ? '--graph' : ''; const allFlag = args.all ? '--all' : ''; const limit = `-${args.limit}`; return executeGitCommand(`git log ${onelineFlag} ${graphFlag} ${allFlag} ${limit}`.trim(), args.cwd);
- src/tools/git.ts:89-95 (schema)Zod validation schema for git_log tool inputs, used in the MCP dispatcher.export const gitLogSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), limit: z.number().optional().default(10).describe('Number of commits to show'), oneline: z.boolean().optional().default(false).describe('Show one line per commit'), graph: z.boolean().optional().default(false).describe('Show commit graph'), all: z.boolean().optional().default(false).describe('Show all branches') });
- src/index.ts:373-375 (registration)MCP CallToolRequest handler registration that routes git_log calls to the gitLog function after schema validation.if (name === 'git_log') { const validated = gitLogSchema.parse(args); return await gitLog(validated);
- src/tools/git.ts:547-559 (registration)MCP tool metadata and JSON input schema for git_log, part of gitTools array returned by ListToolsRequest.{ name: 'git_log', description: 'Show commit history with details', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, limit: { type: 'number', default: 10, description: 'Number of commits to show' }, oneline: { type: 'boolean', default: false, description: 'Show one line per commit' }, graph: { type: 'boolean', default: false, description: 'Show commit graph' }, all: { type: 'boolean', default: false, description: 'Show all branches' } } }
- src/tools/git.ts:21-60 (helper)Utility function to execute git commands asynchronously, formats output as ToolResponse, used by all git tools including gitLog.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 }; }