bb_write_file
Write or update files in a Bitbucket repository, specifying workspace, repo slug, path, content, commit message, and branch. Streamline file management within Bitbucket repositories.
Instructions
Write/update a file in a Bitbucket repository
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | No | Branch name (defaults to main/master) | main |
| content | Yes | Content to write to the file | |
| message | No | Commit message | Update file via MCP |
| path | Yes | Path where to create/update the file | |
| repo_slug | Yes | Repository slug/name | |
| workspace | No | Repository workspace (defaults to kallows) | kallows |
Input Schema (JSON Schema)
{
"properties": {
"branch": {
"default": "main",
"description": "Branch name (defaults to main/master)",
"type": "string"
},
"content": {
"description": "Content to write to the file",
"type": "string"
},
"message": {
"default": "Update file via MCP",
"description": "Commit message",
"type": "string"
},
"path": {
"description": "Path where to create/update the file",
"type": "string"
},
"repo_slug": {
"description": "Repository slug/name",
"type": "string"
},
"workspace": {
"default": "kallows",
"description": "Repository workspace (defaults to kallows)",
"type": "string"
}
},
"required": [
"repo_slug",
"path",
"content"
],
"type": "object"
}
Implementation Reference
- src/mcp_bitbucket/server.py:670-701 (handler)Handler implementation for the 'bb_write_file' tool. Extracts arguments, constructs Bitbucket API URL, posts file content using multipart form data, and returns success or error message.elif name == "bb_write_file": workspace = arguments.get("workspace", "kallows") repo_slug = arguments.get("repo_slug") file_path = arguments.get("path") content = arguments.get("content") message = arguments.get("message", "Update file via MCP") branch = arguments.get("branch", "main") url = f"https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/src" # Prepare form data for file upload files = { file_path: (None, content) } data = { 'message': message, 'branch': branch } response = requests.post(url, auth=auth, files=files, data=data) if response.status_code in (200, 201): return [types.TextContent( type="text", text=f"File {file_path} updated successfully" )] else: return [types.TextContent( type="text", text=f"Failed to write file: {response.status_code}\n{format_permission_error(response.text)}", isError=True )]
- src/mcp_bitbucket/server.py:197-233 (registration)Registration of the 'bb_write_file' tool with MCP server, including description and detailed input schema defining parameters and requirements.types.Tool( name="bb_write_file", description="Write/update a file 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" }, "path": { "type": "string", "description": "Path where to create/update the file" }, "content": { "type": "string", "description": "Content to write to the file" }, "message": { "type": "string", "description": "Commit message", "default": "Update file via MCP" }, "branch": { "type": "string", "description": "Branch name (defaults to main/master)", "default": "main" } }, "required": ["repo_slug", "path", "content"] } ),