create_merge_request
Generate a new merge request in a GitLab project by specifying source and target branches, title, description, and project details.
Instructions
Create a new merge request in a GitLab project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| allow_collaboration | No | ||
| description | No | ||
| draft | No | ||
| project_id | No | ||
| source_branch | No | ||
| target_branch | No | ||
| title | No |
Implementation Reference
- src/index.ts:144-148 (registration)Registration of the 'create_merge_request' tool in the ALL_TOOLS array, including name, description, input schema, and read-only flag.{ name: "create_merge_request", description: "Create a new merge request in a GitLab project", inputSchema: createJsonSchema(CreateMergeRequestSchema), readOnly: false
- src/index.ts:408-412 (handler)MCP tool handler in the switch statement: parses arguments with CreateMergeRequestSchema, extracts project_id and options, calls gitlabApi.createMergeRequest, and returns JSON response.case "create_merge_request": { const args = CreateMergeRequestSchema.parse(request.params.arguments); const { project_id, ...options } = args; const mergeRequest = await gitlabApi.createMergeRequest(project_id, options); return { content: [{ type: "text", text: JSON.stringify(mergeRequest, null, 2) }] };
- src/schemas.ts:426-428 (schema)CreateMergeRequestSchema definition, which merges project_id with CreateMergeRequestOptionsSchema for input validation.export const CreateMergeRequestSchema = z.object({ project_id: z.string() }).merge(CreateMergeRequestOptionsSchema);
- src/schemas.ts:382-389 (schema)CreateMergeRequestOptionsSchema defining input fields: title, description, source_branch, target_branch, allow_collaboration, draft.export const CreateMergeRequestOptionsSchema = z.object({ title: z.string(), description: z.string().optional(), source_branch: z.string(), target_branch: z.string(), allow_collaboration: z.boolean().optional(), draft: z.boolean().optional() });
- src/gitlab-api.ts:728-780 (handler)Core implementation of createMergeRequest in GitLabApi class: makes POST request to GitLab API to create merge request and parses response.async createMergeRequest( projectId: string, options: z.infer<typeof CreateMergeRequestOptionsSchema> ): Promise<GitLabMergeRequest> { const response = await fetch( `${this.apiUrl}/projects/${encodeURIComponent(projectId)}/merge_requests`, { method: "POST", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json" }, body: JSON.stringify({ title: options.title, description: options.description, source_branch: options.source_branch, target_branch: options.target_branch, allow_collaboration: options.allow_collaboration, draft: options.draft }) } ); if (!response.ok) { throw new McpError( ErrorCode.InternalError, `GitLab API error: ${response.statusText}` ); } const responseData = await response.json() as Record<string, any>; return { id: responseData.id, iid: responseData.iid, project_id: responseData.project_id, title: responseData.title, description: responseData.description || null, state: responseData.state, merged: responseData.merged, author: responseData.author, assignees: responseData.assignees || [], source_branch: responseData.source_branch, target_branch: responseData.target_branch, diff_refs: responseData.diff_refs || null, web_url: responseData.web_url, created_at: responseData.created_at, updated_at: responseData.updated_at, merged_at: responseData.merged_at, closed_at: responseData.closed_at, merge_commit_sha: responseData.merge_commit_sha }; }