Skip to main content
Glama
pdogra1299
by pdogra1299

delete_branch

Remove specific branches from Bitbucket repositories using workspace, repository, and branch name parameters. Optional force delete for unmerged branches.

Instructions

Delete a branch

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branch_nameYesBranch name to delete
forceNoForce delete even if branch is not merged (optional, default: false)
repositoryYesRepository slug (e.g., "my-repo")
workspaceYesBitbucket workspace/project key (e.g., "PROJ")

Implementation Reference

  • The main handler function that executes the delete_branch tool logic, validating args with isDeleteBranchArgs, making appropriate Bitbucket API DELETE requests for Server (using branch-utils with endPoint) and Cloud, handling 204 responses, and returning success message or error.
    async handleDeleteBranch(args: any) {
      if (!isDeleteBranchArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid arguments for delete_branch'
        );
      }
    
      const { workspace, repository, branch_name, force } = args;
    
      try {
        let apiPath: string;
    
        if (this.apiClient.getIsServer()) {
          // First, we need to get the branch details to find the latest commit
          const branchesPath = `/rest/api/latest/projects/${workspace}/repos/${repository}/branches`;
          const branchesResponse = await this.apiClient.makeRequest<any>('get', branchesPath, undefined, {
            params: {
              filterText: branch_name,
              limit: 100
            }
          });
          
          // Find the exact branch
          const branch = branchesResponse.values?.find((b: any) => b.displayId === branch_name);
          if (!branch) {
            throw new Error(`Branch '${branch_name}' not found`);
          }
          
          // Now delete using branch-utils endpoint with correct format
          apiPath = `/rest/branch-utils/latest/projects/${workspace}/repos/${repository}/branches`;
          
          try {
            await this.apiClient.makeRequest<any>('delete', apiPath, {
              name: branch_name,
              endPoint: branch.latestCommit
            });
          } catch (deleteError: any) {
            // If the error is about empty response but status is 204 (No Content), it's successful
            if (deleteError.originalError?.response?.status === 204 || 
                deleteError.message?.includes('No content to map')) {
              // Branch was deleted successfully
            } else {
              throw deleteError;
            }
          }
        } else {
          // Bitbucket Cloud API
          apiPath = `/repositories/${workspace}/${repository}/refs/branches/${branch_name}`;
          try {
            await this.apiClient.makeRequest<any>('delete', apiPath);
          } catch (deleteError: any) {
            // If the error is about empty response but status is 204 (No Content), it's successful
            if (deleteError.originalError?.response?.status === 204 || 
                deleteError.message?.includes('No content to map')) {
              // Branch was deleted successfully
            } else {
              throw deleteError;
            }
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                message: `Branch '${branch_name}' deleted successfully`,
                branch: branch_name,
                repository: `${workspace}/${repository}`
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.apiClient.handleApiError(error, `deleting branch '${branch_name}' in ${workspace}/${repository}`);
      }
    }
  • Type guard validating input arguments for delete_branch tool: requires workspace, repository, branch_name; optional force boolean.
    export const isDeleteBranchArgs = (
      args: any
    ): args is {
      workspace: string;
      repository: string;
      branch_name: string;
      force?: boolean;
    } =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workspace === 'string' &&
      typeof args.repository === 'string' &&
      typeof args.branch_name === 'string' &&
      (args.force === undefined || typeof args.force === 'boolean');
  • JSON schema definition for the delete_branch tool, including name, description, and inputSchema used for MCP tool listing and validation.
      name: 'delete_branch',
      description: 'Delete a branch',
      inputSchema: {
        type: 'object',
        properties: {
          workspace: {
            type: 'string',
            description: 'Bitbucket workspace/project key (e.g., "PROJ")',
          },
          repository: {
            type: 'string',
            description: 'Repository slug (e.g., "my-repo")',
          },
          branch_name: {
            type: 'string',
            description: 'Branch name to delete',
          },
          force: {
            type: 'boolean',
            description: 'Force delete even if branch is not merged (optional, default: false)',
          },
        },
        required: ['workspace', 'repository', 'branch_name'],
      },
    },
  • src/index.ts:114-115 (registration)
    Dispatches calls to the delete_branch tool to the BranchHandlers.handleDeleteBranch method in the main tool request handler switch statement.
    case 'delete_branch':
      return this.branchHandlers.handleDeleteBranch(request.params.arguments);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Delete a branch' implies a destructive mutation, but it doesn't mention critical behaviors: whether deletion is permanent, requires specific permissions, has side effects (e.g., affecting pull requests), or what happens on success/failure. The schema's 'force' parameter hints at unmerged branch handling, but the description doesn't explain this behavioral nuance.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is maximally concise at three words with zero wasted language. It's front-loaded with the core action and resource. While under-specified, every word earns its place by stating the essential operation.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive mutation tool with 4 parameters, no annotations, and no output schema, the description is severely incomplete. It doesn't address behavioral risks, success conditions, error scenarios, or relationship to sibling tools. The agent lacks sufficient context to use this tool safely and effectively despite the good schema coverage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, providing clear documentation for all 4 parameters. The description adds no parameter information beyond what's in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description, which applies here.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Delete a branch' is a tautology that merely restates the tool name without adding meaningful context. While it clearly indicates a deletion action, it doesn't specify what type of branch (Git branch in Bitbucket) or distinguish this tool from potential alternatives among siblings like 'remove_requested_changes' or 'merge_pull_request' that might also involve removal operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a branch to exist), exclusions (e.g., not for deleting protected branches), or sibling tools like 'get_branch' for verification. This leaves the agent with no context for appropriate tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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