get_merge_request_commits
Retrieve all commits included in a GitLab merge request to review code changes and track development history for specific projects and MRs.
Instructions
取得 Merge Request 包含的 commits
Args: project_id: 專案 ID 或路徑 mr_iid: MR 的 IID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| mr_iid | Yes |
Implementation Reference
- src/gitlab_mcp/server.py:421-444 (handler)The MCP tool handler for 'get_merge_request_commits', which calls the GitLab client's method.
@mcp.tool() def get_merge_request_commits(project_id: int | str, mr_iid: int) -> str: """取得 Merge Request 包含的 commits Args: project_id: 專案 ID 或路徑 mr_iid: MR 的 IID """ try: client = get_client() commits = client.get_merge_request_commits(project_id, mr_iid) if not commits: return "此 MR 沒有 commits" lines = [f"MR !{mr_iid} 包含 {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"取得 MR commits 失敗: {str(e)}" - src/gitlab_mcp/gitlab_client.py:262-267 (handler)The actual implementation of get_merge_request_commits which communicates with the GitLab API.
def get_merge_request_commits( self, project_id: int | str, mr_iid: int ) -> list[dict]: """GET /projects/:id/merge_requests/:iid/commits""" pid = self._resolve_project_id(project_id) return self._get_json(f"/projects/{pid}/merge_requests/{mr_iid}/commits")