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
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID or URL-encoded path | |
| title | Yes | Merge request title | |
| description | No | Merge request description | |
| source_branch | Yes | Branch containing changes | |
| target_branch | Yes | Branch to merge into | |
| draft | No | Create as draft merge request | |
| allow_collaboration | No | Allow commits from upstream members |
Implementation Reference
- src/api/merge-requests.ts:38-64 (handler)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); } - src/schemas.ts:271-283 (schema)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) }] };