Skip to main content
Glama
ennuiii

Azure DevOps MCP Server with PAT Authentication

by ennuiii

repo_get_branch_by_name

Retrieve a specific branch from an Azure DevOps repository by providing the repository ID and branch name. Simplifies branch management using PAT authentication.

Instructions

Get a branch by its name.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchNameYesThe name of the branch to retrieve, e.g., 'main' or 'feature-branch'.
repositoryIdYesThe ID of the repository where the branch is located.

Implementation Reference

  • Handler function that retrieves all branches (refs) from the specified repository using the Azure DevOps Git API, finds the one matching the provided branch name (prefixed with 'refs/heads/'), and returns the full branch details or a not-found message.
    async ({ repositoryId, branchName }) => {
      const connection = await connectionProvider();
      const gitApi = await connection.getGitApi();
      const branches = await gitApi.getRefs(repositoryId);
      const branch = branches?.find((branch) => branch.name === `refs/heads/${branchName}`);
      if (!branch) {
        return {
          content: [
            {
              type: "text",
              text: `Branch ${branchName} not found in repository ${repositoryId}`,
            },
          ],
        };
      }
      return {
        content: [{ type: "text", text: JSON.stringify(branch, null, 2) }],
      };
    }
  • Zod input schema defining the required parameters: repositoryId (string, ID of the repo) and branchName (string, name like 'main').
    {
      repositoryId: z.string().describe("The ID of the repository where the branch is located."),
      branchName: z.string().describe("The name of the branch to retrieve, e.g., 'main' or 'feature-branch'."),
    },
  • Registration of the tool 'repo_get_branch_by_name' using McpServer.tool(), referencing REPO_TOOLS.get_branch_by_name, with description, input schema, and inline handler function.
    server.tool(
      REPO_TOOLS.get_branch_by_name,
      "Get a branch by its name.",
      {
        repositoryId: z.string().describe("The ID of the repository where the branch is located."),
        branchName: z.string().describe("The name of the branch to retrieve, e.g., 'main' or 'feature-branch'."),
      },
      async ({ repositoryId, branchName }) => {
        const connection = await connectionProvider();
        const gitApi = await connection.getGitApi();
        const branches = await gitApi.getRefs(repositoryId);
        const branch = branches?.find((branch) => branch.name === `refs/heads/${branchName}`);
        if (!branch) {
          return {
            content: [
              {
                type: "text",
                text: `Branch ${branchName} not found in repository ${repositoryId}`,
              },
            ],
          };
        }
        return {
          content: [{ type: "text", text: JSON.stringify(branch, null, 2) }],
        };
      }
    );
  • REPO_TOOLS constant object that maps the internal handler identifier 'get_branch_by_name' to the tool name 'repo_get_branch_by_name' used in 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",
    };
Install Server

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