Skip to main content
Glama

gitlab_list_branches

Retrieve and list all branches in a GitLab repository with detailed commit information. Use to monitor feature branches, identify defaults, or filter results for specific branch types.

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

TableJSON Schema
NameRequiredDescriptionDefault
project_idNoProject ID or path (optional - auto-detects from git)

Implementation Reference

  • The main handler function that implements the gitlab_list_branches tool logic. It resolves the project_id (auto-detecting from git if not provided) and calls the GitLabClient's get_branches method.
    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)
  • MCP Tool schema definition including inputSchema with optional project_id parameter and description, registered via server.list_tools().
    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)"} } } ),
  • Maps the tool name TOOL_LIST_BRANCHES ("gitlab_list_branches") to its handler function in the TOOL_HANDLERS dictionary, used by server.call_tool() for dispatching.
    TOOL_LIST_BRANCHES: handle_list_branches,
  • The @server.call_tool() decorator implementation that dispatches to the appropriate handler using TOOL_HANDLERS[name].
    handler = TOOL_HANDLERS.get(name) if not handler: raise ValueError(f"Unknown tool: {name}") # Execute the handler result = handler(client, arguments) # Truncate response if too large result = truncate_response(result, MAX_RESPONSE_SIZE) return [types.TextContent( type="text", text=json.dumps(result, indent=2) )] except gitlab.exceptions.GitlabAuthenticationError as e: logger.error(f"Authentication failed: {e}") error_response = sanitize_error(e, ERROR_AUTH_FAILED) return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))] except gitlab.exceptions.GitlabGetError as e: response_code = getattr(e, 'response_code', None) if response_code == 404: logger.warning(f"Resource not found: {e}") error_response = sanitize_error(e, ERROR_NOT_FOUND) elif response_code == 429: logger.warning(f"Rate limit exceeded: {e}") error_response = sanitize_error(e, ERROR_RATE_LIMIT) else: logger.error(f"GitLab API error: {e}") error_response = sanitize_error(e) return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))] except gitlab.exceptions.GitlabError as e: logger.error(f"General GitLab error: {e}") error_response = sanitize_error(e) return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))] except ValueError as e: logger.warning(f"Invalid input: {e}") error_response = sanitize_error(e, ERROR_INVALID_INPUT) return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))] except Exception as e: logger.error(f"Unexpected error: {e}") error_response = sanitize_error(e, ERROR_GENERIC) return [types.TextContent(type="text", text=json.dumps(error_response, indent=2))]
  • Defines the constant TOOL_LIST_BRANCHES = "gitlab_list_branches" used as the tool name across the codebase.
    TOOL_LIST_BRANCHES = "gitlab_list_branches"

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

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