Skip to main content
Glama

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
NameRequiredDescriptionDefault
repo_slugYes
limitNo

Implementation Reference

  • 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],
        }
  • 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,
        )
  • 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", [])],
            )

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