list_commits
Retrieve a list of commits from a specific branch in a GitHub repository. Input repository owner, repo name, and branch SHA to access detailed commit history.
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
- operations/commits.ts:12-26 (handler)The core handler function that executes the logic to fetch commits from the GitHub API for the 'list_commits' tool.export async function listCommits( owner: string, repo: string, page?: number, perPage?: number, sha?: string ) { return githubRequest( buildUrl(`https://api.github.com/repos/${owner}/${repo}/commits`, { page: page?.toString(), per_page: perPage?.toString(), sha }) ); }
- operations/commits.ts:4-10 (schema)Input schema for validating arguments to the 'list_commits' tool.export const ListCommitsSchema = z.object({ owner: z.string(), repo: z.string(), sha: z.string().optional(), page: z.number().optional(), perPage: z.number().optional() });
- index.ts:115-119 (registration)Tool registration in the MCP server's list of tools, including name, description, and input schema.{ name: "list_commits", description: "Get list of commits of a branch in a GitHub repository", inputSchema: zodToJsonSchema(commits.ListCommitsSchema) },
- index.ts:468-480 (handler)Dispatch handler in the main CallToolRequestSchema that parses input and calls the listCommits function.case "list_commits": { const args = commits.ListCommitsSchema.parse(request.params.arguments); const results = await commits.listCommits( args.owner, args.repo, args.page, args.perPage, args.sha ); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }], }; }
- common/types.ts:113-130 (schema)Output schema defining the structure of the commits list returned by the GitHub API.export const GitHubListCommitsSchema = z.array(z.object({ sha: z.string(), node_id: z.string(), commit: z.object({ author: GitHubAuthorSchema, committer: GitHubAuthorSchema, message: z.string(), tree: z.object({ sha: z.string(), url: z.string() }), url: z.string(), comment_count: z.number(), }), url: z.string(), html_url: z.string(), comments_url: z.string() }));