home / mcp / gitlab mcp server
Gitlab MCP
Configuration
View docs{
"mcpServers": {
"anupsahu-gitlab-mcp": {
"command": "npx",
"args": [
"-y",
"@anupsahu/gitlab-mcp"
],
"env": {
"USE_OAUTH": "true",
"GITLAB_API_URL": "https://gitlab.com/api/v4",
"GITLAB_PROJECT_ID": "12345",
"GITLAB_READ_ONLY_MODE": "false",
"OAUTH_REDIRECT_PORT_RANGE": "7171-7199",
"GITLAB_ALLOWED_PROJECT_IDS": "123,456",
"GITLAB_PERSONAL_ACCESS_TOKEN": "YOUR_TOKEN",
"OAUTH_REDIRECT_PORT_PREFERRED": "7171"
}
}
}
}You can run a dedicated MCP server that exposes GitLab API interactions with secure OAuth 2.0 PKCE authentication, token persistence, and automatic refresh. This lets you perform repository operations, issue tracking, merge requests, and more through a stable MCP interface while keeping tokens secure and sessions durable across restarts.
You run the GitLab MCP Server locally or in your environment and connect to it from an MCP client. Start by configuring a server entry that uses the MCP command to run the GitLab MCP package. Choose OAuth for secure access or a personal access token for simpler setups.
Prerequisites: you need Node.js and npm installed on your machine.
Install the MCP package globally so you can run it from any location.
npm install -g @anupsahu/gitlab-mcpCreate a configuration that runs the MCP server using the package runner. You can use OAuth authentication or a personal access token. The following configurations use the standard npm/npx flow shown in examples.
{
"mcpServers": {
"gitlab": {
"command": "npx",
"args": ["-y", "@anupsahu/gitlab-mcp"],
"env": {
"USE_OAUTH": "true",
"GITLAB_API_URL": "https://gitlab.com/api/v4"
}
}
}
}{
"mcpServers": {
"gitlab": {
"command": "npx",
"args": ["-y", "@anupsahu/gitlab-mcp"],
"env": {
"GITLAB_PERSONAL_ACCESS_TOKEN": "your_gitlab_token",
"GITLAB_API_URL": "https://gitlab.com/api/v4"
}
}
}
}OAuth authentication uses PKCE for secure access. Start the server with OAuth enabled and follow the login flow through the provided OAuth tool set. Tokens are automatically saved and survive server restarts.
Important port note: the OAuth callback uses http://localhost:7171 for compatibility with GitLab’s OAuth apps. Ensure port 7171 is free during authentication.
Automatic token refresh keeps your sessions valid without manual intervention.
Environment variables you can set to customize behavior:
USE_OAUTH
GITLAB_API_URL
GITLAB_PERSONAL_ACCESS_TOKEN
GITLAB_PROJECT_ID
GITLAB_ALLOWED_PROJECT_IDS
GITLAB_READ_ONLY_MODE
OAUTH_REDIRECT_PORT_PREFERRED
OAUTH_REDIRECT_PORT_RANGEThe MCP server exposes a range of operations to manage repositories, merge requests, issues, commits, and branches. You can perform search, read, create, update, and merge actions against GitLab resources through the MCP client. Use the same session for multiple requests and rely on token persistence to avoid re-authentication.
Use OAuth for production deployments to avoid exposing long-lived tokens. Enable token persistence per your security policy and rely on automatic token refresh to maintain seamless access.
If you encounter authentication failures, check that OAuth is enabled and that port 7171 is open for the callback. Verify that your GITLAB_API_URL points to the correct GitLab instance and that tokens (OAuth or PAT) are valid.
Initiate OAuth authentication flow using PKCE to obtain tokens.
Check the current authentication status and token validity.
Logout and clear stored OAuth tokens.
Search for GitLab repositories accessible to the authenticated user.
Retrieve the repository file tree for navigation.
Read the contents of a file in a repository.
Create or update a file in a repository.
Push multiple file changes to a repository.
Get details of a merge request.
Get the diffs for a merge request.
Create a new merge request.
Update an existing merge request.
Merge a merge request.
Create a new issue in a project.
Get details of an issue.
Update an existing issue.
List issues in a project.
List repository commits.
Get details for a specific commit.
Get the diff for a commit.
Create a new branch in the repository.
Fork a repository into another namespace.