gitlab_get_commit_diff
Extract detailed commit differences for code review, showing added/removed lines and file modifications. Integrates with MCP GitLab Server to simplify change analysis and improve understanding of GitLab project updates.
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 |
|---|---|---|---|
| commit_sha | Yes | Commit SHA | |
| 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 |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:208-213 (handler)The handler function that implements the core logic for the gitlab_get_commit_diff tool. It extracts the project_id (auto-detecting if not provided) and commit_sha parameters, then delegates to the GitLabClient to fetch the commit 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)
- The input schema definition for the gitlab_get_commit_diff tool, defining the expected parameters: optional project_id (string) and required commit_sha (string).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:1034-1036 (registration)Registration of the handle_get_commit_diff handler function in the TOOL_HANDLERS dictionary, which maps tool names to their handler functions. This dictionary is used by the MCP server to dispatch tool calls.TOOL_GET_COMMIT: handle_get_commit, TOOL_GET_COMMIT_DIFF: handle_get_commit_diff, TOOL_GET_MR_APPROVALS: handle_get_merge_request_approvals,
- src/mcp_gitlab/server.py:452-462 (registration)Tool registration and schema definition in the MCP server's list_tools() handler, exposing gitlab_get_commit_diff to MCP clients.types.Tool( name="gitlab_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/constants.py:219-220 (helper)Constant definition for the tool name TOOL_GET_COMMIT_DIFF = "gitlab_get_commit_diff", used throughout the codebase for consistent tool naming.TOOL_GET_COMMIT = "gitlab_get_commit" TOOL_GET_COMMIT_DIFF = "gitlab_get_commit_diff"