list-commits
Retrieve commit history for a specific branch in a GitHub repository to track code changes and review development progress.
Instructions
Get list of commits of a branch in a GitHub repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | ||
| page | No | ||
| perPage | No | ||
| repo | Yes | ||
| sha | No |
Implementation Reference
- src/server.ts:249-274 (registration)Tool registration in the ListToolsRequestHandler, including name, description, and input schema definition.{ name: 'list-commits', description: 'Get list of commits of a branch in a GitHub repository', inputSchema: { type: 'object', properties: { owner: { type: 'string', }, repo: { type: 'string', }, sha: { type: 'string', }, page: { type: 'number', }, perPage: { type: 'number', }, }, required: ['owner', 'repo'], additionalProperties: false, }, },
- src/tools/repository.ts:244-277 (handler)The core handler function implementing the list-commits tool. Parses input with ListCommitsSchema, calls GitHub API repos.listCommits, formats and returns commit data.export async function listCommits(args: unknown): Promise<any> { const { owner, repo, sha, page, perPage } = ListCommitsSchema.parse(args); const github = getGitHubApi(); return tryCatchAsync(async () => { const { data } = await github.getOctokit().repos.listCommits({ owner, repo, sha, page, per_page: perPage, }); return data.map((commit) => ({ sha: commit.sha, commit: { author: commit.commit.author, committer: commit.commit.committer, message: commit.commit.message, }, author: commit.author ? { login: commit.author.login, id: commit.author.id, type: commit.author.type, } : null, committer: commit.committer ? { login: commit.committer.login, id: commit.committer.id, type: commit.committer.type, } : null, html_url: commit.html_url, })); }, 'Failed to list commits'); }
- src/utils/validation.ts:221-225 (schema)Zod schema for input validation used in the listCommits handler. Extends OwnerRepoSchema with optional sha, page, perPage.export const ListCommitsSchema = OwnerRepoSchema.extend({ sha: z.string().optional(), page: z.number().optional(), perPage: z.number().optional(), });
- src/server.ts:1178-1180 (registration)Dispatch case in CallToolRequestHandler switch statement that invokes the listCommits handler.case 'list-commits': result = await listCommits(parsedArgs); break;
- src/tools/repository.ts:1-1 (helper)Import of getGitHubApi helper used to obtain the GitHub Octokit instance.import { getGitHubApi } from '../utils/github-api.js';