Skip to main content
Glama

create_branch

Create a new branch in a GitLab project by specifying the branch name, project ID, and reference. Integrates with the GitLab MCP Server for efficient project management.

Instructions

Create a new branch in a GitLab project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchNo
project_idNo
refNo

Implementation Reference

  • Main MCP tool handler for 'create_branch': parses input schema, fetches default branch ref if not provided, calls GitLab API via gitlabApi.createBranch, and returns the branch details as JSON.
    case "create_branch": {
      const args = CreateBranchSchema.parse(request.params.arguments);
      let ref = args.ref;
      if (!ref) {
        ref = await gitlabApi.getDefaultBranchRef(args.project_id);
      }
    
      const branch = await gitlabApi.createBranch(args.project_id, {
        name: args.branch,
        ref
      });
    
      return { content: [{ type: "text", text: JSON.stringify(branch, null, 2) }] };
    }
  • src/index.ts:156-161 (registration)
    Tool registration in ALL_TOOLS array, defining name, description, input schema, and readOnly flag.
    {
      name: "create_branch",
      description: "Create a new branch in a GitLab project",
      inputSchema: createJsonSchema(CreateBranchSchema),
      readOnly: false
    },
  • Zod schema for 'create_branch' tool input validation: requires project_id and branch, optional ref.
    export const CreateBranchSchema = z.object({
      project_id: z.string(),
      branch: z.string(),
      ref: z.string().optional()
    });
  • GitLabApi helper method that performs the actual POST request to create a branch, handles response parsing and error throwing.
    async createBranch(
      projectId: string,
      options: z.infer<typeof CreateBranchOptionsSchema>
    ): Promise<GitLabReference> {
      const response = await fetch(
        `${this.apiUrl}/projects/${encodeURIComponent(projectId)}/repository/branches`,
        {
          method: "POST",
          headers: {
            "Authorization": `Bearer ${this.token}`,
            "Content-Type": "application/json"
          },
          body: JSON.stringify({
            branch: options.name,
            ref: options.ref
          })
        }
      );
    
      if (!response.ok) {
        throw new McpError(
          ErrorCode.InternalError,
          `GitLab API error: ${response.statusText}`
        );
      }
    
      return GitLabReferenceSchema.parse(await response.json());
    }
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 states 'Create' implies a write operation, but doesn't mention permissions required (e.g., developer access), whether the branch is protected, what happens if the branch already exists, or rate limits. 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, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 (a write operation with 3 parameters), lack of annotations, 0% schema coverage, and no output schema, the description is incomplete. It doesn't address behavioral aspects, parameter meanings, or usage context, leaving the agent with insufficient information to use the tool effectively.

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?

The schema description coverage is 0%, so the description must compensate for three undocumented parameters. It doesn't explain what 'branch', 'project_id', or 'ref' mean (e.g., that 'ref' is the source branch/tag), their formats, or which are required. This leaves parameters semantically unclear.

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') and resource ('new branch in a GitLab project'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling tools (like create_merge_request or create_repository), which would require mentioning it's specifically for branch creation rather than other GitLab entities.

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. It doesn't mention prerequisites (e.g., needing an existing project), compare it to similar tools (like create_merge_request for branching with merge intent), or specify use cases (e.g., for feature development or hotfixes).

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