create_file
Create a new file in a GitLab repository with specified content and commit message on a target branch.
Instructions
Create a new file in repository.
Args:
project_id: GitLab project ID
file_path: Path for the new file
content: File content
branch: Target branch
commit_message: Commit message
token: GitLab Personal Access Token (optional)
ctx: MCP context (automatically injected)Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| file_path | Yes | ||
| content | Yes | ||
| branch | Yes | ||
| commit_message | Yes | ||
| token | No | ||
| ctx | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The actual implementation of the 'create_file' tool. It is registered via @mcp.tool() decorator and executes the logic to create a new file in a GitLab repository by making a POST request to the GitLab API.
@mcp.tool() async def create_file(project_id: int, file_path: str, content: str, branch: str, commit_message: str, token: str = None, ctx=None) -> str: """Create a new file in repository. Args: project_id: GitLab project ID file_path: Path for the new file content: File content branch: Target branch commit_message: Commit message token: GitLab Personal Access Token (optional) ctx: MCP context (automatically injected) """ import urllib.parse encoded_path = urllib.parse.quote(file_path, safe='') data = { "branch": branch, "content": content, "commit_message": commit_message } result = await make_gitlab_request(f"/projects/{project_id}/repository/files/{encoded_path}", "POST", data, ctx=ctx, token=token) if isinstance(result, dict) and "error" in result: return f"Error creating file: {result['error']}" return f"File created: {file_path} in branch {branch}" - gitlab_clone_mcp_server/server.py:739-765 (registration)The @mcp.tool() decorator on line 739 registers the 'create_file' function as an MCP tool named 'create_file'.
@mcp.tool() async def create_file(project_id: int, file_path: str, content: str, branch: str, commit_message: str, token: str = None, ctx=None) -> str: """Create a new file in repository. Args: project_id: GitLab project ID file_path: Path for the new file content: File content branch: Target branch commit_message: Commit message token: GitLab Personal Access Token (optional) ctx: MCP context (automatically injected) """ import urllib.parse encoded_path = urllib.parse.quote(file_path, safe='') data = { "branch": branch, "content": content, "commit_message": commit_message } result = await make_gitlab_request(f"/projects/{project_id}/repository/files/{encoded_path}", "POST", data, ctx=ctx, token=token) if isinstance(result, dict) and "error" in result: return f"Error creating file: {result['error']}" return f"File created: {file_path} in branch {branch}"