# Create Merge Request Comment — GitLab

> Post a comment on a merge request. It works in three modes, chosen by which props you set: leave File Path and Discussion ID blank for a plain comment on the merge request as a whole; set File Path plus a line number to open an inline…

- Key: `gitlab-create-merge-request-comment`
- Type: Action (Write)
- Version: 0.0.1
- App: GitLab (`gitlab`) — https://pipedream.com/apps/gitlab.md
- This page (HTML): https://pipedream.com/apps/gitlab/actions/create-merge-request-comment
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/gitlab/actions/create-merge-request-comment/create-merge-request-comment.mjs

## Description

Post a comment on a merge request. It works in three modes, chosen by which props you set: leave **File Path** and **Discussion ID** blank for a plain comment on the merge request as a whole; set **File Path** plus a line number to open an inline thread anchored to that line of the diff; or set **Discussion ID** to reply inside an existing thread. Use **Get Merge Request Diffs** first to get valid file paths and line numbers, and **List Merge Request Discussions** to get a **Discussion ID** to reply to. Line numbers follow GitLab's diff rules: for a line the merge request **adds** or leaves unchanged, pass **New Line**; for a line it **removes**, pass **Old Line**; for an unchanged context line, pass both. Getting that wrong is the usual cause of a rejected inline comment. To post several review comments at once, and optionally approve in the same step, use **Create Merge Request Review** instead. [See the documentation](https://docs.gitlab.com/api/discussions/#create-new-merge-request-thread)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `projectId` | `string` | Yes | The project, given either as its path — group/project or group/subgroup/project, e.g. backend/payments — or as its numeric project ID. The path is what appears in the project URL and is usually what a user will name, so prefer it. A pasted GitLab URL also works. Use List Projects to find the path if you only know part of the name. |
| `mergeRequestIid` | `integer` | Yes | The merge request's internal ID — the !N shown in the GitLab UI and the number at the end of the merge request URL. This is not the id field, which is a much larger instance-wide number; passing id here returns a 404. Use List Merge Requests or Search Merge Requests to resolve the IID from a title, branch or author. |
| `body` | `string` | Yes | The comment text. Supports GitLab-flavored Markdown, so code blocks, lists and suggestion blocks all work. |
| `discussionId` | `string` | No | Set this to reply inside an existing thread instead of starting a new one. Get it from List Merge Request Discussions. Cannot be combined with File Path. |
| `filePath` | `string` | No | Set this to anchor the comment to a line of the diff — the file's path after the change, exactly as new_path reports it in Get Merge Request Diffs (e.g. src/api/client.py). Leave blank for a comment on the merge request as a whole. |
| `oldFilePath` | `string` | No | The file's path before the change, as old_path reports it in Get Merge Request Diffs. Only needed when the merge request renames the file — GitLab anchors a comment on a renamed file with both paths. Defaults to File Path. |
| `newLine` | `integer` | No | Line number in the new version of the file. Use this for a line the merge request adds, and together with Old Line for an unchanged context line. Required with File Path unless Old Line is given. |
| `oldLine` | `integer` | No | Line number in the old version of the file. Use this for a line the merge request removes, and together with New Line for an unchanged context line. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "gitlab",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "gitlab-create-merge-request-comment",
  arguments: {
    projectId: "Project",
    mergeRequestIid: 10,
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "gitlab-create-merge-request-comment",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    gitlab: { authProvisionId: "apn_xxxxxxx" },
    projectId: "Project",
    mergeRequestIid: 10,
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "gitlab-create-merge-request-comment",
    "configured_props": {
      "gitlab": { "authProvisionId": "apn_xxxxxxx" },
      "projectId": "Project",
      "mergeRequestIid": 10
    }
  }'
```

---

- App: https://pipedream.com/apps/gitlab.md · All apps: https://pipedream.com/apps
