Skip to main content
Glama
ttpears

GitLab MCP Server

by ttpears

Get Merge Request Context

get_merge_request_context
Read-onlyIdempotent

Retrieve complete merge request context including description, notes, commits, pipeline status, reviewers, and linked issues in one call to simplify investigation.

Instructions

Bundle MR body, all notes (paginated up to maxNotes, filtered to non-system by default), commits, pipeline summary, reviewers with approval state, and issues this MR will close into a single call. Use this instead of fanning out across get_merge_requests + get_notes + get_merge_request_commits + get_merge_request_pipelines when investigating an MR.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesFull project path (e.g. "my-group/my-project")
iidYesMerge request IID
maxNotesNoCap on notes fetched. Default 100.
maxCommitsNoCap on commits fetched. Default 50.
includeSystemNotesNoInclude system-generated notes. Default false.
userCredentialsNoYour GitLab credentials (optional — falls back to the configured env token if not provided)

Implementation Reference

  • Main handler function for the 'get_merge_request_context' tool. It takes projectPath, iid, maxNotes, maxCommits, and includeSystemNotes as input, then fetches MR detail (via client.getMergeRequestDetail), notes (via client.getNotes), commits (via client.getMergeRequestCommits), pipelines (via client.getMergeRequestPipelines), reviewers (via client.getMergeRequestReviewers), and closes issues (via client.getMergeRequestClosesIssues) in parallel using Promise.all. It assembles all these into a single bundled response with the merge request body, notes, commits, pipelines, reviewers/approval state, and closing issues.
      handler: async (input, client, userConfig) => {
        const credentials = input.userCredentials ? validateUserConfig(input.userCredentials) : userConfig;
        const projectPath = input.projectPath.trim();
        const iid = input.iid.trim();
    
        const [detail, notesResult, commitsResult, pipelinesResult, reviewers, closesIssues] = await Promise.all([
          client.getMergeRequestDetail(projectPath, iid, credentials),
          client.getNotes(projectPath, 'merge_request', iid, input.maxNotes, undefined, true, credentials),
          client.getMergeRequestCommits(projectPath, iid, input.maxCommits, undefined, true, credentials),
          client.getMergeRequestPipelines(projectPath, iid, 5, undefined, false, credentials).catch(() => null),
          client.getMergeRequestReviewers(projectPath, iid, credentials).catch(() => null),
          client.getMergeRequestClosesIssues(projectPath, iid, credentials).catch(() => []),
        ]);
    
        const mr = detail?.project?.mergeRequest;
        if (!mr) {
          throw new Error(`Merge request ${projectPath}!${iid} not found.`);
        }
    
        const allNotes: any[] = Array.isArray(notesResult?.nodes) ? notesResult.nodes : [];
        const notes = input.includeSystemNotes ? allNotes : allNotes.filter((n) => !n.system);
    
        return {
          project: { fullPath: projectPath },
          mergeRequest: mr,
          notes: {
            count: notes.length,
            truncated: !!notesResult?.hasMore,
            nodes: notes,
          },
          commits: {
            count: Array.isArray(commitsResult?.nodes) ? commitsResult.nodes.length : 0,
            truncated: !!commitsResult?.hasMore,
            nodes: commitsResult?.nodes ?? [],
          },
          pipelines: pipelinesResult ?? null,
          reviewers: reviewers ?? null,
          closesIssues: closesIssues.map((i: any) => ({
            iid: String(i.iid),
            title: i.title,
            state: i.state,
            webUrl: i.web_url ?? null,
            projectId: i.project_id ?? null,
          })),
        };
      },
    };
  • Input schema (Zod) for the 'get_merge_request_context' tool. Defines projectPath (required), iid (required), maxNotes (default 100, max 500), maxCommits (default 50, max 500), and includeSystemNotes (default false). Uses withUserAuth to optionally accept user credentials.
    inputSchema: withUserAuth(z.object({
      projectPath: z.string().min(1).describe('Full project path (e.g. "my-group/my-project")'),
      iid: z.string().min(1).describe('Merge request IID'),
      maxNotes: z.number().int().min(1).max(500).default(100).describe('Cap on notes fetched. Default 100.'),
      maxCommits: z.number().int().min(1).max(500).default(50).describe('Cap on commits fetched. Default 50.'),
      includeSystemNotes: z.boolean().default(false).describe('Include system-generated notes. Default false.'),
    })),
  • src/tools.ts:2284-2284 (registration)
    The getMergeRequestContextTool is included in the readOnlyTools array (line 2284), which is spread into the exported tools array (line 2335-2346). It is also registered via the ListToolsRequestSchema and CallToolRequestSchema handlers in src/index.ts (lines 88-146) by matching tool.name.
    getMergeRequestContextTool,
  • Client method getMergeRequestDetail() - fetches the detailed MR info (title, description, state, branches, author, assignees, labels, milestone, diff stats) via GraphQL query, used by the handler.
    async getMergeRequestDetail(
      projectPath: string,
      iid: string,
      userConfig?: UserConfig,
    ): Promise<any> {
      const query = gql`
        query getMergeRequestDetail($projectPath: ID!, $iid: String!) {
          project(fullPath: $projectPath) {
            fullPath
            mergeRequest(iid: $iid) {
              id
              iid
              title
              description
              state
              draft
              createdAt
              updatedAt
              mergedAt
              closedAt
              webUrl
              sourceBranch
              targetBranch
              author { username name }
              assignees { nodes { username name } }
              mergeUser { username name }
              labels { nodes { title color } }
              milestone { title state dueDate webPath }
              userNotesCount
              upvotes
              downvotes
              diffStatsSummary {
                additions
                deletions
                fileCount
              }
            }
          }
        }
      `;
      return this.query(query, { projectPath, iid }, userConfig);
    }
  • Client method getMergeRequestClosesIssues() - fetches issues that a merge request will close via the GitLab REST API (GET /projects/:id/merge_requests/:iid/closes_issues). Used by the handler.
    async getMergeRequestClosesIssues(
      projectPath: string,
      iid: string,
      userConfig?: UserConfig,
    ): Promise<any[]> {
      const encodedPath = encodeURIComponent(projectPath);
      return this.restRequest('GET', `/projects/${encodedPath}/merge_requests/${iid}/closes_issues`, {
        userConfig,
      });
    }
Behavior4/5

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

Annotations already convey readOnly, non-destructive, idempotent behavior. The description adds valuable details: pagination limits (maxNotes, maxCommits), default filtering of system notes, and inclusion of specific data types (pipeline summary, approval state, closing issues). This goes beyond annotations.

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?

Two concise sentences: first states the action and bundled data, second gives usage guidance. No redundancy, every word adds value.

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

Completeness5/5

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

Despite no output schema, the description enumerates exactly what is returned: MR body, notes (paginated/filtered), commits, pipeline summary, reviewers with approval states, closing issues. This is comprehensive for an agent to understand the return value.

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?

All parameters have schema descriptions with 100% coverage. The description does not add new information about individual parameters but reinforces defaults (e.g., 'filtered to non-system by default' for includeSystemNotes). Baseline 3 applies.

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

Purpose5/5

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

The description clearly states the tool bundles MR body, notes, commits, pipeline summary, reviewers, and closing issues. It uses specific verbs like 'Bundle' and explicitly distinguishes from sibling tools by naming alternatives.

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

Usage Guidelines5/5

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

The description explicitly recommends using this tool instead of fanning out across four other tools when investigating an MR. It provides clear when-to-use guidance and names specific alternatives.

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

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