Skip to main content
Glama
pdogra1299
by pdogra1299

list_branches

Retrieve a list of branches in a Bitbucket repository, filter by name pattern, and manage pagination with start index and limit parameters.

Instructions

List branches in a repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNoFilter branches by name pattern (optional)
limitNoMaximum number of branches to return (default: 25)
repositoryYesRepository slug (e.g., "my-repo")
startNoStart index for pagination (default: 0)
workspaceYesBitbucket workspace/project key (e.g., "PROJ")

Implementation Reference

  • Core handler function that implements the list_branches tool: validates args, calls Bitbucket API (Server/Cloud), formats branches with pagination info, returns JSON text content.
    async handleListBranches(args: any) {
      if (!isListBranchesArgs(args)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Invalid arguments for list_branches'
        );
      }
    
      const { workspace, repository, filter, limit = 25, start = 0 } = args;
    
      try {
        let apiPath: string;
        let params: any = {};
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server API - using latest version for better filtering support
          apiPath = `/rest/api/latest/projects/${workspace}/repos/${repository}/branches`;
          params = {
            limit,
            start,
            details: true,
            orderBy: 'MODIFICATION'
          };
          if (filter) {
            params.filterText = filter;
          }
        } else {
          // Bitbucket Cloud API
          apiPath = `/repositories/${workspace}/${repository}/refs/branches`;
          params = {
            pagelen: limit,
            page: Math.floor(start / limit) + 1,
          };
          if (filter) {
            params.q = `name ~ "${filter}"`;
          }
        }
    
        const response = await this.apiClient.makeRequest<any>('get', apiPath, undefined, { params });
    
        // Format the response
        let branches: any[] = [];
        let totalCount = 0;
        let nextPageStart = null;
    
        if (this.apiClient.getIsServer()) {
          // Bitbucket Server response
          branches = (response.values || []).map((branch: any) => ({
            name: branch.displayId,
            id: branch.id,
            latest_commit: branch.latestCommit,
            is_default: branch.isDefault || false
          }));
          totalCount = response.size || 0;
          if (!response.isLastPage && response.nextPageStart !== undefined) {
            nextPageStart = response.nextPageStart;
          }
        } else {
          // Bitbucket Cloud response
          branches = (response.values || []).map((branch: any) => ({
            name: branch.name,
            target: branch.target.hash,
            is_default: branch.name === 'main' || branch.name === 'master'
          }));
          totalCount = response.size || 0;
          if (response.next) {
            nextPageStart = start + limit;
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                branches,
                total_count: totalCount,
                start,
                limit,
                has_more: nextPageStart !== null,
                next_start: nextPageStart
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return this.apiClient.handleApiError(error, `listing branches in ${workspace}/${repository}`);
      }
    }
  • Tool definition schema for list_branches including input parameters: workspace, repository, optional filter/limit/start.
      name: 'list_branches',
      description: 'List branches in a repository',
      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")',
          },
          filter: {
            type: 'string',
            description: 'Filter branches by name pattern (optional)',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of branches to return (default: 25)',
          },
          start: {
            type: 'number',
            description: 'Start index for pagination (default: 0)',
          },
        },
        required: ['workspace', 'repository'],
      },
    },
  • Type guard function isListBranchesArgs for runtime validation of tool input arguments.
    export const isListBranchesArgs = (
      args: any
    ): args is {
      workspace: string;
      repository: string;
      filter?: string;
      limit?: number;
      start?: number;
    } =>
      typeof args === 'object' &&
      args !== null &&
      typeof args.workspace === 'string' &&
      typeof args.repository === 'string' &&
      (args.filter === undefined || typeof args.filter === 'string') &&
      (args.limit === undefined || typeof args.limit === 'number') &&
      (args.start === undefined || typeof args.start === 'number');
  • src/index.ts:112-113 (registration)
    Registration/dispatch in main MCP server: routes 'list_branches' calls to BranchHandlers.handleListBranches.
    case 'list_branches':
      return this.branchHandlers.handleListBranches(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 but offers minimal information. It doesn't mention that this is a read-only operation (implied by 'List'), pagination behavior (though hinted in schema), rate limits, authentication requirements, or what the output format looks like (no output schema). The description adds almost no behavioral context beyond the basic action.

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 extremely concise—a single sentence with no wasted words. It's front-loaded with the core purpose ('List branches in a repository'), making it immediately clear. Every word earns its place, though this conciseness comes at the cost of completeness.

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?

Given the tool's moderate complexity (5 parameters, no output schema, no annotations), the description is insufficiently complete. It doesn't explain the return format, pagination strategy, error conditions, or how it differs from similar tools. The high schema coverage helps, but the description alone leaves significant gaps for an agent to understand the tool's full behavior.

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?

The schema has 100% description coverage, so parameters are well-documented in the structured data. The description adds no additional parameter semantics beyond what's in the schema—it doesn't explain relationships between parameters (e.g., how 'filter' interacts with 'limit') or provide usage examples. This meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('List') and resource ('branches in a repository'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_branch' (which retrieves a single branch) or 'list_branch_commits' (which lists commits for a branch), missing an opportunity for clearer distinction.

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

Usage Guidelines2/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. For example, it doesn't mention that 'get_branch' is for retrieving details of a specific branch, or that 'list_branch_commits' focuses on commit history rather than branch listing. There's no context about prerequisites or typical use cases.

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