Skip to main content
Glama

create_merge_request

Create a new merge request in a GitLab project to propose code changes from a source branch to a target branch for review and integration.

Instructions

Create a new merge request in a GitLab project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID or URL-encoded path
titleYesMerge request title
descriptionNoMerge request description
source_branchYesBranch containing changes
target_branchYesBranch to merge into
draftNoCreate as draft merge request
allow_collaborationNoAllow commits from upstream members

Implementation Reference

  • The actual implementation of the 'createMergeRequest' function that interacts with the GitLab API.
    export async function createMergeRequest(projectId: string, options: CreateMergeRequestOptions): Promise<GitLabMergeRequest> {
      if (!projectId?.trim()) {
        throw new Error("Project ID is required");
      }
      if (!options?.title?.trim()) {
        throw new Error("Merge request title is required");
      }
      if (!options?.source_branch?.trim()) {
        throw new Error("Source branch is required");
      }
      if (!options?.target_branch?.trim()) {
        throw new Error("Target branch is required");
      }
    
      const endpoint = `/projects/${encodeProjectId(projectId)}/merge_requests`;
    
      const mergeRequest = await gitlabPost<GitLabMergeRequest>(endpoint, {
        title: options.title,
        description: options.description,
        source_branch: options.source_branch,
        target_branch: options.target_branch,
        allow_collaboration: options.allow_collaboration,
        draft: options.draft
      });
    
      return GitLabMergeRequestSchema.parse(mergeRequest);
    }
  • Input schema validation for the create_merge_request tool.
    export const CreateMergeRequestSchema = ProjectParamsSchema.extend({
      title: z.string().describe("Merge request title"),
      description: z.string().optional().describe("Merge request description"),
      source_branch: z.string().describe("Branch containing changes"),
      target_branch: z.string().describe("Branch to merge into"),
      draft: z.boolean().optional().describe("Create as draft merge request"),
      allow_collaboration: z.boolean().optional().describe("Allow commits from upstream members")
    });
    
    export const ForkRepositorySchema = ProjectParamsSchema.extend({
      namespace: z.string().optional().describe("Namespace to fork to (full path)")
    });
  • src/server.ts:292-303 (registration)
    Tool handler registration for 'create_merge_request' in the server loop.
    case "create_merge_request": {
      const args = CreateMergeRequestSchema.parse(request.params.arguments);
      const { project_id, ...options } = args;
      const mergeRequest = await api.createMergeRequest(project_id, options);
      return { content: [{ type: "text", text: JSON.stringify(mergeRequest, null, 2) }] };
    }
    
    // Label tools
    case "list_labels": {
      const args = ListLabelsSchema.parse(request.params.arguments);
      const labels = await api.listLabels(args.project_id, args.page, args.per_page);
      return { content: [{ type: "text", text: JSON.stringify(labels, null, 2) }] };

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