Skip to main content
Glama

github_list_branches

Retrieve branch information from any GitHub repository to track development work, manage code versions, and understand project structure.

Instructions

List branches in a GitHub repository.

Args: repo_name: Full repository name (e.g., "owner/repo") limit: Maximum number of branches to return (default: 20)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
repo_nameYes

Implementation Reference

  • MCP tool handler for 'github_list_branches'. Decorated with @mcp.tool() to register and execute the tool, delegating to GitHubTools.list_branches.
    @mcp.tool() async def github_list_branches(repo_name: str, limit: int = 20) -> list: """List branches in a GitHub repository. Args: repo_name: Full repository name (e.g., "owner/repo") limit: Maximum number of branches to return (default: 20) """ return await github_tools.list_branches(repo_name=repo_name, limit=limit)
  • Core helper method in GitHubTools class that implements the branch listing logic using PyGithub library, fetching repository branches and formatting results.
    async def list_branches( self, repo_name: str, limit: int = 20 ) -> List[Dict[str, Any]]: """ List branches in a repository. Args: repo_name: Full repository name (e.g., "owner/repo") limit: Maximum number of branches to return Returns: List of branch information """ self._check_client() try: repo = self.client.get_repo(repo_name) branches = repo.get_branches() results = [] for i, branch in enumerate(branches): if i >= limit: break results.append( { "name": branch.name, "protected": branch.protected, "commit_sha": branch.commit.sha, } ) return results except GithubException as e: logger.error(f"GitHub API error: {e}") raise ValueError(f"Failed to list branches: {str(e)}")

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/bsangars/mcp'

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