Skip to main content
Glama

list_branches

Retrieve and filter branches from a GitLab project using search parameters and pagination controls.

Instructions

列出專案的分支

Args: project_id: 專案 ID 或路徑 search: 搜尋關鍵字 page: 頁碼 per_page: 每頁筆數

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
searchNo
pageNo
per_pageNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for 'list_branches'. This function is registered with @mcp.tool() and calls the GitLabClient to fetch branch information.
    @mcp.tool()
    def list_branches(project_id: int | str, search: str = None,
                      page: int = 1, per_page: int = 20) -> str:
        """列出專案的分支
    
        Args:
            project_id: 專案 ID 或路徑
            search: 搜尋關鍵字
            page: 頁碼
            per_page: 每頁筆數
        """
        try:
            client = get_client()
            branches = client.list_branches(project_id, search=search, page=page, per_page=per_page)
    
            if not branches:
                return "找不到符合條件的分支"
    
            lines = [f"找到 {len(branches)} 個分支:\n"]
            for b in branches:
                flags = []
                if b.get("default"):
                    flags.append("預設")
                if b.get("protected"):
                    flags.append("受保護")
                if b.get("merged"):
                    flags.append("已合併")
                flag_str = f" ({', '.join(flags)})" if flags else ""
    
                commit = b.get("commit", {})
                lines.append(
                    f"- {b['name']}{flag_str}"
                    f"\n  最新 commit: {commit.get('short_id', 'N/A')} {commit.get('title', 'N/A')}"
                )
            return "\n".join(lines)
        except GitLabAPIError as e:
            return f"列出分支失敗: {str(e)}"
  • The underlying client method that performs the API request to list repository branches from GitLab.
    def list_branches(
        self,
        project_id: int | str,
        search: str = None,
        page: int = 1,
        per_page: int = 20,
    ) -> list[dict]:
        """GET /projects/:id/repository/branches"""
        pid = self._resolve_project_id(project_id)
        params = {"page": page, "per_page": per_page}
        if search:
            params["search"] = search
        return self._get_json(f"/projects/{pid}/repository/branches", params=params)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It only states the basic function without mentioning whether this is a read-only operation, what permissions are required, whether results are paginated (implied by parameters but not explicitly stated), rate limits, or error conditions. The description adds minimal behavioral context beyond the bare function.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with a clear purpose statement followed by a parameter list. The structure is front-loaded with the main function first. However, the parameter section uses generic labels without additional explanatory text, which keeps it brief but could be more informative.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that there's an output schema (which handles return values), no annotations, and 4 parameters with 0% schema coverage, the description provides the basic function but lacks important context. It doesn't explain behavioral aspects, usage guidelines, or parameter details that would help an agent use this tool effectively alongside its many siblings.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description includes an Args section that lists all 4 parameters with brief Chinese labels, but with 0% schema description coverage, this provides only basic parameter identification. It doesn't explain parameter semantics, formats, constraints, or relationships. The description compensates somewhat by naming the parameters, but doesn't add meaningful semantic context beyond what's minimally required.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as '列出專案的分支' (list project branches), which is a specific verb+resource combination. It distinguishes itself from siblings like 'get_branch' (singular) and 'compare_branches', but doesn't explicitly differentiate from other list operations like 'list_commits' or 'list_merge_requests' beyond the resource type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to use 'list_branches' versus 'get_branch' (for a single branch) or 'compare_branches', nor does it provide any context about prerequisites or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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