Skip to main content
Glama

list_commits

Retrieve commit history for GitLab projects to track changes, filter by branch, tag, or file path, and manage repository revisions.

Instructions

列出 Commits

Args: project_id: 專案 ID 或路徑 ref_name: 分支或標籤名稱(預設為預設分支) path: 檔案路徑篩選 page: 頁碼 per_page: 每頁筆數

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
ref_nameNo
pathNo
pageNo
per_pageNo

Implementation Reference

  • Tool handler for listing commits, registered with @mcp.tool().
    @mcp.tool()
    def list_commits(project_id: int | str, ref_name: str = None,
                     path: str = None, page: int = 1, per_page: int = 20) -> str:
        """列出 Commits
    
        Args:
            project_id: 專案 ID 或路徑
            ref_name: 分支或標籤名稱(預設為預設分支)
            path: 檔案路徑篩選
            page: 頁碼
            per_page: 每頁筆數
        """
        try:
            client = get_client()
            commits = client.list_commits(project_id, ref_name=ref_name, path=path,
                                           page=page, per_page=per_page)
            if not commits:
                return "找不到符合條件的 commits"
    
            lines = [f"找到 {len(commits)} 個 commits:\n"]
            for c in commits:
                lines.append(
                    f"- {c.get('short_id', 'N/A')} {c.get('title', 'N/A')}"
                    f"\n  作者: {c.get('author_name', 'N/A')} | {c.get('authored_date', 'N/A')}"
                )
            return "\n".join(lines)
        except GitLabAPIError as e:
            return f"列出 commits 失敗: {str(e)}"
  • Actual implementation of the commit listing logic in the GitLab client.
    def list_commits(
        self,
        project_id: int | str,
        ref_name: str = None,
        path: str = None,
        page: int = 1,
        per_page: int = 20,
    ) -> list[dict]:
        """GET /projects/:id/repository/commits"""
        pid = self._resolve_project_id(project_id)
        params = {"page": page, "per_page": per_page}
        if ref_name:
            params["ref_name"] = ref_name
        if path:
            params["path"] = path
        return self._get_json(f"/projects/{pid}/repository/commits", params=params)

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