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
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| ref_name | No | ||
| path | No | ||
| page | No | ||
| per_page | No |
Implementation Reference
- src/gitlab_mcp/server.py:833-860 (handler)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)}" - src/gitlab_mcp/gitlab_client.py:394-409 (handler)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)