Skip to main content
Glama

create_or_update_file

Create or update a file in a GitLab project by specifying the branch, file path, content, and commit message. Use for streamlined file management and version control.

Instructions

Create or update a single file in a GitLab project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchNo
commit_messageNo
contentNo
file_pathNo
previous_pathNo
project_idNo

Implementation Reference

  • Core handler function that implements the create_or_update_file logic by calling GitLab repository/files API (POST/PUT based on existence).
    async createOrUpdateFile(
      projectId: string,
      filePath: string,
      content: string,
      commitMessage: string,
      branch: string,
      previousPath?: string
    ): Promise<GitLabCreateUpdateFileResponse> {
      const encodedPath = encodeURIComponent(filePath);
      const url = `${this.apiUrl}/projects/${encodeURIComponent(projectId)}/repository/files/${encodedPath}`;
    
      const body = {
        branch,
        content,
        commit_message: commitMessage,
        ...(previousPath ? { previous_path: previousPath } : {})
      };
    
      // Check if file exists
      let method = "POST";
      try {
        await this.getFileContents(projectId, filePath, branch);
        method = "PUT";
      } catch (error) {
        // File doesn't exist, use POST
      }
    
      const response = await fetch(url, {
        method,
        headers: {
          "Authorization": `Bearer ${this.token}`,
          "Content-Type": "application/json"
        },
        body: JSON.stringify(body)
      });
    
      if (!response.ok) {
        throw new McpError(
          ErrorCode.InternalError,
          `GitLab API error: ${response.statusText}`
        );
      }
    
      const responseData = await response.json() as Record<string, any>;
      return {
        file_path: filePath,
        branch: branch,
        commit_id: responseData.commit_id || responseData.id || "unknown",
        content: responseData.content
      };
    }
  • MCP server tool dispatcher case that parses arguments using the schema and delegates to gitlabApi.createOrUpdateFile handler.
    case "create_or_update_file": {
      const args = CreateOrUpdateFileSchema.parse(request.params.arguments);
      const result = await gitlabApi.createOrUpdateFile(
        args.project_id,
        args.file_path,
        args.content,
        args.commit_message,
        args.branch,
        args.previous_path
      );
      return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
    }
  • src/index.ts:108-113 (registration)
    Tool registration in ALL_TOOLS array, defining name, description, input schema, and readOnly flag.
    {
      name: "create_or_update_file",
      description: "Create or update a single file in a GitLab project",
      inputSchema: createJsonSchema(CreateOrUpdateFileSchema),
      readOnly: false
    },
  • Zod schema defining input parameters for the create_or_update_file tool.
    export const CreateOrUpdateFileSchema = z.object({
      project_id: z.string(),
      file_path: z.string(),
      content: z.string(),
      commit_message: z.string(),
      branch: z.string(),
      previous_path: z.string().optional()
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states the action without disclosing behavioral traits. It doesn't mention permissions required, whether it's idempotent, how conflicts are handled, or what happens on success/failure. This is a significant gap for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's front-loaded and appropriately sized for the tool's complexity, though it could benefit from additional context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (6 parameters, mutation operation, no annotations, no output schema), the description is incomplete. It doesn't cover parameter meanings, usage scenarios, or expected outcomes, leaving the agent with insufficient information to invoke it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description provides no parameter information. It doesn't explain what 'branch', 'commit_message', 'content', etc., mean or their relationships (e.g., 'previous_path' for renaming). This fails to compensate for the lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('create or update') and resource ('a single file in a GitLab project'), making the purpose unambiguous. It distinguishes from siblings like 'get_file_contents' (read-only) and 'push_files' (batch operations), though it doesn't explicitly contrast with them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'push_files' for multiple files or 'get_file_contents' for reading. The description lacks context about prerequisites, such as needing write permissions or when updates versus creations occur.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/yoda-digital/mcp-gitlab-server'

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