compare_versions
Compare commits, branches, or tags to identify differences between code versions in GitLab projects for code review and change analysis.
Instructions
Compare two commits/branches/tags to see the differences between them.
Args:
project_id: The GitLab project ID or URL-encoded path
from_sha: The source commit/branch/tag
to_sha: The target commit/branch/tag
Returns:
Dict containing the comparison information
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| from_sha | Yes | ||
| to_sha | Yes |
Input Schema (JSON Schema)
{
"properties": {
"from_sha": {
"title": "From Sha",
"type": "string"
},
"project_id": {
"title": "Project Id",
"type": "string"
},
"to_sha": {
"title": "To Sha",
"type": "string"
}
},
"required": [
"project_id",
"from_sha",
"to_sha"
],
"type": "object"
}
Implementation Reference
- server.py:174-195 (handler)The main handler function for the 'compare_versions' tool. It is decorated with @mcp.tool(), which handles both registration and schema inference from the function signature and docstring. The function fetches the GitLab project and performs a repository compare between the given SHAs using the GitLab API.@mcp.tool() def compare_versions(ctx: Context, project_id: str, from_sha: str, to_sha: str) -> Dict[str, Any]: """ Compare two commits/branches/tags to see the differences between them. Args: project_id: The GitLab project ID or URL-encoded path from_sha: The source commit/branch/tag to_sha: The target commit/branch/tag Returns: Dict containing the comparison information """ gl = ctx.request_context.lifespan_context project = gl.projects.get(project_id) try: result = project.repository_compare(from_sha, to_sha) except Exception as e: logger.error(f"Failed to compare {from_sha} and {to_sha}: {e}") result = {} return result