Skip to main content
Glama

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
NameRequiredDescriptionDefault
project_idYesProject ID or URL-encoded path
file_pathYesPath where to create/update the file
contentYesContent of the file
commit_messageYesCommit message
branchYesBranch to create/update the file in
previous_pathNoPath of the file to move/rename

Implementation Reference

  • 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,
  • 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,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TheRealChrisThomas/gitlab-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server