Skip to main content
Glama

get_branch

Retrieve detailed information about a specific branch in a GitLab project by providing the project identifier and branch name.

Instructions

取得分支詳細資訊

Args: project_id: 專案 ID 或路徑 branch_name: 分支名稱

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
branch_nameYes

Implementation Reference

  • The `get_branch` tool handler function in `src/gitlab_mcp/server.py`. It fetches branch details using the GitLab client and formats the information for the user. Note that while `@mcp.tool()` is not immediately preceding this specific function in the file, it is part of the tool implementation set.
    def get_branch(project_id: int | str, branch_name: str) -> str:
        """取得分支詳細資訊
    
        Args:
            project_id: 專案 ID 或路徑
            branch_name: 分支名稱
        """
        try:
            client = get_client()
            b = client.get_branch(project_id, branch_name)
    
            commit = b.get("commit", {})
            flags = []
            if b.get("default"):
                flags.append("預設")
            if b.get("protected"):
                flags.append("受保護")
            if b.get("merged"):
                flags.append("已合併")
    
            return f"""分支: {b['name']}
    屬性: {', '.join(flags) if flags else '無'}
    最新 Commit: {commit.get('id', 'N/A')}
    Commit 標題: {commit.get('title', 'N/A')}
    Commit 作者: {commit.get('author_name', 'N/A')}
    Commit 時間: {commit.get('committed_date', 'N/A')}
    網址: {b.get('web_url', '')}"""
        except GitLabAPIError as e:
            return f"取得分支失敗: {str(e)}"

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/snowild/gitlab-mcp'

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