git_commit_history
Retrieve and filter commit history for a specific Git repository branch, with options to limit results by author, date range, or message content.
Instructions
Get commit history for a branch with optional filtering.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| author | No | Filter by author (optional) | |
| branch | No | The branch to get history from | main |
| grep | No | Filter commits by message content (optional) | |
| max_count | No | Maximum number of commits to retrieve | |
| repo_url | Yes | The URL of the Git repository | |
| since | No | Get commits after this date (e.g., "1 week ago", "2023-01-01") | |
| until | No | Get commits before this date (e.g., "yesterday", "2023-12-31") |
Implementation Reference
- src/handlers/commit-operations.js:15-91 (handler)Core implementation of the git_commit_history tool handler. Clones the repository, applies filters to git log, formats commit data, and returns structured JSON response.export async function handleGitCommitHistory({ repo_url, branch = "main", max_count = 10, author, since, until, grep, }) { try { const repoPath = await cloneRepo(repo_url); const git = simpleGit(repoPath); // Prepare log options const logOptions = { maxCount: max_count, }; if (author) { logOptions["--author"] = author; } if (since) { logOptions["--since"] = since; } if (until) { logOptions["--until"] = until; } if (grep) { logOptions["--grep"] = grep; } // Make sure branch exists locally const branches = await git.branch(); if (!branches.all.includes(branch)) { await git.fetch("origin", branch); } // Get commit history const log = await git.log(logOptions, branch); // Format the commits const commits = log.all.map((commit) => ({ hash: commit.hash, author: commit.author_name, email: commit.author_email, date: commit.date, message: commit.message, body: commit.body || "", })); return { content: [ { type: "text", text: JSON.stringify({ commits }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to get commit history: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:242-282 (schema)Input schema and metadata definition for the git_commit_history tool used in MCP tool listing.name: "git_commit_history", description: "Get commit history for a branch with optional filtering.", inputSchema: { type: "object", properties: { repo_url: { type: "string", description: "The URL of the Git repository", }, branch: { type: "string", description: "The branch to get history from", default: "main", }, max_count: { type: "integer", description: "Maximum number of commits to retrieve", default: 10, }, author: { type: "string", description: "Filter by author (optional)", }, since: { type: "string", description: 'Get commits after this date (e.g., "1 week ago", "2023-01-01")', }, until: { type: "string", description: 'Get commits before this date (e.g., "yesterday", "2023-12-31")', }, grep: { type: "string", description: "Filter commits by message content (optional)", }, }, required: ["repo_url"], }, },
- src/server.js:903-903 (registration)Maps the tool name 'git_commit_history' to its handler function in the server's handlersMap.git_commit_history: handleGitCommitHistory,
- src/server.js:886-886 (registration)Registers 'git_log' as an alias for the 'git_commit_history' tool.git_log: "git_commit_history",
- src/handlers/index.js:9-13 (registration)Imports the handleGitCommitHistory function from its implementation file for re-export and use in server.handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack, } from "./commit-operations.js";