create_commit
Create a commit in a GitLab project on a specified branch, supporting file create, update, or delete actions with custom content.
Instructions
Create a commit with file changes.
Args:
project_id: GitLab project ID
branch: Target branch
commit_message: Commit message
file_path: Path to the file
file_content: File content
action: Action (create, update, delete)
token: GitLab Personal Access Token (optional)
ctx: MCP context (automatically injected)Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| branch | Yes | ||
| commit_message | Yes | ||
| file_path | Yes | ||
| file_content | Yes | ||
| action | No | create | |
| token | No | ||
| ctx | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The async function `create_commit` is the handler for the 'create_commit' tool. It accepts project_id, branch, commit_message, file_path, file_content, and action parameters, then makes a POST request to the GitLab API's /projects/{project_id}/repository/commits endpoint to create a commit with the specified file changes.
@mcp.tool() async def create_commit(project_id: int, branch: str, commit_message: str, file_path: str, file_content: str, action: str = "create", token: str = None, ctx=None) -> str: """Create a commit with file changes. Args: project_id: GitLab project ID branch: Target branch commit_message: Commit message file_path: Path to the file file_content: File content action: Action (create, update, delete) token: GitLab Personal Access Token (optional) ctx: MCP context (automatically injected) """ data = { "branch": branch, "commit_message": commit_message, "actions": [{ "action": action, "file_path": file_path, "content": file_content if action != "delete" else None }] } result = await make_gitlab_request(f"/projects/{project_id}/repository/commits", "POST", data, ctx=ctx, token=token) if isinstance(result, dict) and "error" in result: return f"Error creating commit: {result['error']}" return f"Commit created: {result['short_id']} - {result['title']}" - gitlab_clone_mcp_server/server.py:365-366 (registration)The `@mcp.tool()` decorator on line 365 registers the `create_commit` function as an MCP tool named 'create_commit' (Python function name is used as the tool name by FastMCP).
@mcp.tool() async def create_commit(project_id: int, branch: str, commit_message: str, file_path: str, file_content: str, action: str = "create", token: str = None, ctx=None) -> str: - The function signature defines the input schema for create_commit: project_id (int), branch (str), commit_message (str), file_path (str), file_content (str), action (str with default 'create'), token (optional str), ctx (injected context). The docstring describes each parameter.
async def create_commit(project_id: int, branch: str, commit_message: str, file_path: str, file_content: str, action: str = "create", token: str = None, ctx=None) -> str: """Create a commit with file changes. Args: project_id: GitLab project ID branch: Target branch commit_message: Commit message file_path: Path to the file file_content: File content action: Action (create, update, delete) token: GitLab Personal Access Token (optional) ctx: MCP context (automatically injected)