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
| Name | Required | Description | Default |
|---|---|---|---|
| repo_slug | Yes | ||
| branch_name | Yes |
Implementation Reference
- src/server.py:714-743 (handler)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"), }, }
- src/bitbucket_client.py:1268-1283 (helper)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), )
- src/models.py:221-253 (schema)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"), )