gitlab

Local 2025-08-31 23:23:55 0

MCP Server for the GitLab API, enabling project management, file operations, and more.


MCP Server for the GitLab API, enabling project management, file operations, and more.

Features

  • Automatic Branch Creation: When creating/updating files or pushing changes, branches are automatically created if they don't exist
  • Comprehensive Error Handling: Clear error messages for common issues
  • Git History Preservation: Operations maintain proper Git history without force pushing
  • Batch Operations: Support for both single-file and multi-file operations

Tools

  1. create_or_update_file
  2. Create or update a single file in a project
  3. Inputs:
    • project_id (string): Project ID or URL-encoded path
    • file_path (string): Path where to create/update the file
    • content (string): Content of the file
    • commit_message (string): Commit message
    • branch (string): Branch to create/update the file in
    • previous_path (optional string): Path of the file to move/rename
  4. Returns: File content and commit details

  5. push_files

  6. Push multiple files in a single commit
  7. Inputs:
    • project_id (string): Project ID or URL-encoded path
    • branch (string): Branch to push to
    • files (array): Files to push, each with file_path and content
    • commit_message (string): Commit message
  8. Returns: Updated branch reference

  9. search_repositories

  10. Search for GitLab projects
  11. Inputs:
    • search (string): Search query
    • page (optional number): Page number for pagination
    • per_page (optional number): Results per page (default 20)
  12. Returns: Project search results

  13. create_repository

  14. Create a new GitLab project
  15. Inputs:
    • name (string): Project name
    • description (optional string): Project description
    • visibility (optional string): 'private', 'internal', or 'public'
    • initialize_with_readme (optional boolean): Initialize with README
  16. Returns: Created project details

  17. get_file_contents

  18. Get contents of a file or directory
  19. Inputs:
    • project_id (string): Project ID or URL-encoded path
    • file_path (string): Path to file/directory
    • ref (optional string): Branch/tag/commit to get contents from
  20. Returns: File/directory contents

  21. create_issue

  22. Create a new issue
  23. Inputs:
    • project_id (string): Project ID or URL-encoded path
    • title (string): Issue title
    • description (optional string): Issue description
    • assignee_ids (optional number[]): User IDs to assign
    • labels (optional string[]): Labels to add
    • milestone_id (optional number): Milestone ID
  24. Returns: Created issue details

  25. create_merge_request

  26. Create a new merge request
  27. Inputs:
    • project_id (string): Project ID or URL-encoded path
    • title (string): MR title
    • description (optional string): MR description
    • source_branch (string): Branch containing changes
    • target_branch (string): Branch to merge into
    • draft (optional boolean): Create as draft MR
    • allow_collaboration (optional boolean): Allow commits from upstream members
  28. Returns: Created merge request details

  29. fork_repository

  30. Fork a project
  31. Inputs:
    • project_id (string): Project ID or URL-encoded path
    • namespace (optional string): Namespace to fork to
  32. Returns: Forked project details

  33. create_branch

  34. Create a new branch
  35. Inputs:
    • project_id (string): Project ID or URL-encoded path
    • branch (string): Name for new branch
    • ref (optional string): Source branch/commit for new branch
  36. Returns: Created branch reference

Setup

Personal Access Token

Create a GitLab Personal Access Token with appropriate permissions: - Go to User Settings > Access Tokens in GitLab - Select the required scopes: - api for full API access - read_api for read-only access - read_repository and write_repository for repository operations - Create the token and save it securely

Usage with Claude Desktop

Add the following to your claude_desktop_config.json:

Docker

{
  "mcpServers": { 
    "gitlab": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        "GITLAB_PERSONAL_ACCESS_TOKEN",
        "-e",
        "GITLAB_API_URL",
        "mcp/gitlab"
      ],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>",
        "GITLAB_API_URL": "https://gitlab.com/api/v4" // Optional, for self-hosted instances
      }
    }
  }
}

NPX

{
  "mcpServers": {
    "gitlab": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-gitlab"
      ],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>",
        "GITLAB_API_URL": "https://gitlab.com/api/v4" // Optional, for self-hosted instances
      }
    }
  }
}

Build

Docker build:

docker build -t vonwig/gitlab:mcp -f src/gitlab/Dockerfile .

Environment Variables

  • GITLAB_PERSONAL_ACCESS_TOKEN: Your GitLab personal access token (required)
  • GITLAB_API_URL: Base URL for GitLab API (optional, defaults to https://gitlab.com/api/v4)

License

This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

[
  {
    "description": "Create or update a single file in a GitLab project",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "branch": {
          "description": "Branch to create/update the file in",
          "type": "string"
        },
        "commit_message": {
          "description": "Commit message",
          "type": "string"
        },
        "content": {
          "description": "Content of the file",
          "type": "string"
        },
        "file_path": {
          "description": "Path where to create/update the file",
          "type": "string"
        },
        "previous_path": {
          "description": "Path of the file to move/rename",
          "type": "string"
        },
        "project_id": {
          "description": "Project ID or URL-encoded path",
          "type": "string"
        }
      },
      "required": [
        "project_id",
        "file_path",
        "content",
        "commit_message",
        "branch"
      ],
      "type": "object"
    },
    "name": "create_or_update_file"
  },
  {
    "description": "Search for GitLab projects",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "page": {
          "description": "Page number for pagination (default: 1)",
          "type": "number"
        },
        "per_page": {
          "description": "Number of results per page (default: 20)",
          "type": "number"
        },
        "search": {
          "description": "Search query",
          "type": "string"
        }
      },
      "required": [
        "search"
      ],
      "type": "object"
    },
    "name": "search_repositories"
  },
  {
    "description": "Create a new GitLab project",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "description": {
          "description": "Repository description",
          "type": "string"
        },
        "initialize_with_readme": {
          "description": "Initialize with README.md",
          "type": "boolean"
        },
        "name": {
          "description": "Repository name",
          "type": "string"
        },
        "visibility": {
          "description": "Repository visibility level",
          "enum": [
            "private",
            "internal",
            "public"
          ],
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "type": "object"
    },
    "name": "create_repository"
  },
  {
    "description": "Get the contents of a file or directory from a GitLab project",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "file_path": {
          "description": "Path to the file or directory",
          "type": "string"
        },
        "project_id": {
          "description": "Project ID or URL-encoded path",
          "type": "string"
        },
        "ref": {
          "description": "Branch/tag/commit to get contents from",
          "type": "string"
        }
      },
      "required": [
        "project_id",
        "file_path"
      ],
      "type": "object"
    },
    "name": "get_file_contents"
  },
  {
    "description": "Push multiple files to a GitLab project in a single commit",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "branch": {
          "description": "Branch to push to",
          "type": "string"
        },
        "commit_message": {
          "description": "Commit message",
          "type": "string"
        },
        "files": {
          "description": "Array of files to push",
          "items": {
            "additionalProperties": false,
            "properties": {
              "content": {
                "description": "Content of the file",
                "type": "string"
              },
              "file_path": {
                "description": "Path where to create the file",
                "type": "string"
              }
            },
            "required": [
              "file_path",
              "content"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "project_id": {
          "description": "Project ID or URL-encoded path",
          "type": "string"
        }
      },
      "required": [
        "project_id",
        "branch",
        "files",
        "commit_message"
      ],
      "type": "object"
    },
    "name": "push_files"
  },
  {
    "description": "Create a new issue in a GitLab project",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "assignee_ids": {
          "description": "Array of user IDs to assign",
          "items": {
            "type": "number"
          },
          "type": "array"
        },
        "description": {
          "description": "Issue description",
          "type": "string"
        },
        "labels": {
          "description": "Array of label names",
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "milestone_id": {
          "description": "Milestone ID to assign",
          "type": "number"
        },
        "project_id": {
          "description": "Project ID or URL-encoded path",
          "type": "string"
        },
        "title": {
          "description": "Issue title",
          "type": "string"
        }
      },
      "required": [
        "project_id",
        "title"
      ],
      "type": "object"
    },
    "name": "create_issue"
  },
  {
    "description": "Create a new merge request in a GitLab project",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "allow_collaboration": {
          "description": "Allow commits from upstream members",
          "type": "boolean"
        },
        "description": {
          "description": "Merge request description",
          "type": "string"
        },
        "draft": {
          "description": "Create as draft merge request",
          "type": "boolean"
        },
        "project_id": {
          "description": "Project ID or URL-encoded path",
          "type": "string"
        },
        "source_branch": {
          "description": "Branch containing changes",
          "type": "string"
        },
        "target_branch": {
          "description": "Branch to merge into",
          "type": "string"
        },
        "title": {
          "description": "Merge request title",
          "type": "string"
        }
      },
      "required": [
        "project_id",
        "title",
        "source_branch",
        "target_branch"
      ],
      "type": "object"
    },
    "name": "create_merge_request"
  },
  {
    "description": "Fork a GitLab project to your account or specified namespace",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "namespace": {
          "description": "Namespace to fork to (full path)",
          "type": "string"
        },
        "project_id": {
          "description": "Project ID or URL-encoded path",
          "type": "string"
        }
      },
      "required": [
        "project_id"
      ],
      "type": "object"
    },
    "name": "fork_repository"
  },
  {
    "description": "Create a new branch in a GitLab project",
    "inputSchema": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "additionalProperties": false,
      "properties": {
        "branch": {
          "description": "Name for the new branch",
          "type": "string"
        },
        "project_id": {
          "description": "Project ID or URL-encoded path",
          "type": "string"
        },
        "ref": {
          "description": "Source branch/commit for new branch",
          "type": "string"
        }
      },
      "required": [
        "project_id",
        "branch"
      ],
      "type": "object"
    },
    "name": "create_branch"
  }
]