gitlab_cherry_pick_commit
Apply a specific commit to another branch for backporting fixes or selective changes. Input the commit SHA and target branch to create a new commit with the same changes.
Instructions
Apply commit to another branch Returns: New commit on target branch Use when: Backporting fixes, selective changes Creates: New commit with same changes
Example: Backport bug fix to stable
commit: "abc123" (fix from main)
branch: "stable-1.0" (apply here)
Related tools:
gitlab_get_commit: Find commit to pick
gitlab_create_merge_request: MR for picked commit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | Yes | Target branch for commits Type: string Required: Yes Format: Existing branch name Examples: - 'main' (commit to main) - 'feature/add-login' (feature branch) - 'hotfix/security-patch' (hotfix branch) Note: Branch must exist before committing | |
| commit_sha | Yes | Git commit SHA Type: string Format: Abbreviated (min 7 chars) or full 40-character SHA Required: Yes Examples: - 'a1b2c3d' (short form - minimum 7 characters) - 'a1b2c3d4e5f6' (medium form) - 'e83c5163316f89bfbde7d9ab23ca2e25604af290' (full SHA) How to find: git log, GitLab UI, or MR/commit pages | |
| 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:463-470 (handler)Handler function that extracts project_id, commit_sha, and branch from arguments and delegates to GitLabClient.cherry_pick_commit() to perform the cherry-pick operation.def handle_cherry_pick_commit(client: GitLabClient, arguments: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Handle cherry-picking a commit""" project_id = require_project_id(client, arguments) commit_sha = require_argument(arguments, "commit_sha") branch = require_argument(arguments, "branch") return client.cherry_pick_commit(project_id, commit_sha, branch)
- MCP Tool schema definition including name, description, and input schema validation for required parameters: project_id (optional), commit_sha, branch.name=TOOL_CHERRY_PICK_COMMIT, description=desc.DESC_CHERRY_PICK, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "commit_sha": {"type": "string", "description": desc.DESC_COMMIT_SHA}, "branch": {"type": "string", "description": desc.DESC_BRANCH} }, "required": ["commit_sha", "branch"] } ),
- src/mcp_gitlab/tool_handlers.py:1052-1053 (registration)Registration of the tool handler in the TOOL_HANDLERS dictionary, which is used by server.py to dispatch tool calls to the appropriate handler function.TOOL_CHERRY_PICK_COMMIT: handle_cherry_pick_commit, TOOL_COMPARE_REFS: handle_compare_refs,
- src/mcp_gitlab/server.py:799-810 (schema)Duplicate tool schema registration directly in the server's list_tools() handler for MCP protocol compliance.name="gitlab_cherry_pick_commit", description=desc.DESC_CHERRY_PICK, inputSchema={ "type": "object", "properties": { "project_id": {"type": "string", "description": desc.DESC_PROJECT_ID}, "commit_sha": {"type": "string", "description": desc.DESC_COMMIT_SHA}, "branch": {"type": "string", "description": desc.DESC_BRANCH} }, "required": ["commit_sha", "branch"] } ),
- src/mcp_gitlab/constants.py:239-239 (helper)Constant definition for the tool name used across schema definitions, handlers, and registrations.TOOL_CHERRY_PICK_COMMIT = "gitlab_cherry_pick_commit"