gitlab_list_branches
List all branches in a GitLab repository with latest commit information. Use to check available branches, find feature branches, or filter results by search criteria.
Instructions
List repository branches Returns: All branches with latest commit info Use when: Checking branches, finding feature branches Optional: Search filter
Example response: [{ "name": "main", "protected": true, "merged": false, "can_push": true, "default": true, "commit": { "id": "abc123...", "short_id": "abc123", "title": "Latest commit" } }]
Related tools:
gitlab_create_branch: Create new branch
gitlab_delete_branch: Remove branch
gitlab_compare_refs: Compare branches
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | No | Project ID or path (optional - auto-detects from git) |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:238-242 (handler)Handler function that implements the gitlab_list_branches tool by resolving the project ID (auto-detecting from git if not provided) and calling GitLabClient.get_branches() to retrieve the list of branches.def handle_list_branches(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Any: """Handle listing branches""" project_id = require_project_id(client, arguments) return client.get_branches(project_id)
- src/mcp_gitlab/server.py:496-505 (registration)MCP tool registration in server.list_tools() including name, description from tool_descriptions, and input schema allowing optional project_id.types.Tool( name=TOOL_LIST_BRANCHES, description=desc.DESC_LIST_BRANCHES, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": "Project ID or path (optional - auto-detects from git)"} } } ),
- Tool schema definition in tool_definitions.py (duplicate/alternative to server.py) defining input schema for project_id.types.Tool( name=TOOL_LIST_BRANCHES, description=desc.DESC_LIST_BRANCHES, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": "Project ID or path (optional - auto-detects from git)"} } }
- src/mcp_gitlab/tool_handlers.py:1007-1007 (registration)Registration of the handler function in the TOOL_HANDLERS dictionary used by server.call_tool() for dispatching.TOOL_LIST_BRANCHES: handle_list_branches,
- src/mcp_gitlab/constants.py:184-184 (helper)Constant defining the tool name string used throughout the codebase.TOOL_LIST_BRANCHES = "gitlab_list_branches"