repo_list_my_branches_by_repo
Retrieve a list of branches you own in a specified Azure DevOps repository using a repository ID, with options to limit results. Simplifies branch management with PAT authentication.
Instructions
Retrieve a list of my branches for a given repository Id.
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. |
Implementation Reference
- src/tools/repos.ts:510-520 (handler)Handler function that retrieves the current user's branches from the specified repository using Azure DevOps Git API with includeMyBranches set to true, filters irrelevant properties, sorts, and limits the top results.async ({ repositoryId, top }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const branches = await gitApi.getRefs(repositoryId, undefined, undefined, undefined, undefined, true); const filteredBranches = branchesFilterOutIrrelevantProperties(branches, top); return { content: [{ type: "text", text: JSON.stringify(filteredBranches, null, 2) }], }; }
- src/tools/repos.ts:506-509 (schema)Zod schema defining input parameters: repositoryId (string) and top (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."), },
- src/tools/repos.ts:503-521 (registration)Tool registration using McpServer.tool() with the tool name REPO_TOOLS.list_my_branches_by_repo, description, schema, and handler.server.tool( REPO_TOOLS.list_my_branches_by_repo, "Retrieve a list of my branches for a given repository Id.", { 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."), }, async ({ repositoryId, top }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const branches = await gitApi.getRefs(repositoryId, undefined, undefined, undefined, undefined, true); const filteredBranches = branchesFilterOutIrrelevantProperties(branches, top); return { content: [{ type: "text", text: JSON.stringify(filteredBranches, null, 2) }], }; } );
- src/tools/repos.ts:30-30 (registration)Constant definition mapping the internal key 'list_my_branches_by_repo' to the tool name 'repo_list_my_branches_by_repo'.list_my_branches_by_repo: "repo_list_my_branches_by_repo",
- src/tools/repos.ts:46-53 (helper)Helper function to extract, filter (heads only), clean (remove refs/heads/), sort descending, and limit branch names.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); }