list_branch_restrictions
Retrieve branch protection rules for a Bitbucket repository to manage access controls and enforce security policies on specific branches.
Instructions
List branch restrictions (protection rules) in a repository.
Args:
repo_slug: Repository slug
limit: Maximum number of results (default: 50)
Returns:
List of branch restrictions with kind, pattern, and settings
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_slug | Yes | ||
| limit | No |
Implementation Reference
- src/server.py:1351-1368 (handler)MCP tool handler function that executes the list_branch_restrictions tool. Calls BitbucketClient.list_branch_restrictions and formats output using BranchRestriction model.@mcp.tool() @handle_bitbucket_error @formatted def list_branch_restrictions(repo_slug: str, limit: int = 50) -> dict: """List branch restrictions (protection rules) in a repository. Args: repo_slug: Repository slug limit: Maximum number of results (default: 50) Returns: List of branch restrictions with kind, pattern, and settings """ client = get_client() restrictions = client.list_branch_restrictions(repo_slug, limit=validate_limit(limit)) return { "restrictions": [BranchRestriction.from_api(r).model_dump() for r in restrictions], }
- src/bitbucket_client.py:1359-1376 (helper)BitbucketClient helper method that performs the actual API request to list branch restrictions using the paginated_list utility.def list_branch_restrictions( self, repo_slug: str, limit: int = 50, ) -> list[dict[str, Any]]: """List branch restrictions. Args: repo_slug: Repository slug limit: Maximum results to return Returns: List of restriction info dicts """ return self._paginated_list( self._repo_path(repo_slug, "branch-restrictions"), limit=limit, )
- src/models.py:600-624 (schema)Pydantic model for BranchRestriction used in tool output schema and data transformation from raw API response.class BranchRestriction(BaseModel): """Branch restriction info.""" id: int kind: str pattern: str = "" branch_match_kind: Optional[str] = None branch_type: Optional[str] = None value: Optional[int] = None users: list[str] = [] groups: list[str] = [] @classmethod def from_api(cls, data: dict) -> "BranchRestriction": return cls( id=data.get("id", 0), kind=data.get("kind", ""), pattern=data.get("pattern", ""), branch_match_kind=data.get("branch_match_kind"), branch_type=data.get("branch_type"), value=data.get("value"), users=[u.get("display_name", "") for u in data.get("users", [])], groups=[g.get("name", "") for g in data.get("groups", [])], )