Skip to main content
Glama

list_commits

Retrieve a paginated list of commits from a specified branch in a GitHub repository by providing the repository owner, name, and branch reference.

Instructions

Get list of commits of a branch in a GitHub repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerYesRepository owner
repoYesRepository name
shaNoSHA or Branch name
per_pageNoResults per page (default 10, max 100)
pageNoPage number (default 1)

Implementation Reference

  • The main implementation of the 'list_commits' tool. It registers the tool via server.tool() with the name 'list_commits', defines a Zod schema for parameters (owner, repo, sha, per_page, page), and contains the async handler that calls octokit.rest.repos.listCommits() and formats the response as markdown.
    // Tool: List Commits
    server.tool(
    	"list_commits",
    	"Get list of commits of a branch in a GitHub repository",
    	{
    		owner: z.string().describe("Repository owner"),
    		repo: z.string().describe("Repository name"),
    		sha: z.string().optional().describe("SHA or Branch name"),
    		per_page: z
    			.number()
    			.optional()
    			.default(10)
    			.describe("Results per page (default 10, max 100)"),
    		page: z
    			.number()
    			.optional()
    			.default(1)
    			.describe("Page number (default 1)"),
    	},
    	async ({ owner, repo, sha, per_page, page }) => {
    		try {
    			const response = await octokit.rest.repos.listCommits({
    				owner,
    				repo,
    				sha,
    				per_page,
    				page,
    			})
    
    			const commits = response.data
    
    			if (commits.length === 0) {
    				return {
    					content: [{ type: "text", text: "No commits found." }],
    				}
    			}
    
    			// Format as clean markdown
    			let markdown = `# Commits for ${owner}/${repo}`
    			if (sha) {
    				markdown += ` (${sha})`
    			}
    			markdown += `\n\n`
    			markdown += `Showing ${commits.length} commit(s) - Page ${page}\n`
    			if (commits.length === per_page) {
    				markdown += `*Note: More commits may be available. Use 'page' parameter to see next page.*\n`
    			}
    			markdown += `\n`
    
    			commits.forEach(commit => {
    				const shortSha = commit.sha.substring(0, 7)
    				const message = commit.commit.message.split("\n")[0] // First line only
    				const author =
    					commit.commit.author?.name || commit.author?.login || "Unknown"
    				const date = new Date(
    					commit.commit.author?.date || "",
    				).toLocaleDateString()
    
    				markdown += `## ${shortSha}: ${message}\n\n`
    				markdown += `- **Author:** ${author}\n`
    				markdown += `- **Date:** ${date}\n`
    
    				if (commit.commit.comment_count > 0) {
    					markdown += `- **Comments:** ${commit.commit.comment_count}\n`
    				}
    
    				markdown += `- **URL:** ${commit.html_url}\n`
    				markdown += `\n`
    			})
    
    			return {
    				content: [{ type: "text", text: markdown }],
    			}
    		} catch (e: any) {
    			return {
    				content: [{ type: "text", text: `Error: ${e.message}` }],
    			}
    		}
    	},
    )
  • The input schema for 'list_commits' using Zod: owner (string), repo (string), sha (optional string), per_page (optional number, default 10), page (optional number, default 1).
    // Tool: List Commits
    server.tool(
    	"list_commits",
    	"Get list of commits of a branch in a GitHub repository",
    	{
    		owner: z.string().describe("Repository owner"),
    		repo: z.string().describe("Repository name"),
    		sha: z.string().optional().describe("SHA or Branch name"),
    		per_page: z
    			.number()
    			.optional()
    			.default(10)
    			.describe("Results per page (default 10, max 100)"),
    		page: z
    			.number()
    			.optional()
    			.default(1)
    			.describe("Page number (default 1)"),
    	},
  • Registration of the 'list_commits' tool via server.tool() call inside the registerRepositoryTools function.
    // Tool: List Commits
    server.tool(
    	"list_commits",
  • src/index.ts:17-17 (registration)
    The entry point where registerRepositoryTools (which contains list_commits) is called.
    registerRepositoryTools(server, octokit)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description only indicates a read operation, but does not disclose any behavioral details such as pagination behavior, rate limits, or required authentication. Since no annotations are present, the description bears full responsibility for transparency, which it fails to fulfill.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, front-loaded sentence of 9 words that immediately conveys the tool's function. Every word earns its place, and no unnecessary information is included.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has no output schema, so the description should explain what the return value contains (e.g., a list of commit objects). It does not, leaving the agent to guess the output structure. While the input parameters are well-documented, the missing output context makes the description incomplete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already provides complete descriptions for all 5 parameters (100% coverage), including the optional sha, per_page, and page. The description adds no additional meaning beyond what the schema provides, so a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'get list' and the resource 'commits of a branch in a GitHub repository', making the purpose obvious. However, it does not explicitly distinguish itself from the sibling tool 'get_commit' which returns a single commit, missing an opportunity for differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'get_commit' for a single commit, or when pagination is needed. The description simply states what the tool does without any context about usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hithereiamaliff/mcp-github'

If you have feedback or need assistance with the MCP directory API, please join our Discord server