gitlab_get_commit_diff
Retrieve detailed file changes for a specific commit to support code review and change analysis. Shows added/removed lines and file modifications.
Instructions
Get commit diff/changes Returns: Detailed diff of all changed files Use when: Code review, understanding changes Shows: Added/removed lines, file modifications
Example response: [{ "old_path": "src/main.py", "new_path": "src/main.py", "diff": "@@ -10,3 +10,5 @@\n def main():\n- print('Hello')\n+ print('Hello, World!')\n+ return 0", "new_file": false, "deleted_file": false }]
Related tools:
gitlab_get_commit: Commit metadata
gitlab_compare_refs: Compare branches
gitlab_smart_diff: Advanced diff options
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | No | Project identifier (auto-detected if not provided) Type: integer OR string Format: numeric ID or 'namespace/project' Optional: Yes - auto-detects from current git repository Examples: - 12345 (numeric ID) - 'gitlab-org/gitlab' (namespace/project path) - 'my-group/my-subgroup/my-project' (nested groups) Note: If in a git repo with GitLab remote, this can be omitted | |
| commit_sha | Yes | Commit SHA |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:208-214 (handler)Handler function that implements the gitlab_get_commit_diff tool. Extracts project_id and commit_sha from arguments, then calls client.get_commit_diff() to retrieve the diff.def handle_get_commit_diff(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting commit diff""" project_id = require_project_id(client, arguments) commit_sha = require_argument(arguments, "commit_sha") return client.get_commit_diff(project_id, commit_sha)
- Pydantic/MCP tool schema definition including inputSchema with project_id (optional) and required commit_sha.types.Tool( name=TOOL_GET_COMMIT_DIFF, description=desc.DESC_GET_COMMIT_DIFF, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "commit_sha": {"type": "string", "description": "Commit SHA"} }, "required": ["commit_sha"] } ),
- src/mcp_gitlab/tool_handlers.py:1035-1035 (registration)Registration of the tool name to its handler function in the TOOL_HANDLERS dictionary.TOOL_GET_COMMIT_DIFF: handle_get_commit_diff,
- src/mcp_gitlab/constants.py:220-220 (helper)Constant definition for the tool name used across the codebase.TOOL_GET_COMMIT_DIFF = "gitlab_get_commit_diff"