Gitlab Accept MR Tool
Accept and merge GitLab merge requests for specified projects with customizable options like commit messages, branch removal, and squash merging.
Instructions
接受并合并指定项目的合并请求,支持自定义合并选项。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | No | 需要返回的字段路径数组 | |
| mergeOptions | No | 合并选项 | |
| mergeRequestId | Yes | 合并请求 ID | |
| projectId | Yes | 项目 ID |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"fields": {
"description": "需要返回的字段路径数组",
"items": {
"type": "string"
},
"type": "array"
},
"mergeOptions": {
"additionalProperties": false,
"description": "合并选项",
"properties": {
"mergeCommitMessage": {
"type": "string"
},
"shouldRemoveSourceBranch": {
"type": "boolean"
},
"squash": {
"type": "boolean"
}
},
"type": "object"
},
"mergeRequestId": {
"description": "合并请求 ID",
"type": "number"
},
"projectId": {
"description": "项目 ID",
"type": "string"
}
},
"required": [
"projectId",
"mergeRequestId"
],
"type": "object"
}
Implementation Reference
- src/tools/GitlabAcceptMRTool.ts:19-67 (handler)Handler function that executes the tool: resolves project ID, performs GitLab API PUT to merge MR, filters response if needed, handles errors.async execute(args: unknown, context: Context<Record<string, unknown> | undefined>) { const typedArgs = args as { projectId: string | number; mergeRequestId: number; mergeOptions?: { mergeCommitMessage?: string; squash?: boolean; shouldRemoveSourceBranch?: boolean; }; fields?: string[]; }; const { projectId: projectIdOrName, mergeRequestId, mergeOptions, fields } = typedArgs; try { const client = createGitlabClientFromContext(context); const resolvedProjectId = await client.resolveProjectId(projectIdOrName); if (!resolvedProjectId) { throw new Error(`无法解析项目 ID 或名称:${projectIdOrName}`); } const endpoint = `/projects/${encodeURIComponent(String(resolvedProjectId))}/merge_requests/${mergeRequestId}/merge`; const response = await client.apiRequest(endpoint, "PUT", undefined, mergeOptions); if (!client.isValidResponse(response)) { throw new Error(`GitLab API error: ${response?.message || 'Unknown error'}`); } if (fields) { const filteredResponse = filterResponseFields(response, fields); return { content: [{ type: "text", text: JSON.stringify(filteredResponse) }] } as ContentResult; } return { content: [{ type: "text", text: JSON.stringify(response) }] } as ContentResult; } catch (error: any) { return { content: [ { type: "text", text: `GitLab MCP 工具调用异常:${error?.message || String(error)}` } ], isError: true }; }
- src/tools/GitlabAcceptMRTool.ts:9-18 (schema)Zod schema defining input parameters: projectId, mergeRequestId, optional mergeOptions and fields.parameters: z.object({ projectId: z.union([z.string(), z.number()]).describe("项目 ID 或名称"), mergeRequestId: z.number().describe("合并请求 ID"), mergeOptions: z.object({ mergeCommitMessage: z.string().optional(), squash: z.boolean().optional(), shouldRemoveSourceBranch: z.boolean().optional(), }).optional().describe("合并选项"), fields: z.array(z.string()).optional().describe("需要返回的字段路径数组"), }),
- src/gitlab-tools-sdk.ts:71-80 (registration)GitlabAcceptMRTool is included in the fastmcpTools array, which is iterated over during tool registration.const fastmcpTools = [ GitlabAcceptMRTool, GitlabCreateMRCommentTool, GitlabCreateMRTool, GitlabGetUserTasksTool, GitlabRawApiTool, GitlabSearchProjectDetailsTool, GitlabSearchUserProjectsTool, GitlabUpdateMRTool, ];
- src/gitlab-tools-sdk.ts:142-147 (registration)The registration logic in registerGitLabToolsForFastMCP that adds filtered tools from fastmcpTools to the FastMCP server.fastmcpTools.forEach(tool => { const standardizedName = toolNameMapping[tool.name as keyof typeof toolNameMapping]; if (shouldRegisterTool(standardizedName as GitLabToolName, options.toolFilter)) { // GitLabTool is now fully compatible with FastMCP's base type, can be registered directly server.addTool(tool); }
- src/gitlab-tools-sdk.ts:63-63 (registration)Name mapping for the tool used in filtering during registration.[GitlabAcceptMRTool.name]: "Gitlab_Accept_MR_Tool",