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

NameRequiredDescriptionDefault
branchNo
project_idNo
refNo

Input Schema (JSON Schema)

{ "properties": { "branch": { "type": "string" }, "project_id": { "type": "string" }, "ref": { "type": "string" } }, "type": "object" }

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()); }

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