git_commits_details
Retrieve detailed commit data from Git repositories, including messages and optional diffs. Filter by branch, date range, author, or message content to streamline code history analysis.
Instructions
Get detailed information about commits including full messages and diffs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| author | No | Filter by author (optional) | |
| branch | No | The branch to get commits from | main |
| grep | No | Filter commits by message content (optional) | |
| include_diff | No | Whether to include the commit diffs | |
| 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
- The primary handler function that implements the git_commits_details tool. It clones the repository, fetches detailed commit logs using simple-git, optionally retrieves diffs and changed files for each commit, and returns formatted JSON output.export async function handleGitCommitsDetails({ repo_url, branch = "main", max_count = 10, include_diff = false, author, since, until, grep, }) { try { const repoPath = await cloneRepo(repo_url); const git = simpleGit(repoPath); // Ensure branch exists locally const branches = await git.branch(); if (!branches.all.includes(branch)) { await git.fetch("origin", branch); } // Prepare log options with full details const logOptions = { maxCount: max_count, "--format": "fuller", // Get more detailed commit info }; if (author) { logOptions["--author"] = author; } if (since) { logOptions["--since"] = since; } if (until) { logOptions["--until"] = until; } if (grep) { logOptions["--grep"] = grep; } // Get commit history with full details const log = await git.log(logOptions, branch); // Enhance with additional details const commitsDetails = []; for (const commit of log.all) { const commitDetails = { hash: commit.hash, author: commit.author_name, author_email: commit.author_email, committer: commit.committer_name, committer_email: commit.committer_email, date: commit.date, message: commit.message, body: commit.body || "", refs: commit.refs, }; // Get the commit diff if requested if (include_diff) { if (commit.parents && commit.parents.length > 0) { // For normal commits with parents const diff = await git.diff([`${commit.hash}^..${commit.hash}`]); commitDetails.diff = diff; } else { // For initial commits with no parents const diff = await git.diff([ "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commit.hash, ]); commitDetails.diff = diff; } // Get list of changed files const showResult = await git.show([ "--name-status", "--oneline", commit.hash, ]); // Parse the changed files from the result const fileLines = showResult .split("\n") .slice(1) // Skip the first line (commit summary) .filter(Boolean); // Remove empty lines commitDetails.changed_files = fileLines .map((line) => { const match = line.match(/^([AMDTRC])\s+(.+)$/); if (match) { return { status: match[1], file: match[2], }; } return null; }) .filter(Boolean); } commitsDetails.push(commitDetails); } return { content: [ { type: "text", text: JSON.stringify( { commits: commitsDetails, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to get commit details: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:284-330 (schema)The tool schema definition including name, description, and detailed inputSchema with properties and defaults matching the handler parameters.name: "git_commits_details", description: "Get detailed information about commits including full messages and diffs.", inputSchema: { type: "object", properties: { repo_url: { type: "string", description: "The URL of the Git repository", }, branch: { type: "string", description: "The branch to get commits from", default: "main", }, max_count: { type: "integer", description: "Maximum number of commits to retrieve", default: 10, }, include_diff: { type: "boolean", description: "Whether to include the commit diffs", default: false, }, 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")', }, author: { type: "string", description: "Filter by author (optional)", }, grep: { type: "string", description: "Filter commits by message content (optional)", }, }, required: ["repo_url"], }, },
- src/server.js:904-904 (registration)Registration of the tool name 'git_commits_details' mapped to the handler function 'handleGitCommitsDetails' in the central handlersMap used by the MCP server.git_commits_details: handleGitCommitsDetails,
- src/handlers/index.js:9-13 (registration)Import of the handleGitCommitsDetails handler from its implementation file.handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack, } from "./commit-operations.js";
- src/handlers/index.js:49-52 (registration)Re-export of the handleGitCommitsDetails function for use by server.js.handleGitCommitHistory, handleGitCommitsDetails, handleGitCommit, handleGitTrack,