gitlab_smart_diff
Generate structured and customizable diffs between Git refs with configurable context lines and file size limits. Optimized for handling large comparisons efficiently.
Instructions
Get intelligent diff between refs Returns: Structured diff with smart chunking Use when: Need customizable diffs Features: Context control, size limits
Advantages over standard diff:
Configurable context lines
File size filtering
Better for large diffs
Related tools:
gitlab_get_commit_diff: Simple commit diff
gitlab_compare_refs: Basic comparison
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_lines | No | Context lines in diff Type: integer Range: 0-10 Default: 3 Examples: - 0: Only changed lines - 3: Standard context - 10: Maximum context Use case: Balance between context and size | |
| from_ref | Yes | Source reference for comparison Type: string Required: Yes Format: Branch, tag, or commit SHA Examples: - 'feature/new-api' (branch) - 'v1.0.0' (tag) - 'abc123def' (commit) Use case: Starting point for comparison | |
| max_file_size | No | Maximum file size for diffs Type: integer Unit: Bytes Default: 50000 (50KB) Examples: - 10000: 10KB limit - 50000: 50KB (default) - 100000: 100KB for larger files Use case: Prevent huge diffs from overwhelming output | |
| 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 | |
| to_ref | Yes | Target reference for comparison Type: string Required: Yes Format: Branch, tag, or commit SHA Examples: - 'main' (branch) - 'v2.0.0' (tag) - '456789abc' (commit) Use case: Ending point for comparison |
Implementation Reference
- src/mcp_gitlab/tool_handlers.py:501-509 (handler)The core handler function that parses tool arguments (project_id, from_ref, to_ref, context_lines, max_file_size) and delegates to GitLabClient.smart_diff for generating an intelligent diff.def handle_smart_diff(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle getting a smart diff between refs""" project_id = require_project_id(client, arguments) from_ref = require_argument(arguments, "from_ref") to_ref = require_argument(arguments, "to_ref") context_lines = get_argument(arguments, "context_lines", 3) max_file_size = get_argument(arguments, "max_file_size", 50000) return client.smart_diff(project_id, from_ref, to_ref, context_lines, max_file_size)
- Input schema definition specifying parameters, types, descriptions, defaults, and required fields for the gitlab_smart_diff tool.types.Tool( name=TOOL_SMART_DIFF, description=desc.DESC_SMART_DIFF, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "from_ref": {"type": "string", "description": desc.DESC_FROM_REF}, "to_ref": {"type": "string", "description": desc.DESC_TO_REF}, "context_lines": {"type": "integer", "description": desc.DESC_CONTEXT_LINES, "default": 3}, "max_file_size": {"type": "integer", "description": desc.DESC_MAX_FILE_SIZE, "default": 50000} }, "required": ["from_ref", "to_ref"] } ),
- src/mcp_gitlab/tool_handlers.py:1063-1063 (registration)Registration of the tool name to its handler function in the TOOL_HANDLERS dictionary, used by server.py for dispatching tool calls.TOOL_SMART_DIFF: handle_smart_diff,
- src/mcp_gitlab/server.py:854-867 (registration)Tool registration in the server's list_tools() response, defining the tool for MCP protocol including schema and description.types.Tool( name="gitlab_smart_diff", description=desc.DESC_SMART_DIFF, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "from_ref": {"type": "string", "description": desc.DESC_FROM_REF}, "to_ref": {"type": "string", "description": desc.DESC_TO_REF}, "context_lines": {"type": "integer", "description": desc.DESC_CONTEXT_LINES, "default": 3}, "max_file_size": {"type": "integer", "description": desc.DESC_MAX_FILE_SIZE, "default": 50000} }, "required": ["from_ref", "to_ref"] }
- src/mcp_gitlab/constants.py:246-246 (helper)Constant definition for the tool name, used consistently across registration, handlers, and tests.TOOL_SMART_DIFF = "gitlab_smart_diff"