create_or_update_file
Create or update a file in a GitLab project by specifying project ID, file path, content, commit message, and branch. This tool manages file operations for repository workflows.
Instructions
Create or update a single file in a GitLab project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID or URL-encoded path | |
| file_path | Yes | Path where to create/update the file | |
| content | Yes | Content of the file | |
| commit_message | Yes | Commit message | |
| branch | Yes | Branch to create/update the file in | |
| previous_path | No | Path of the file to move/rename |
Implementation Reference
- src/api/files.ts:28-58 (handler)The main handler function that executes the file creation/update logic.
export async function createOrUpdateFile( projectId: string, filePath: string, content: string, commitMessage: string, branch: string, previousPath?: string ): Promise<GitLabCreateUpdateFileResponse> { if (!projectId?.trim()) { throw new Error("Project ID is required"); } if (!filePath?.trim()) { throw new Error("File path is required"); } if (!content) { throw new Error("File content is required"); } if (!commitMessage?.trim()) { throw new Error("Commit message is required"); } if (!branch?.trim()) { throw new Error("Branch is required"); } const encodedPath = encodeFilePath(filePath); const endpoint = `/projects/${encodeProjectId(projectId)}/repository/files/${encodedPath}`; const body = { branch, content, commit_message: commitMessage, - src/schemas.ts:213-219 (schema)Validation schema for the create_or_update_file tool inputs.
export const CreateOrUpdateFileSchema = ProjectParamsSchema.extend({ file_path: z.string().describe("Path where to create/update the file"), content: z.string().describe("Content of the file"), commit_message: z.string().describe("Commit message"), branch: z.string().describe("Branch to create/update the file in"), previous_path: z.string().optional().describe("Path of the file to move/rename") }); - src/server.ts:261-268 (registration)Registration logic where the tool request is handled and mapped to the API function.
case "create_or_update_file": { const args = CreateOrUpdateFileSchema.parse(request.params.arguments); const result = await api.createOrUpdateFile( args.project_id, args.file_path, args.content, args.commit_message, args.branch,