Skip to content

get_merge_request API response exceeds token limit for large MRs

Issue Description

When using the get_merge_request MCP function on merge requests with extensive content (many files, large diffs, or numerous discussions), the response exceeds the maximum allowed token limit of 25,000 tokens.

Error Details

Error: MCP tool "get_merge_request" response (25853 tokens) exceeds maximum allowed tokens (25000). 
Please use pagination, filtering, or limit parameters to reduce the response size.

Reproduction Steps

  1. Use the get_merge_request function on a merge request with:
    • Multiple file changes
    • Large diffs
    • Extensive discussions/comments
  2. Example call that triggers the error:
    mcp__GitLab__get_merge_request(project_id: "71424686", merge_request_iid: 7)

Expected Behavior

The function should either:

  1. Automatically paginate or truncate the response to stay within token limits
  2. Provide parameters to control the response size (e.g., exclude diffs, limit discussions)
  3. Split the response into multiple parts that can be retrieved separately

Suggested Solutions

  1. Add optional parameters to control response content:

    get_merge_request(
      project_id: string,
      merge_request_iid: number,
      options?: {
        include_diffs?: boolean,      // default: true
        include_discussions?: boolean, // default: true
        diff_limit?: number,          // limit number of diff entries
        discussion_limit?: number     // limit number of discussions
      }
    )
  2. Implement automatic response truncation:

    • Detect when response would exceed token limit
    • Prioritize essential information (MR metadata, status)
    • Indicate that content was truncated
  3. Provide separate endpoints for large content:

    • get_merge_request_metadata - Just the MR info without diffs/discussions
    • Keep existing list_merge_request_diffs for diff content
    • Keep existing discussion_list for discussions

Environment

  • MCP Tool: gitlab-mcp
  • Use case: Code review on large merge requests
  • Token limit: 25,000

Impact

This limitation prevents proper code review and MR analysis for substantial changes, which are common in real-world development scenarios.

Related

This issue particularly affects development tools and AI assistants that need to analyze complete merge request content for code reviews.