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
| Name | Required | Description | Default |
|---|---|---|---|
| branch | Yes | Name for the new branch | |
| repo_slug | Yes | Repository slug/name | |
| start_point | No | Branch/commit to create from (defaults to main) | main |
| workspace | No | Repository workspace (defaults to kallows) | kallows |
Input Schema (JSON Schema)
{
"properties": {
"branch": {
"description": "Name for the new branch",
"type": "string"
},
"repo_slug": {
"description": "Repository slug/name",
"type": "string"
},
"start_point": {
"default": "main",
"description": "Branch/commit to create from (defaults to main)",
"type": "string"
},
"workspace": {
"default": "kallows",
"description": "Repository workspace (defaults to kallows)",
"type": "string"
}
},
"required": [
"repo_slug",
"branch"
],
"type": "object"
}
Implementation Reference
- src/mcp_bitbucket/server.py:573-614 (handler)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 )]
- src/mcp_bitbucket/server.py:122-149 (registration)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"] } ),
- src/mcp_bitbucket/server.py:125-148 (schema)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"] }