Skip to main content
Glama

list_branches

List all branches of a GitHub repository by providing the owner and repository name. Supports pagination to control the number of results per page.

Instructions

List branches in a GitHub repository

Input Schema

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

Implementation Reference

  • The tool 'list_branches' is registered via server.tool() call with description, Zod schema for inputs, and async handler callback.
    server.tool(
    	"list_branches",
    	"List branches in a GitHub repository",
    	{
    		owner: z.string().describe("Repository owner"),
    		repo: z.string().describe("Repository 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, per_page, page }) => {
    		try {
    			const response = await octokit.rest.repos.listBranches({
    				owner,
    				repo,
    				per_page,
    				page,
    			})
    
    			const branches = response.data
    
    			if (branches.length === 0) {
    				return {
    					content: [{ type: "text", text: "No branches found." }],
    				}
    			}
    
    			// Get default branch
    			const repoResponse = await octokit.rest.repos.get({ owner, repo })
    			const defaultBranch = repoResponse.data.default_branch
    
    			// Format as clean markdown
    			let markdown = `# Branches for ${owner}/${repo}\n\n`
    			markdown += `Showing ${branches.length} branch(es) - Page ${page}\n`
    			if (branches.length === per_page) {
    				markdown += `*Note: More branches may be available. Use 'page' parameter to see next page.*\n`
    			}
    			markdown += `\n`
    
    			branches.forEach(branch => {
    				const isDefault = branch.name === defaultBranch
    				markdown += `## ${branch.name}${isDefault ? " (default)" : ""}\n\n`
    				markdown += `- **SHA:** ${branch.commit.sha.substring(0, 7)}\n`
    
    				if (branch.protected) {
    					markdown += `- **Protected:** Yes\n`
    				}
    
    				markdown += `- **URL:** ${branch.commit.url.replace("api.github.com/repos", "github.com").replace("/commits/", "/tree/")}\n`
    				markdown += `\n`
    			})
    
    			return {
    				content: [{ type: "text", text: markdown }],
    			}
    		} catch (e: any) {
    			return {
    				content: [{ type: "text", text: `Error: ${e.message}` }],
    			}
    		}
    	},
    )
  • Async handler function that calls octokit.rest.repos.listBranches to fetch branches, retrieves the default branch via octokit.rest.repos.get, and formats output as markdown.
    async ({ owner, repo, per_page, page }) => {
    	try {
    		const response = await octokit.rest.repos.listBranches({
    			owner,
    			repo,
    			per_page,
    			page,
    		})
    
    		const branches = response.data
    
    		if (branches.length === 0) {
    			return {
    				content: [{ type: "text", text: "No branches found." }],
    			}
    		}
    
    		// Get default branch
    		const repoResponse = await octokit.rest.repos.get({ owner, repo })
    		const defaultBranch = repoResponse.data.default_branch
    
    		// Format as clean markdown
    		let markdown = `# Branches for ${owner}/${repo}\n\n`
    		markdown += `Showing ${branches.length} branch(es) - Page ${page}\n`
    		if (branches.length === per_page) {
    			markdown += `*Note: More branches may be available. Use 'page' parameter to see next page.*\n`
    		}
    		markdown += `\n`
    
    		branches.forEach(branch => {
    			const isDefault = branch.name === defaultBranch
    			markdown += `## ${branch.name}${isDefault ? " (default)" : ""}\n\n`
    			markdown += `- **SHA:** ${branch.commit.sha.substring(0, 7)}\n`
    
    			if (branch.protected) {
    				markdown += `- **Protected:** Yes\n`
    			}
    
    			markdown += `- **URL:** ${branch.commit.url.replace("api.github.com/repos", "github.com").replace("/commits/", "/tree/")}\n`
    			markdown += `\n`
    		})
    
    		return {
    			content: [{ type: "text", text: markdown }],
    		}
    	} catch (e: any) {
    		return {
    			content: [{ type: "text", text: `Error: ${e.message}` }],
    		}
    	}
    },
  • Zod schema defining input parameters: owner (string), repo (string), per_page (optional number, default 10), page (optional number, default 1).
    {
    	owner: z.string().describe("Repository owner"),
    	repo: z.string().describe("Repository 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)"),
    },
Behavior2/5

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

With no annotations, the description should disclose behavior (e.g., pagination, ordering, whether all branches are returned). It merely says 'list branches' without any such details, leaving the agent uninformed.

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, concise sentence. It is appropriately sized for the tool's simplicity, with no wasted words.

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

Completeness3/5

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

The description is minimal but adequate for a simple listing tool with thorough parameter descriptions. However, lack of output schema and annotations means it could be more complete (e.g., noting that it returns branch objects).

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?

Schema coverage is 100%, so the schema already documents all parameters. The description adds no extra semantics beyond what is in the schema, resulting in baseline score of 3.

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 'List branches in a GitHub repository', a specific verb and resource. It is straightforward, though it does not differentiate from sibling tools like list_tags or list_commits, but those are distinct resources.

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?

The description offers no guidance on when to use this tool versus alternatives (e.g., create_branch, list_tags). It lacks any when-not-to-use or contextual hints.

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