repo_list_branches_by_repo
Retrieve a list of branches from a specified repository in Azure DevOps using the repository ID, with options to limit results to a defined number of branches.
Instructions
Retrieve a list of branches for a given repository.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repositoryId | Yes | The ID of the repository where the branches are located. | |
| top | No | The maximum number of branches to return. Defaults to 100. |
Implementation Reference
- src/tools/repos.ts:491-501 (handler)The handler function for the 'repo_list_branches_by_repo' tool. It retrieves all refs from the specified repository using the Azure DevOps Git API, filters and sorts the branch names (excluding non-head refs and limiting to top N), and returns them as JSON.const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const branches = await gitApi.getRefs(repositoryId, undefined); const filteredBranches = branchesFilterOutIrrelevantProperties(branches, top); return { content: [{ type: "text", text: JSON.stringify(filteredBranches, null, 2) }], }; } );
- src/tools/repos.ts:487-490 (schema)Zod schema defining the input parameters for the tool: repositoryId (required string) and top (optional number, default 100).repositoryId: z.string().describe("The ID of the repository where the branches are located."), top: z.number().default(100).describe("The maximum number of branches to return. Defaults to 100."), }, async ({ repositoryId, top }) => {
- src/tools/repos.ts:25-44 (registration)The REPO_TOOLS constant maps internal function names to external tool names, including 'list_branches_by_repo' to 'repo_list_branches_by_repo'. This is used in server.tool calls for registration.const REPO_TOOLS = { list_repos_by_project: "repo_list_repos_by_project", list_pull_requests_by_repo: "repo_list_pull_requests_by_repo", list_pull_requests_by_project: "repo_list_pull_requests_by_project", list_branches_by_repo: "repo_list_branches_by_repo", list_my_branches_by_repo: "repo_list_my_branches_by_repo", list_pull_request_threads: "repo_list_pull_request_threads", list_pull_request_thread_comments: "repo_list_pull_request_thread_comments", get_repo_by_name_or_id: "repo_get_repo_by_name_or_id", get_branch_by_name: "repo_get_branch_by_name", get_pull_request_by_id: "repo_get_pull_request_by_id", create_pull_request: "repo_create_pull_request", update_pull_request: "repo_update_pull_request", update_pull_request_reviewers: "repo_update_pull_request_reviewers", reply_to_comment: "repo_reply_to_comment", create_pull_request_thread: "repo_create_pull_request_thread", resolve_comment: "repo_resolve_comment", search_commits: "repo_search_commits", list_pull_requests_by_commits: "repo_list_pull_requests_by_commits", };
- src/tools/repos.ts:484-486 (registration)The server.tool registration call for the tool, specifying the tool name (via REPO_TOOLS), description, schema, and handler.REPO_TOOLS.list_branches_by_repo, "Retrieve a list of branches for a given repository.", {
- src/tools/repos.ts:46-52 (helper)Helper function used by the handler to filter Git refs to only branch names (refs/heads/), strip the prefix, sort descending, and limit to top N.function branchesFilterOutIrrelevantProperties(branches: GitRef[], top: number) { return branches ?.flatMap((branch) => (branch.name ? [branch.name] : [])) ?.filter((branch) => branch.startsWith("refs/heads/")) .map((branch) => branch.replace("refs/heads/", "")) .sort((a, b) => b.localeCompare(a)) .slice(0, top);