Skip to main content
Glama

gitlab_get_merge_request_details

Retrieve comprehensive details and file changes from a GitLab merge request to review code modifications and track development progress.

Instructions

Fetches detailed information about a GitLab Merge Request, including file diffs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mrUrlYesThe URL of the GitLab Merge Request.

Implementation Reference

  • src/index.ts:69-82 (registration)
    Tool registration and input schema definition for gitlab_get_merge_request_details
    {
      name: 'gitlab_get_merge_request_details',
      description:
        'Fetches detailed information about a GitLab Merge Request, including file diffs.',
      inputSchema: {
        type: 'object',
        properties: {
          mrUrl: {
            type: 'string',
            description: 'The URL of the GitLab Merge Request.',
          },
        },
        required: ['mrUrl'],
      },
  • MCP server handler that dispatches the tool call to GitLabService.getMergeRequestDetailsFromUrl
    case 'gitlab_get_merge_request_details': {
      if (!gitlabService) {
        throw new Error('GitLab service is not initialized.');
      }
      const { mrUrl } = args as { mrUrl: string };
      const result =
        await gitlabService.getMergeRequestDetailsFromUrl(mrUrl);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Core handler function that fetches MR details from GitLab API, processes changes, parses diffs, and returns structured GitLabMRDetails
    async getMergeRequestDetails(
      projectPath: string,
      mrIid: number,
    ): Promise<GitLabMRDetails> {
      const encodedProjectPath = encodeURIComponent(projectPath);
      const baseUrl = `projects/${encodedProjectPath}/merge_requests/${mrIid}`;
    
      const mrDetails = await this.callGitLabApi<any>(baseUrl);
      const mrChanges = await this.callGitLabApi<any>(
        `projects/${encodedProjectPath}/merge_requests/${mrIid}/changes`,
      );
    
      // Map file diffs
      const fileDiffs = mrChanges.changes.map((change: any) => ({
        old_path: change.old_path,
        new_path: change.new_path,
        new_file: change.new_file,
        deleted_file: change.deleted_file,
        renamed_file: change.renamed_file,
        diff: change.diff,
      }));
    
      const parsedDiffs = fileDiffs.map((diff: any) => ({
        filePath: diff.new_path,
        oldPath: diff.old_path,
        isNew: diff.new_file,
        isDeleted: diff.deleted_file,
        isRenamed: diff.renamed_file,
        hunks: this.parseDiff(diff.diff),
      }));
    
      return {
        projectPath: mrDetails.path_with_namespace,
        mrIid: mrDetails.iid.toString(),
        projectId: mrDetails.project_id,
        title: mrDetails.title,
        authorName: mrDetails.author.name,
        webUrl: mrDetails.web_url,
        sourceBranch: mrDetails.source_branch,
        targetBranch: mrDetails.target_branch,
        base_sha: mrDetails.diff_refs.base_sha,
        start_sha: mrDetails.diff_refs.start_sha,
        head_sha: mrDetails.diff_refs.head_sha,
        fileDiffs: fileDiffs,
        diffForPrompt: fileDiffs.map((diff: any) => diff.diff).join('\n'),
        parsedDiffs: parsedDiffs,
        fileContents: new Map(), // fileContents will be populated by a separate tool
        discussions: [], // Discussions will be fetched by a separate tool
        existingFeedback: [], // Existing feedback will be derived from discussions
      };
    }
  • Convenience handler that parses MR URL and delegates to getMergeRequestDetails (directly called by MCP handler)
    async getMergeRequestDetailsFromUrl(mrUrl: string): Promise<GitLabMRDetails> {
      const { projectPath, mrIid } = this.parseMrUrl(mrUrl, this.config.url);
      return this.getMergeRequestDetails(projectPath, mrIid);
    }
  • Helper function to parse GitLab MR URL into projectPath and mrIid
    private parseMrUrl(
      mrUrl: string,
      gitlabBaseUrl: string,
    ): { projectPath: string; mrIid: number } {
      try {
        const url = new URL(mrUrl);
        const baseUrl = new URL(gitlabBaseUrl);
    
        // Ensure the URL is from the same GitLab instance
        if (url.origin !== baseUrl.origin) {
          throw new Error(
            `MR URL is not from the configured GitLab instance: ${gitlabBaseUrl}`,
          );
        }
    
        // Parse the path: /{namespace}/{project}/-/merge_requests/{iid}
        const pathMatch = url.pathname.match(/^\/(.+)\/-\/merge_requests\/(\d+)/);
        if (!pathMatch) {
          throw new Error(`Invalid GitLab MR URL format: ${mrUrl}`);
        }
    
        const projectPath = pathMatch[1];
        const mrIid = parseInt(pathMatch[2], 10);
    
        return { projectPath, mrIid };
      } catch (error) {
        throw new Error(
          `Failed to parse GitLab MR URL: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }
  • Type definition for the output schema (GitLabMRDetails interface)
    export interface GitLabMRDetails {
      projectPath: string;
      mrIid: string;
      projectId: number;
      title: string;
      authorName: string;
      webUrl: string;
      sourceBranch: string;
      targetBranch: string;
      base_sha: string;
      start_sha: string;
      head_sha: string;
      fileDiffs: FileDiff[];
      diffForPrompt: string;
      parsedDiffs: ParsedFileDiff[];
      fileContents: Map<string, { oldContent?: string[]; newContent?: string[] }>;
      discussions: GitLabDiscussion[];
      existingFeedback: ReviewFeedback[];
      approvals?: {
        approved_by: Array<{ user: { name: string; username: string } }>;
        approvals_left: number;
        approvals_required: number;
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It mentions 'including file diffs,' which adds some context about returned data, but lacks critical details like authentication requirements, rate limits, error handling, or whether it's a read-only operation. This is inadequate for a tool with potential complexity.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('fetches detailed information') and adds a useful detail ('including file diffs') without unnecessary words. Every part earns its place, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is minimally complete for a read operation but lacks depth. It hints at returned data ('file diffs') but omits other behavioral aspects like permissions or response format. For a tool fetching detailed MR info, more context would be beneficial to fully guide an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting the single parameter 'mrUrl.' The description does not add any semantic details beyond what the schema provides, such as URL format examples or validation rules, so it meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('fetches') and resource ('detailed information about a GitLab Merge Request'), making the purpose evident. It distinguishes from siblings like 'gitlab_list_merge_requests' by specifying it retrieves details for a single MR, but does not explicitly contrast with other detail-fetching tools like 'gitlab_get_issue_details'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It does not mention prerequisites (e.g., needing a specific MR URL) or compare with similar tools like 'gitlab_get_merge_request_pipelines' for pipeline-related details, leaving usage context unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/HainanZhao/mcp-gitlab-jira'

If you have feedback or need assistance with the MCP directory API, please join our Discord server