get_branch_restriction
Retrieve specific branch restriction details by ID to manage repository access controls and understand permission settings in Bitbucket.
Instructions
Get a single branch restriction by its ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repository_name | Yes | Name of the repository (repo slug) | |
| restriction_id | Yes | The ID of the branch restriction. |
Implementation Reference
- The handler function that executes the tool: validates inputs, calls Bitbucket API to get branch restriction by ID, formats details (kind, pattern, users, groups), handles errors.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 definition with name, description, and input schema requiring 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:162-162 (registration)Registration of the handler in the tool dispatch map for CallToolRequest.get_branch_restriction: getBranchRestriction,
- src/index.ts:123-123 (registration)Registration of the tool in the list returned by ListToolsRequest.getBranchRestrictionTool,
- src/index.ts:41-43 (registration)Import of the tool definition and handler from its module.getBranchRestriction, getBranchRestrictionTool, } from './tools/branch-restrictions/getBranchRestriction.js';