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,
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the action ('create or update') but doesn't specify critical details like required authentication levels, whether it's idempotent, potential rate limits, or what happens on conflicts (e.g., if the file already exists). This leaves significant gaps for an agent to understand the tool's behavior.

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, clear sentence that directly states the tool's purpose without any fluff or redundant information. It's appropriately front-loaded and wastes no words.

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?

For a mutation tool with no annotations and no output schema, the description is insufficient. It doesn't cover behavioral aspects like error conditions, response format, or side effects (e.g., creating commits). Given the complexity of file operations in GitLab, more context is needed for an agent to use this tool effectively.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional semantic context about parameters beyond what's in the schema (e.g., explaining how 'previous_path' relates to renaming). This meets the baseline for high schema coverage.

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 action ('create or update') and resource ('a single file in a GitLab project'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'push_files' or 'get_file_contents', which could handle similar file operations.

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?

The description provides no guidance on when to use this tool versus alternatives like 'push_files' (which might handle multiple files) or 'get_file_contents' (for reading). There's no mention of prerequisites, such as needing appropriate permissions, or when to choose create vs. update scenarios.

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

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