git_log
Retrieve recent Git commit history for a repository to track changes, review updates, and monitor project activity. Specify path and commit count for targeted analysis.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "git_log"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | . | |
| maxCount | No |
Implementation Reference
- src/tools/dev-tools.ts:79-98 (handler)Handler function that runs the git log command, parses output with parseGitLog, and returns JSON array of 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:75-78 (schema)Zod input schema defining optional 'path' (git directory) and 'maxCount' (number of commits).
{ 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, including 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)Helper function to parse git log output into structured GitCommit objects.
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 }; }); }