Skip to main content
Glama
Korfu
by Korfu

get_branch_restriction

Retrieve a specific branch restriction by its ID to view access control rules for a Bitbucket repository.

Instructions

Get a single branch restriction by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repository_nameYesName of the repository (repo slug)
restriction_idYesThe ID of the branch restriction.

Implementation Reference

  • The main handler function that executes the tool: validates inputs, calls Bitbucket API to get branch restriction by ID, formats details (kind, pattern, users, groups), and returns formatted text or error.
    export async function getBranchRestriction(
      axiosInstance: AxiosInstance,
      config: Config,
      args: any
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      try {
        const { repository_name, restriction_id } = args;
    
        if (!repository_name) {
          throw new Error('Repository name is required');
        }
        if (!restriction_id) {
          throw new Error('Restriction ID is required');
        }
    
        console.error(
          `Fetching branch restriction ${restriction_id} for repository: ${repository_name}`
        );
    
        const response = await axiosInstance.get<BranchRestriction>(
          `/repositories/${config.BITBUCKET_WORKSPACE}/${repository_name}/branch-restrictions/${restriction_id}`
        );
    
        const restriction = response.data;
        const restrictionDetails = `**Restriction Details: ${restriction.id}**
    - Kind: ${restriction.kind}
    - Pattern: ${restriction.pattern}
    - Users: ${
          restriction.users
            ? restriction.users.map(u => u.display_name).join(', ')
            : 'None'
        }
    - Groups: ${
          restriction.groups
            ? restriction.groups.map(g => g.name).join(', ')
            : 'None'
        }`;
    
        return {
          content: [
            {
              type: 'text',
              text: restrictionDetails,
            },
          ],
        };
      } catch (error) {
        console.error('Error fetching branch restriction:', error);
        return {
          content: [
            {
              type: 'text',
              text: `Error fetching branch restriction: ${
                error instanceof Error ? error.message : 'Unknown error'
              }`,
            },
          ],
        };
      }
    } 
  • Tool metadata definition with name, description, and input schema specifying required string parameters: repository_name and restriction_id.
    export const getBranchRestrictionTool = {
      name: 'get_branch_restriction',
      description: 'Get a single branch restriction by its ID.',
      inputSchema: {
        type: 'object',
        properties: {
          repository_name: {
            type: 'string',
            description: 'Name of the repository (repo slug)',
          },
          restriction_id: {
            type: 'string',
            description: 'The ID of the branch restriction.',
          },
        },
        required: ['repository_name', 'restriction_id'],
      },
    };
  • src/index.ts:41-43 (registration)
    Imports the handler function and tool definition for use in registration.
      getBranchRestriction,
      getBranchRestrictionTool,
    } from './tools/branch-restrictions/getBranchRestriction.js';
  • src/index.ts:123-123 (registration)
    Registers the tool metadata (schema) in the list of tools for ListToolsRequestHandler.
    getBranchRestrictionTool,
  • src/index.ts:162-162 (registration)
    Registers the handler function in the dispatch map for CallToolRequestHandler.
    get_branch_restriction: getBranchRestriction,

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

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