git_log
Retrieve commit history from a Git repository to track changes, review modifications, and understand project evolution.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | . | |
| maxCount | No |
Implementation Reference
- src/tools/dev-tools.ts:79-98 (handler)Executes the git log command with specified path and maxCount, parses the output into commits, and returns JSON-formatted text content.async ({ path: gitPath, maxCount }) => { return wrapToolExecution(async () => { const { stdout } = await execAsync( `git log -${maxCount} --pretty=format:"%H|%an|%ad|%s" --date=iso`, { cwd: gitPath } ); const commits = parseGitLog(stdout); return { content: [{ type: "text" as const, text: JSON.stringify(commits, null, 2) }] }; }, { errorCode: ERROR_CODES.GIT_OPERATION, context: "Failed to get git log" }); }
- src/tools/dev-tools.ts:75-78 (schema)Zod schema defining optional 'path' (git directory, default '.') and 'maxCount' (number of commits, default from constants).{ path: z.string().optional().default("."), maxCount: z.number().optional().default(DEFAULTS.MAX_COMMITS) },
- src/tools/dev-tools.ts:73-100 (registration)Registers the 'git_log' tool with the MCP server, providing schema and handler function.function registerGitLog(server: McpServer): void { server.tool("git_log", { path: z.string().optional().default("."), maxCount: z.number().optional().default(DEFAULTS.MAX_COMMITS) }, async ({ path: gitPath, maxCount }) => { return wrapToolExecution(async () => { const { stdout } = await execAsync( `git log -${maxCount} --pretty=format:"%H|%an|%ad|%s" --date=iso`, { cwd: gitPath } ); const commits = parseGitLog(stdout); return { content: [{ type: "text" as const, text: JSON.stringify(commits, null, 2) }] }; }, { errorCode: ERROR_CODES.GIT_OPERATION, context: "Failed to get git log" }); } ); }
- src/tools/dev-tools.ts:102-113 (helper)Parses the stdout from 'git log --pretty=format:"%H|%an|%ad|%s"' into an array of GitCommit objects with abbreviated hash.function parseGitLog(stdout: string): GitCommit[] { const lines = stdout.trim().split('\n').filter(line => line); return lines.map(line => { const [hash, author, date, message] = line.split('|'); return { hash: hash.substring(0, 8), author, date, message }; }); }
- src/index.ts:67-67 (registration)Calls registerDevTools which includes registerGitLog to register dev tools including git_log on the main MCP server.registerDevTools(server);