Gitlab MCP
A MCP (Model Context Protocol) server for interacting with GitLab API.
Installation
npx gitlab-mcpAsk AI about Gitlab MCP
Powered by Claude Β· Grounded in docs
I know everything about Gitlab MCP. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
GitLab MCP Server
A MCP (Model Context Protocol) server for interacting with GitLab API. This server provides a set of tools that allow AI clients to perform operations on GitLab repositories, issues, merge requests, and more. All operations support both synchronous and asynchronous execution patterns.
Installation
Using uv (Recommended)
# Clone the repository
git clone https://github.com/Adit-999/gitlab-mcp.git
cd gitlab-mcp
# Install dependencies using uv
uv sync
Using pip
# Clone the repository
git clone https://github.com/Adit-999/gitlab-mcp.git
cd gitlab-mcp
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -e .
Configuration
The GitLab MCP server requires two environment variables to function properly:
GITLAB_PERSONAL_ACCESS_TOKEN- For authentication with GitLab APIGITLAB_API_URL- The base URL for the GitLab API
Option 1: Environment Variables
Create a .env file in the project root directory with these variables:
GITLAB_PERSONAL_ACCESS_TOKEN=your_personal_access_token
GITLAB_API_URL=https://gitlab.com
Option 2: MCP Configuration
You can also configure the MCP server in your MCP JSON configuration file:
{
"mcpServers": {
"gitlab-mcp": {
"command": "uv",
"args": ["run", "--with", "mcp[cli]", "mcp", "run", "/path/to/gitlab-mcp/server.py"],
"env": {
"GITLAB_PERSONAL_ACCESS_TOKEN": "your_personal_access_token",
"GITLAB_API_URL": "https://gitlab.com"
}
}
}
}
Configure with uv for Claude Desktop
uv run mcp install server.py
Project Structure
The project follows a modular, domain-driven architecture:
gitlab-mcp/
βββ src/ # Source code
β βββ api/ # API interaction layer
β β βββ rest_client.py # GitLab REST API client
β β βββ exceptions.py # API exception definitions
β βββ schemas/ # Data models and validation
β β βββ base.py # Base schema classes
β β βββ repositories.py # Repository data models
β β βββ branches.py # Branch data models
β β βββ issues.py # Issue data models
β β βββ merge_requests.py # Merge request data models
β β βββ groups.py # Group data models
β β βββ search.py # search data models
β βββ services/ # Business logic layer
β β βββ repositories.py # Repository operations
β β βββ branches.py # Branch operations
β β βββ issues.py # Issue operations
β β βββ merge_requests.py # Merge request operations
β β βββ groups.py # Group operations
β β βββ search.py # search operations
β βββ tools/ # MCP tool implementations
β βββ repositories.py # Repository tools
β βββ branches.py # Branch tools
β βββ issues.py # Issue tools
β βββ merge_requests.py # Merge request tools
β βββ groups.py # Group tools
β βββ search.py # search tools
βββ server.py # Main MCP server entry point
This architecture provides several benefits:
- Separation of concerns: Each module has a clear responsibility
- Type safety: Pydantic schemas ensure data validation
- Maintainability: Domain-driven organization makes code easier to navigate
- Extensibility: New features can be added by following the established patterns
- Async support: All operations are available in both synchronous and asynchronous versions
Available Tools
The server provides the following tools for interacting with GitLab:
Repository Management
create_repository: Create a new GitLab repositorylist_repository_tree: List the contents of a repository tree
Branch Operations
create_branch: Create a new branch in a GitLab repositorylist_branches: List branches in a GitLab repositoryget_branch: Get details for a specific GitLab branchdelete_branch: Delete a branch from a GitLab repositorydelete_merged_branches: Delete all merged branches from a GitLab repositoryprotect_branch: Protect a branch in a GitLab repositoryunprotect_branch: Remove protection from a branch in a GitLab repositoryget_default_branch_ref: Get the default branch reference for a GitLab repository
File Operations
create_file: Create a new file in a GitLab repositoryget_file_contents: Retrieve the contents of a file from a GitLab repositoryupdate_file: Update an existing file in a GitLab repositorydelete_file: Delete a file from a GitLab repository
Issue Management
create_issue: Create a new issue in a GitLab repositorylist_all_issues: List all issues the authenticated user has access toget_issue: Get details for a specific GitLab issueclose_issue: Close a GitLab issuedelete_issue: Delete an issue from a GitLab repositorymove_issue: Move an issue to a different projectcomment_on_issue: Add a comment to a GitLab issuelist_issue_comments: List comments for a GitLab issue
Merge Request Operations
create_merge_request: Create a new merge request in a GitLab repositorylist_merge_requests: List merge requests for a GitLab projectget_merge_request: Get details for a specific GitLab merge requestmerge_merge_request: Merge a GitLab merge requestupdate_merge_request: Update an existing merge request in a GitLab repository.delete_merge_request: Delete a merge request from a GitLab repository.merge_request_changes: Get the changes for a specific merge request.create_merge_request_comment: Add a comment to a GitLab merge request.
Job Operations
get_job_logs: Get logs from a GitLab job
Group Operations
list_groups: List GitLab groupsget_group: Get a specific GitLab groupget_group_by_project_namespace: Get a GitLab group based on a project namespace
Search Tools
search_globally: Search across all GitLab resources (currently supports projects and files/blobs).search_project: Search within a specific project (currently supports projects and files/blobs).search_group: Search within a specific group (currently supports projects and files/blobs).
Troubleshooting
Common Issues
- GitLab API Authentication Errors: Ensure your
GITLAB_PERSONAL_ACCESS_TOKENhas the necessary permissions and is correctly set in your environment variables. - NoneType errors: Some functions may encounter issues when handling empty results. If you encounter these errors, please report them with detailed steps to reproduce.
License
This project is licensed under the MIT License - see the LICENSE file for details.
