Add create_merge_request_pipeline MCP tool mapping to POST /projects/:id/merge_requests/:iid/pipelines

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

The current gitlab_manage_pipeline MCP tool maps exclusively to POST /projects/:id/pipelines, which creates a pipeline on a given ref but does not associate it with a merge request. When an AI agent (e.g. opencode, Claude) is asked to "create a pipeline for MR 32", it correctly resolves the ref to refs/merge-requests/32/merge but the resulting pipeline appears only in the project's pipeline list — not in the MR's Pipelines tab — because the MR context is never set.

The correct GitLab API endpoint for this use case is:

POST /projects/:id/merge_requests/:merge_request_iid/pipelines

This endpoint creates a pipeline in the context of the MR, linking it properly so it appears in the MR UI and is treated as an MR pipeline.

Problem

There is no MCP tool that maps to POST /projects/:id/merge_requests/:merge_request_iid/pipelines. As a result, any agent asked to trigger a pipeline for an MR will silently produce a detached pipeline instead, with no error or warning. This is a correctness gap — the agent succeeds but the outcome is wrong.

Example of the broken behavior

When a user asks an AI agent (opencode + GitLab MCP) "Can you create a new pipeline for MR 32?", the agent:

  1. Calls gitlab_get_merge_request to get the source ref
  2. Calls gitlab_manage_pipeline with ref: refs/merge-requests/32/merge
  3. Reports success — pipeline created with status created

But the pipeline is not linked to the MR. It appears in the project's pipeline list tagged with refs/merge-requests/32/merge, but the MR's Pipelines tab remains empty. The user has no indication anything went wrong.

Proposal

Add a dedicated create_merge_request_pipeline MCP tool with the following spec:

Tool name: create_merge_request_pipeline

Input schema:

Parameter Type Required Description
project_id string ✅ Project ID or URL-encoded path (e.g., gitlab-org/gitlab)
merge_request_iid integer ✅ The project-scoped IID of the merge request

Output schema:

Field Type Description
id integer Pipeline ID
iid integer Project-scoped pipeline IID
sha string SHA the pipeline runs on
ref string The ref (merge request ref)
status string Pipeline status (e.g., created, pending)
web_url string URL to the pipeline on GitLab

GitLab API mapping: POST /projects/:id/merge_requests/:merge_request_iid/pipelines

Additional improvement

The description of gitlab_manage_pipeline should be updated to explicitly warn that it does not create MR-linked pipelines, and should recommend create_merge_request_pipeline when the user's intent is to trigger a pipeline for a merge request.

Acceptance Criteria

  • Tool is registered in the MCP server tool registry with name create_merge_request_pipeline, a clear description, and a JSON Schema input definition.
  • Tool calls POST /projects/:id/merge_requests/:merge_request_iid/pipelines and returns a normalized pipeline object.
  • The created pipeline appears in the MR's Pipelines tab (verified via the GitLab UI or API).
  • Returns a structured 404 error when the project or MR does not exist or is not visible.
  • Returns a structured 403 error when the user lacks permission to create pipelines.
  • Returns a structured 400 error when a pipeline cannot be created (e.g., MR is closed or merged).
  • Unit tests cover: successful creation, MR not found (404), project not found (404), permission denied (403), and MR not in a pipeable state (400).
  • Integration test confirms the tool is callable end-to-end via the MCP protocol.
  • Tool description and parameter schema are clear enough for an LLM to select this tool (over gitlab_manage_pipeline) when the user's intent is to run a pipeline for an MR.
  • gitlab_manage_pipeline description is updated to note it does not create MR-linked pipelines and to recommend this tool instead.

References

Edited by 🤖 GitLab Bot 🤖