GitLab MCP server repository tools
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
To provide feedback on this feature, leave a comment on issue 630189.
These tools are part of the repository toolset.
Use them to create branches and commits, fork projects, and read branches, files, the repository tree, commits, releases, and tags.
For a list of all tools, see GitLab MCP server tools.
add_branch
Adds a branch to a GitLab project from a source ref.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No | GitLab URL of the project. Provide this, or project_id. |
project_id | string | No | ID or path of the project. Required if url is not provided. |
branch | string | Yes | Name of the new branch. |
ref | string | Yes | Branch name or commit SHA to create the new branch from. |
Example:
Create a branch named feature/x from main in project gitlab-org/gitlabfork_repository
Forks a GitLab project into a namespace.
The fork is created asynchronously. The response contains the new project attributes, including
an import_status field, such as scheduled, that shows fork progress.
The call fails due to reasons based on the following statuses:
409status when the namespace already has a fork of the project.404status when the project or namespace doesn’t exist, or you don’t have permission to fork the project.
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | ID or full path of the project. |
namespace_id | integer | No | ID of the namespace to fork the project into. |
namespace_path | string | No | Path of the namespace to fork the project into. |
name | string | No | Name to assign to the fork. |
path | string | No | Path to assign to the fork. |
description | string | No | Description to assign to the fork. |
visibility | string | No | Visibility of the fork. |
Example:
Fork gitlab-org/gitlab-test into my personal namespacelist_branches
Lists the branches of a GitLab project, optionally filtered by name.
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | Yes | ID or full path of the project. |
search | string | No | Filters branches by name. |
page | integer | No | Current page number. Default is 1. |
per_page | integer | No | Number of items per page. Default is 20. |
Example:
List branches in gitlab-org/gitlab whose names contain "release"get_repository_file
Retrieves the contents of a single file from a repository at a specific ref.
Content comes from the repository, not from your local filesystem.
The file is returned as committed at ref, so uncommitted changes in a local checkout are not included.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No | URL of the file, for example https://gitlab.example.com/my-group/my-project/-/blob/main/app/models/user.rb. Provide this, or project_id, file_path, and ref. |
project_id | string | No | ID or full path of the project. Required if url is not provided. If url is also provided, both must refer to the same project. |
file_path | string | No | Path of the file relative to the repository root. Required if url is not provided. |
ref | string | No | Branch name, tag name, or commit SHA. Use HEAD for the default branch. Required if url is not provided. |
offset | integer | No | Zero-indexed line to start reading from. Default is 0. |
limit | integer | No | Maximum number of lines to return. Default is 500. Maximum is 2000. |
line_byte_offset | integer | No | Byte position in the line at offset where the response starts. Use the value from system_instruction after a long line is cut. |
The response contains a metadata object with total_lines, returned_lines, truncated, and size_bytes.
When the response covers only part of the file, system_instruction states the offset to use in the next call.
Each response returns at most 32 KiB of file content.
When a line is longer than 32 KiB, the response ends partway through the line,
and system_instruction states the offset and line_byte_offset to use for the rest of the line.
This tool returns text only. Binary files and files stored in Git LFS return an error. Files that a project excludes from GitLab Duo context also return an error.
Example:
Show me app/models/user.rb from the main branch of my-group/my-projectlist_repository_tree
Lists the files and directories in a GitLab repository at a given path and ref.
Returns entry metadata only, never file contents. To read the contents of a file,
use get_repository_file.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No | GitLab URL of the project. Provide exactly one of url or project_id. |
project_id | string | No | ID or full path of the project. Provide exactly one of url or project_id. |
path | string | No | Path of the directory to list, relative to the repository root. Defaults to the root. |
ref | string | No | Branch name, tag name, or commit SHA. Defaults to the default branch. |
recursive | boolean | No | Lists entries of all subdirectories recursively. Default is false. |
after | string | No | Cursor for forward pagination. Use endCursor from the previous response. |
Each call returns up to 100 entries. When pageInfo.hasNextPage is true, pass
pageInfo.endCursor as after to fetch the next page.
Example:
List the files under app/services in gitlab-org/gitlab on the default branchget_commit
Retrieves a single commit’s metadata, and optionally its diff or notes.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No | URL of the GitLab commit. Required if project_id and commit_sha are not provided. |
project_id | string | No | ID or full path of the project. Required if url is not provided. |
commit_sha | string | No | Commit to look up. Accepts a full or short SHA, branch name, or tag name. Required if url is not provided. |
include | array | No | Associated facets to fetch inline. You can request diff, notes, or both in one call. Base metadata is always returned. |
diff_detail | string | No | Level of detail in the commit diff. Applies only when include contains diff. Can be either stats or full_patch. Default is stats. |
notes_after | string | No | Token to fetch the next page of notes. Applies only when include contains notes. |
notes_first | integer | No | Number of notes to return per page (maximum 100). Applies only when include contains notes. |
With diff_detail set to stats, the diff facet returns per-file and summary line counts.
With full_patch, it returns the patch text.
Example:
Show me commit abc123 in gitlab-org/gitlab with its diff statslist_commits
Lists the commits of a GitLab project, optionally filtered by ref, author, path, or date.
Returns compact commit metadata. To get the diff or notes of a single commit, use
get_commit.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No | GitLab URL of the project. Provide exactly one of url or project_id. |
project_id | string | No | ID or full path of the project. Provide exactly one of url or project_id. |
ref_name | string | No | Branch or tag to list commits from. Defaults to the default branch. |
author | string | No | Filters by commit author name or email. |
path | string | No | Returns only commits that touch this file path. |
since | string | No | Returns only commits with a committed date after this ISO 8601 date or time. |
until | string | No | Returns only commits with a committed date before this ISO 8601 date or time. |
order | string | No | Ordering strategy. Can be topo or date. Defaults to reverse chronological order. |
first_parent | boolean | No | Follows only the first parent of merge commits. |
with_stats | boolean | No | Includes per-commit line-count stats (additions, deletions, and files changed). |
after | string | No | Cursor for forward pagination. Use endCursor from the previous response. |
first | integer | No | Number of commits to return. Default is 20, maximum is 100. |
Each commit costs a Gitaly call when with_stats is true, so first defaults to 10
and must not exceed 10 when with_stats is set.
Example:
List commits to app/models in gitlab-org/gitlab since 2026-08-01 by Alexlist_releases
Lists releases in a GitLab project, most recently released first.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No | GitLab URL of the project. Required if project_id is not provided. |
project_id | string | No | ID or full path of the project. Required if url is not provided. |
page | integer | No | Page number to retrieve. Default is 1. |
per_page | integer | No | Releases to return per page. Default is 20, maximum is 100. |
state | string | No | Filter by release state: released, upcoming, or all. Default is released. |
Provide exactly one of url or project_id.
Each entry returns release metadata only: tag_name, name, released_at, upcoming, and
assets. assets holds a count of the release’s asset links and up to five of those links.
When a release has more than five, count reports the real total. Source archives are excluded,
because they are derivable from the tag.
The response also carries a metadata object with page, per_page, and has_more. Use
has_more to decide whether to request the next page.
Release notes are intentionally not returned in this response.
A release with a future released_at is scheduled rather than published, and sorts ahead of
published releases. Use state to control which you get. Scheduled releases carry upcoming set
to true.
To read the commit a release is built on, pass its tag_name to the get_commit tool. To
download an asset, use the url from assets.links.
Example:
List the most recent releases for project gitlab-org/gitlablist_tags
Lists tags in a GitLab project, most recently updated first. If search matches a tag name
exactly, GitLab lists that tag first.
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | No | GitLab URL of the project. Required if project_id is not provided. |
project_id | string | No | ID or full path of the project. Required if url is not provided. |
search | string | No | Filter tags by name. Supports ^ to anchor the start, $ to anchor the end, and * as a wildcard. |
first | integer | No | Number of tags to return. Default is 20, maximum is 100. |
after | string | No | Cursor for forward pagination. Use metadata.end_cursor from the previous response. |
Provide exactly one of url or project_id.
Each entry returns name and commit, where commit holds the tag’s tip commit sha and
title. commit is null for a tag that points at something other than a commit.
Tag messages are intentionally not returned in this response.
The response also carries a metadata object with has_next_page and end_cursor. When
has_next_page is true, pass end_cursor as after to fetch the next page.
To read the full commit a tag points at, use the get_commit tool.
Example:
List the most recent tags for the gitlab-org/gitlab projectadd_commit
Adds a commit with one or more file actions to a branch in a single call.
| Parameter | Type | Required | Description |
|---|---|---|---|
commit_message | string | Yes | Commit message. |
actions | array of objects | Yes | File actions to commit as a single batch. |
branch | string | Yes | Name of the branch to commit into. |
project_id | string | No | ID or path of the project. Required if url is not provided. |
url | string | No | GitLab URL of the project. Required if project_id is not provided. |
start_branch | string | No | Name of the branch to start the new branch from. Required when branch does not exist. |
start_sha | string | No | SHA of the commit to start a new branch from. Mutually exclusive with start_branch. |
start_project | string | No | Full path of the project to start the commit from. Must be the project itself or a project it was forked from. |
Each object in actions accepts the following fields:
| Field | Type | Required | Description |
|---|---|---|---|
action | string | Yes | The action to perform: create, update, delete, move, or chmod. |
file_path | string | Yes | Full path to the file. |
content | string | No | File content. Used by create, update, and move. Mutually exclusive with old_str and new_str. |
old_str | string | No | Existing text to replace in an update action. Requires new_str. |
new_str | string | No | Replacement text for old_str in an update action. |
previous_path | string | No | Original file path. Required for move. |
encoding | string | No | Encoding of content: text or base64. Default is text. |
last_commit_id | string | No | Last known commit ID for the file, used for optimistic concurrency. |
execute_filemode | boolean | No | Whether the file is executable. Required for chmod. |
Partial edits replace exactly one occurrence of old_str. If it occurs more than once, provide more surrounding
context. Partial edits read the complete file on the server, so they are not supported for files larger than 10 MiB.
For larger files, commit the full file content instead.
Partial edits are not supported for binary files or for files stored in LFS.
Example:
In project gitlab-org/gitlab, create README.md on branch "docs-update"
with the content "# New title" and commit message "Add README"