revert_commit
Revert a specific commit to a target branch in a GitLab project by specifying the commit SHA and branch.
Instructions
Revert a commit.
Args:
project_id: GitLab project ID
commit_sha: Commit SHA to revert
branch: Target branch for revert
token: GitLab Personal Access Token (optional)
ctx: MCP context (automatically injected)Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| commit_sha | Yes | ||
| branch | Yes | ||
| token | No | ||
| ctx | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The `revert_commit` tool implementation - an MCP tool function decorated with @mcp.tool() that reverts a given commit via the GitLab API endpoint /projects/{project_id}/repository/commits/{commit_sha}/revert. It accepts project_id, commit_sha, branch, optional token, and ctx parameters, sends a POST request with the branch data, and returns a success or error message.
@mcp.tool() async def revert_commit(project_id: int, commit_sha: str, branch: str, token: str = None, ctx=None) -> str: """Revert a commit. Args: project_id: GitLab project ID commit_sha: Commit SHA to revert branch: Target branch for revert token: GitLab Personal Access Token (optional) ctx: MCP context (automatically injected) """ data = {"branch": branch} result = await make_gitlab_request(f"/projects/{project_id}/repository/commits/{commit_sha}/revert", "POST", data, ctx=ctx, token=token) if isinstance(result, dict) and "error" in result: return f"Error reverting commit: {result['error']}" return f"Commit {commit_sha} reverted successfully: {result['short_id']}" - gitlab_clone_mcp_server/server.py:893-894 (registration)The tool is registered via the @mcp.tool() decorator on line 893, which registers `revert_commit` as an MCP tool with the FastMCP server instance.
@mcp.tool() async def revert_commit(project_id: int, commit_sha: str, branch: str, token: str = None, ctx=None) -> str: