Skip to main content
Glama

create_pull_request

Create a pull request in Bitbucket to merge code changes from a source branch to a target branch, with options for description and branch management.

Instructions

Create a pull request in a Bitbucket repository.

Args:
    repo_slug: Repository slug (e.g., "anzsic_classifier")
    title: PR title
    source_branch: Source branch name
    destination_branch: Target branch (default: main)
    description: PR description in markdown
    close_source_branch: Delete source branch after merge (default: True)

Returns:
    Created PR info with id, url, and state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_slugYes
titleYes
source_branchYes
destination_branchNomain
descriptionNo
close_source_branchNo

Implementation Reference

  • MCP tool handler function for 'create_pull_request', decorated with @mcp.tool() for registration. It validates inputs, calls the Bitbucket client helper, and formats the response.
    @mcp.tool()
    @handle_bitbucket_error
    @formatted
    def create_pull_request(
        repo_slug: str,
        title: str,
        source_branch: str,
        destination_branch: str = "main",
        description: str = "",
        close_source_branch: bool = True,
    ) -> dict:
        """Create a pull request in a Bitbucket repository.
    
        Args:
            repo_slug: Repository slug (e.g., "anzsic_classifier")
            title: PR title
            source_branch: Source branch name
            destination_branch: Target branch (default: main)
            description: PR description in markdown
            close_source_branch: Delete source branch after merge (default: True)
    
        Returns:
            Created PR info with id, url, and state
        """
        client = get_client()
        result = client.create_pull_request(
            repo_slug=repo_slug,
            title=title,
            source_branch=source_branch,
            destination_branch=destination_branch,
            description=description,
            close_source_branch=close_source_branch,
        )
        return {
            "id": result.get("id"),
            "title": result.get("title"),
            "state": result.get("state"),
            "url": client.extract_pr_url(result),
        }
  • Core helper method in BitbucketClient class that constructs the API payload and makes the POST request to create the pull request.
    def create_pull_request(
        self,
        repo_slug: str,
        title: str,
        source_branch: str,
        destination_branch: str = "main",
        description: str = "",
        close_source_branch: bool = True,
        reviewers: Optional[list[str]] = None,
    ) -> dict[str, Any]:
        """Create a pull request.
    
        Args:
            repo_slug: Repository slug
            title: PR title
            source_branch: Source branch name
            destination_branch: Target branch (default: main)
            description: PR description body
            close_source_branch: Delete branch after merge
            reviewers: List of reviewer account IDs (optional)
    
        Returns:
            Dict with PR info including 'id', 'links', 'state'
        """
        payload = {
            "title": title,
            "source": {"branch": {"name": source_branch}},
            "destination": {"branch": {"name": destination_branch}},
            "close_source_branch": close_source_branch,
        }
        if description:
            payload["description"] = description
        if reviewers:
            # Handle both UUID format and account_id format
            payload["reviewers"] = [
                {"uuid": r} if r.startswith("{") else {"account_id": r}
                for r in reviewers
            ]
    
        result = self._request(
            "POST",
            self._repo_path(repo_slug, "pullrequests"),
            json=payload,
        )
        return self._require_result(
            result, "create PR", f"{source_branch} -> {destination_branch}"
        )

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