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.

ParameterTypeRequiredDescription
urlstringNoGitLab URL of the project. Provide this, or project_id.
project_idstringNoID or path of the project. Required if url is not provided.
branchstringYesName of the new branch.
refstringYesBranch name or commit SHA to create the new branch from.

Example:

Create a branch named feature/x from main in project gitlab-org/gitlab

fork_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:

  • 409 status when the namespace already has a fork of the project.
  • 404 status when the project or namespace doesn’t exist, or you don’t have permission to fork the project.
ParameterTypeRequiredDescription
idstringYesID or full path of the project.
namespace_idintegerNoID of the namespace to fork the project into.
namespace_pathstringNoPath of the namespace to fork the project into.
namestringNoName to assign to the fork.
pathstringNoPath to assign to the fork.
descriptionstringNoDescription to assign to the fork.
visibilitystringNoVisibility of the fork.

Example:

Fork gitlab-org/gitlab-test into my personal namespace

list_branches

Lists the branches of a GitLab project, optionally filtered by name.

ParameterTypeRequiredDescription
idstringYesID or full path of the project.
searchstringNoFilters branches by name.
pageintegerNoCurrent page number. Default is 1.
per_pageintegerNoNumber 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.

ParameterTypeRequiredDescription
urlstringNoURL 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_idstringNoID 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_pathstringNoPath of the file relative to the repository root. Required if url is not provided.
refstringNoBranch name, tag name, or commit SHA. Use HEAD for the default branch. Required if url is not provided.
offsetintegerNoZero-indexed line to start reading from. Default is 0.
limitintegerNoMaximum number of lines to return. Default is 500. Maximum is 2000.
line_byte_offsetintegerNoByte 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-project

list_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.

ParameterTypeRequiredDescription
urlstringNoGitLab URL of the project. Provide exactly one of url or project_id.
project_idstringNoID or full path of the project. Provide exactly one of url or project_id.
pathstringNoPath of the directory to list, relative to the repository root. Defaults to the root.
refstringNoBranch name, tag name, or commit SHA. Defaults to the default branch.
recursivebooleanNoLists entries of all subdirectories recursively. Default is false.
afterstringNoCursor 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 branch

get_commit

Retrieves a single commit’s metadata, and optionally its diff or notes.

ParameterTypeRequiredDescription
urlstringNoURL of the GitLab commit. Required if project_id and commit_sha are not provided.
project_idstringNoID or full path of the project. Required if url is not provided.
commit_shastringNoCommit to look up. Accepts a full or short SHA, branch name, or tag name. Required if url is not provided.
includearrayNoAssociated facets to fetch inline. You can request diff, notes, or both in one call. Base metadata is always returned.
diff_detailstringNoLevel of detail in the commit diff. Applies only when include contains diff. Can be either stats or full_patch. Default is stats.
notes_afterstringNoToken to fetch the next page of notes. Applies only when include contains notes.
notes_firstintegerNoNumber 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 stats

list_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.

ParameterTypeRequiredDescription
urlstringNoGitLab URL of the project. Provide exactly one of url or project_id.
project_idstringNoID or full path of the project. Provide exactly one of url or project_id.
ref_namestringNoBranch or tag to list commits from. Defaults to the default branch.
authorstringNoFilters by commit author name or email.
pathstringNoReturns only commits that touch this file path.
sincestringNoReturns only commits with a committed date after this ISO 8601 date or time.
untilstringNoReturns only commits with a committed date before this ISO 8601 date or time.
orderstringNoOrdering strategy. Can be topo or date. Defaults to reverse chronological order.
first_parentbooleanNoFollows only the first parent of merge commits.
with_statsbooleanNoIncludes per-commit line-count stats (additions, deletions, and files changed).
afterstringNoCursor for forward pagination. Use endCursor from the previous response.
firstintegerNoNumber 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 Alex

list_releases

Lists releases in a GitLab project, most recently released first.

ParameterTypeRequiredDescription
urlstringNoGitLab URL of the project. Required if project_id is not provided.
project_idstringNoID or full path of the project. Required if url is not provided.
pageintegerNoPage number to retrieve. Default is 1.
per_pageintegerNoReleases to return per page. Default is 20, maximum is 100.
statestringNoFilter 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/gitlab

list_tags

Lists tags in a GitLab project, most recently updated first. If search matches a tag name exactly, GitLab lists that tag first.

ParameterTypeRequiredDescription
urlstringNoGitLab URL of the project. Required if project_id is not provided.
project_idstringNoID or full path of the project. Required if url is not provided.
searchstringNoFilter tags by name. Supports ^ to anchor the start, $ to anchor the end, and * as a wildcard.
firstintegerNoNumber of tags to return. Default is 20, maximum is 100.
afterstringNoCursor 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 project

add_commit

Adds a commit with one or more file actions to a branch in a single call.

ParameterTypeRequiredDescription
commit_messagestringYesCommit message.
actionsarray of objectsYesFile actions to commit as a single batch.
branchstringYesName of the branch to commit into.
project_idstringNoID or path of the project. Required if url is not provided.
urlstringNoGitLab URL of the project. Required if project_id is not provided.
start_branchstringNoName of the branch to start the new branch from. Required when branch does not exist.
start_shastringNoSHA of the commit to start a new branch from. Mutually exclusive with start_branch.
start_projectstringNoFull 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:

FieldTypeRequiredDescription
actionstringYesThe action to perform: create, update, delete, move, or chmod.
file_pathstringYesFull path to the file.
contentstringNoFile content. Used by create, update, and move. Mutually exclusive with old_str and new_str.
old_strstringNoExisting text to replace in an update action. Requires new_str.
new_strstringNoReplacement text for old_str in an update action.
previous_pathstringNoOriginal file path. Required for move.
encodingstringNoEncoding of content: text or base64. Default is text.
last_commit_idstringNoLast known commit ID for the file, used for optimistic concurrency.
execute_filemodebooleanNoWhether 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"