Skip to main content
Glama
Kallows

MCP Bitbucket Python

by Kallows

bb_create_branch

Create a new branch in a Bitbucket repository by specifying the repository slug, branch name, and optional start point or workspace. Simplifies repository management tasks.

Instructions

Create a new branch in a Bitbucket repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchYesName for the new branch
repo_slugYesRepository slug/name
start_pointNoBranch/commit to create from (defaults to main)main
workspaceNoRepository workspace (defaults to kallows)kallows

Implementation Reference

  • Handler implementation for the bb_create_branch tool. It fetches the hash of the start point branch, then creates a new branch from that hash using Bitbucket API.
    elif name == "bb_create_branch":
        workspace = arguments.get("workspace", "kallows")
        repo_slug = arguments.get("repo_slug")
        branch_name = arguments.get("branch")
        start_point = arguments.get("start_point", "main")
    
        # First get the hash of the start point
        ref_url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches/{start_point}"
        ref_response = requests.get(ref_url, auth=auth, headers=headers)
        
        if ref_response.status_code != 200:
            return [types.TextContent(
                type="text",
                text=f"Failed to get start point reference: {ref_response.status_code}\n{format_permission_error(ref_response.text)}",
                isError=True
            )]
        
        start_hash = ref_response.json()['target']['hash']
        
        # Create the new branch
        url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches"
        payload = {
            "name": branch_name,
            "target": {
                "hash": start_hash
            }
        }
        
        response = requests.post(url, json=payload, auth=auth, headers=headers)
    
        if response.status_code in (200, 201):
            branch_url = response.json().get('links', {}).get('html', {}).get('href', '')
            return [types.TextContent(
                type="text",
                text=f"Branch '{branch_name}' created successfully\nURL: {branch_url}"
            )]
        else:
            return [types.TextContent(
                type="text",
                text=f"Failed to create branch: {response.status_code}\n{format_permission_error(response.text)}",
                isError=True
            )]
  • Registration of the bb_create_branch tool in the list_tools handler, including description and input schema definition.
    types.Tool(
        name="bb_create_branch",
        description="Create a new branch in a Bitbucket repository",
        inputSchema={
            "type": "object", 
            "properties": {
                "workspace": {
                    "type": "string",
                    "description": "Repository workspace (defaults to kallows)",
                    "default": "kallows"
                },
                "repo_slug": {
                    "type": "string",
                    "description": "Repository slug/name"
                },
                "branch": {
                    "type": "string",
                    "description": "Name for the new branch"
                },
                "start_point": {
                    "type": "string", 
                    "description": "Branch/commit to create from (defaults to main)",
                    "default": "main"
                }
            },
            "required": ["repo_slug", "branch"]
        }
    ),        
  • Input schema definition for the bb_create_branch tool, specifying parameters like workspace, repo_slug, branch, and start_point.
    inputSchema={
        "type": "object", 
        "properties": {
            "workspace": {
                "type": "string",
                "description": "Repository workspace (defaults to kallows)",
                "default": "kallows"
            },
            "repo_slug": {
                "type": "string",
                "description": "Repository slug/name"
            },
            "branch": {
                "type": "string",
                "description": "Name for the new branch"
            },
            "start_point": {
                "type": "string", 
                "description": "Branch/commit to create from (defaults to main)",
                "default": "main"
            }
        },
        "required": ["repo_slug", "branch"]
    }
Install Server

Other Tools

Related Tools

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

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