get_merge_request_diffs
Retrieve code changes from GitLab merge requests to review modifications between branches. Specify project ID with either merge request ID or source branch name.
Instructions
Get the changes/diffs of a merge request. Either merge_request_iid or source_branch must be provided.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID or path | |
| merge_request_iid | No | Merge request internal ID | |
| source_branch | No | Source branch name (alternative to merge_request_iid) | |
| view | No | Diff view type |
Implementation Reference
- src/handlers/merge-requests.ts:135-162 (handler)The core handler function implementing get_merge_request_diffs tool. Resolves merge request IID from source_branch if not provided, constructs the GitLab API URL for MR changes/diffs, fetches the data, and returns it as JSON text content.async getMergeRequestDiffs(args: GetMergeRequestDiffsParams) { const mergeRequestIid = await this.resolveMergeRequestIid( args.project_id, args.merge_request_iid, args.source_branch ); const params = new URLSearchParams(); if (args.view) params.append("view", args.view); const queryString = params.toString(); const url = `/projects/${encodeURIComponent( args.project_id )}/merge_requests/${mergeRequestIid}/changes${ queryString ? `?${queryString}` : "" }`; const data = await this.client.get(url); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; }
- src/tools/merge-requests.ts:85-111 (schema)MCP tool definition including name, description, and inputSchema for the get_merge_request_diffs tool.{ name: 'get_merge_request_diffs', description: 'Get the changes/diffs of a merge request. Either merge_request_iid or source_branch must be provided.', inputSchema: { type: 'object', properties: { project_id: { type: 'string', description: 'Project ID or path', }, merge_request_iid: { type: 'number', description: 'Merge request internal ID', }, source_branch: { type: 'string', description: 'Source branch name (alternative to merge_request_iid)', }, view: { type: 'string', enum: ['inline', 'parallel'], description: 'Diff view type', }, }, required: ['project_id'], }, },
- src/server.ts:193-196 (registration)Server dispatch/registration for the tool call, routing to the mergeRequestHandlers.getMergeRequestDiffs method.case "get_merge_request_diffs": return await this.mergeRequestHandlers.getMergeRequestDiffs( args as unknown as GetMergeRequestDiffsParams );
- src/types.ts:260-265 (schema)TypeScript interface defining the parameters for the getMergeRequestDiffs handler.export interface GetMergeRequestDiffsParams { project_id: string; merge_request_iid?: number; source_branch?: string; view?: 'inline' | 'parallel'; }