Skip to main content
Glama
ennuiii

Azure DevOps MCP Server with PAT Authentication

by ennuiii

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
NameRequiredDescriptionDefault
repositoryIdYesThe ID of the repository where the branches are located.
topNoThe maximum number of branches to return.

Implementation Reference

  • 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) }], }; }
  • 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."), },
  • 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) }], }; } );
  • 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",
  • 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); }

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/ennuiii/DevOpsMcpPAT'

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