Skip to main content
Glama

get_branch

Retrieve detailed information about a specific Bitbucket branch, including latest commit details, by providing the repository slug and branch name.

Instructions

Get information about a specific branch.

Args:
    repo_slug: Repository slug
    branch_name: Branch name

Returns:
    Branch info with latest commit details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_slugYes
branch_nameYes

Implementation Reference

  • The main MCP tool handler for 'get_branch'. It fetches branch data from the Bitbucket client, handles not-found cases, and returns formatted branch information including the latest commit details.
    @mcp.tool()
    @handle_bitbucket_error
    @formatted
    def get_branch(repo_slug: str, branch_name: str) -> dict:
        """Get information about a specific branch.
    
        Args:
            repo_slug: Repository slug
            branch_name: Branch name
    
        Returns:
            Branch info with latest commit details
        """
        client = get_client()
        result = client.get_branch(repo_slug, branch_name)
        if not result:
            return not_found_response("Branch", branch_name)
    
        target = result.get("target", {})
        return {
            "name": result.get("name"),
            "latest_commit": {
                "hash": target.get("hash"),
                "message": target.get("message", ""),
                "author": (target.get("author") or {}).get("raw"),
                "date": target.get("date"),
            },
        }
  • Helper method in BitbucketClient that performs the actual API request to retrieve branch information from Bitbucket.
    def get_branch(
        self, repo_slug: str, branch_name: str
    ) -> Optional[dict[str, Any]]:
        """Get branch information.
    
        Args:
            repo_slug: Repository slug
            branch_name: Branch name
    
        Returns:
            Branch info or None if not found
        """
        return self._request(
            "GET",
            self._repo_path(repo_slug, "refs", "branches", branch_name),
        )
  • Pydantic model for branch summary data, used in related branch listing tools and defines the structure similar to get_branch output.
    class BranchSummary(BaseModel):
        """Branch info for list responses."""
    
        name: str
        commit: str
        message: str = ""
        date: Optional[str] = None
    
        @field_validator("commit", mode="before")
        @classmethod
        def truncate_hash(cls, v: Any) -> str:
            return (v or "")[:12]
    
        @field_validator("message", mode="before")
        @classmethod
        def first_line(cls, v: Any) -> str:
            return (v or "").split("\n")[0]
    
        @field_validator("date", mode="before")
        @classmethod
        def truncate_ts(cls, v: Any) -> Optional[str]:
            return truncate_timestamp(v)
    
        @classmethod
        def from_api(cls, data: dict) -> "BranchSummary":
            target = data.get("target") or {}
            return cls(
                name=data.get("name", ""),
                commit=target.get("hash", ""),
                message=target.get("message"),
                date=target.get("date"),
            )

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/JaviMaligno/mcp-server-bitbucket'

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