GitLab MCP Server
このプロジェクトはアーカイブされています
公式の glab mcp の使用を検討してください
{
"mcpServers": {
"glab": {
"type": "stdio",
"command": "glab",
"args": ["mcp", "serve"]
}
}
}GitLab MCP サーバー
IntelliJ IDEA の GitHub Copilot と統合する、本番環境対応の GitLab 用 Model Context Protocol (MCP) サーバーです。Git リモートから GitLab プロジェクトを自動検出し、インテリジェントなポーリングでパイプラインとジョブのステータスを監視し、リトライロジックを備えた信頼性の高い API 統合を提供します。
ステータス: ✅ 完全検証済み (35 テスト、合格率 100%)
クイックスタート
1. 依存関係のインストール
# Runtime dependencies
pip install -r requirements.txt
# Development/test dependencies (optional)
pip install -r requirements-dev.txt2. 環境設定
# Copy the example configuration
cp .env.example .env
# Edit .env with your GitLab credentials
# GITLAB_URL=https://your-gitlab-instance.com
# GITLAB_TOKEN=glpat-xxxGitLab トークンの取得方法:
GitLab 設定 → Personal Access Tokens
以下のスコープを持つトークンを作成:
api,read_api,read_repositoryトークン値を
.envにコピー
3. サーバーの起動
# Using the startup script
./run.sh
# Or directly
python -m src.server期待される出力:
2026-02-10 13:15:30,123 - src.server - INFO - Initializing GitLab MCP server for https://...
2026-02-10 13:15:30,456 - src.server - INFO - GitLab authentication successful
2026-02-10 13:15:30,789 - src.server - INFO - Tools registered successfully
2026-02-10 13:15:30,900 - src.server - INFO - GitLab MCP server started, listening on stdio4. IntelliJ IDEA での設定
GitHub Copilot プラグインをインストール (未インストールの場合)
設定 → ツール → GitHub Copilot → MCP サーバー
MCP サーバーを追加:
タイプ:
stdioコマンド:
python -m src.server環境:
.envファイルを指定
Related MCP server: GitLab MCP Server
機能
✅ 自動プロジェクト検出
プロジェクトパスを指定する必要はありません
git リモート origin から自動的に検出
SSH および HTTPS URL で動作
ネストされた GitLab グループをサポート
✅ パイプラインステータス監視
リアルタイムのパイプラインステータス
すべてのジョブの詳細とステータス
ブランチとコミットの自動検出
人間が読みやすい形式の出力
✅ スマートポーリングによるジョブステータス
ジョブ完了まで 2 秒ごとにポーリング
設定可能なタイムアウト (デフォルト 30 秒)
中間状態を返却
レスポンスにポーリングメタデータを含める
✅ 信頼性の高い API 統合
指数バックオフ (1秒、5秒、9秒) を伴う 3 回のリトライ
一時的なネットワーク障害を適切に処理
セッションレベルのプロジェクト ID キャッシュ
デバッグ用の明確なエラーメッセージ
✅ セルフホスト型 GitLab のサポート
あらゆるセルフホスト型 GitLab インスタンスで動作
gitlab.com への依存なし
完全な API 互換性
利用可能なツール
check_pipeline_status
現在のプロジェクトとブランチのパイプラインステータスを取得
Input: working_directory (string)
Optional: branch (string), commit (string)
Output: Pipeline status report with all jobs機能:
自動検出: git リポジトリからプロジェクト、ブランチ、コミットを検出
返却値: パイプライン ID、ステータス、各ジョブのステータス
形式: 人間が読みやすいテキストレポート
内容: タイミング、Web URL、ステージ情報
例:
# In Copilot context:
# "Check the pipeline status for this project"
# → Copilot calls: check_pipeline_status("/path/to/repo")check_job_status
自動ポーリングによる特定のジョブステータスの確認
Input: working_directory (string)
job_name (string) OR job_id (integer)
Output: Job status report with polling metadata機能:
自動検出: 現在のブランチ/コミットからプロジェクト、パイプラインを検出
検索: ジョブ名または数値のジョブ ID で検索
ポーリング: 完了まで 2 秒ごとにポーリング (最大 30 秒)
返却値: ジョブステータス、タイミング、ログ URL、ポーリングメタデータ
メタデータ:
is_polling,polling_timeout,polling_duration_seconds
例:
# In Copilot context:
# "Check the status of the 'test' job"
# → Copilot calls: check_job_status("/path/to/repo", job_name="test")プロジェクト構造
gitlab-mcp/
├── src/
│ ├── __init__.py
│ ├── server.py # MCP server entry point
│ ├── mcp_tools.py # Tool definitions & logic
│ ├── gitlab_client.py # GitLab API wrapper (retry logic, caching)
│ └── git_utils.py # Git utilities (URL parsing, branch detection)
│
├── tests/ # Comprehensive test suite
│ ├── test_gitlab_client.py # 9 tests for API client
│ ├── test_git_utils.py # 11 tests for git utilities
│ ├── test_mcp_tools.py # 10 tests for tool logic
│ ├── test_server.py # 5 tests for server initialization
│ └── conftest.py # Pytest configuration
│
├── requirements.txt # Runtime dependencies
├── requirements-dev.txt # Test dependencies
├── .env.example # Configuration template
├── pytest.ini # Pytest settings
├── run.sh # Startup script
└── README.md # This fileテストの実行
クイックテスト実行
# Run all tests
python -m pytest tests/ -v
# Quick summary
python -m pytest tests/ -qテストカバレッジ
合計テスト数: 35 (合格率 100% ✅)
テスト済みモジュール: 4 つのコアモジュールすべて
gitlab_client.py: 9 テスト (API クライアント、リトライロジック、キャッシュ)git_utils.py: 11 テスト (URL 解析、検証)mcp_tools.py: 10 テスト (ポーリング、フォーマット、ロジック)server.py: 5 テスト (初期化、設定)
特定のテストの実行
# Test GitLab client
python -m pytest tests/test_gitlab_client.py -v
# Test git utilities
python -m pytest tests/test_git_utils.py -v
# Test MCP tools
python -m pytest tests/test_mcp_tools.py -v
# Test server
python -m pytest tests/test_server.py -v
# Run with coverage
python -m pytest tests/ --cov=src --cov-report=html設定
環境変数
.env ファイルを作成して以下を記述:
# Required
GITLAB_URL=https://your-gitlab-instance.com
GITLAB_TOKEN=glpat-your-token-here
# Optional
DEBUG=false # Set to 'true' for verbose loggingリトライロジックの設定
クライアントは失敗した API 呼び出しを自動的にリトライします:
合計試行回数: 3 (初回 + 2 回のリトライ)
バックオフ遅延: 1秒、5秒、9秒
適用対象: すべての GitLab API 呼び出し
ジョブポーリングの設定
コードを通じてポーリング動作を設定します:
# Default settings
_poll_job_status(client, project, job_name, job_id,
timeout_seconds=30, # Max wait time
poll_interval=2.0) # Check every 2 secondsアーキテクチャ
┌─────────────────────────────────────────────┐
│ IntelliJ IDEA + GitHub Copilot Plugin │
│ (IDE Client) │
└──────────────────┬──────────────────────────┘
│ (stdio transport)
│ (MCP Protocol)
│
┌──────────────────▼──────────────────────────┐
│ FastMCP Server (Python) │
│ ┌────────────────────────────────────────┐ │
│ │ MCP Tools │ │
│ │ • check_pipeline_status │ │
│ │ • check_job_status (with polling) │ │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
│ │ GitLab Client │ │
│ │ • Session-based caching │ │
│ │ • Retry logic (1s, 5s, 9s backoff) │ │
│ │ • Pipeline/job/MR queries │ │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
│ │ Git Utilities │ │
│ │ • SSH/HTTPS URL parsing │ │
│ │ • Branch/commit detection │ │
│ │ • Repository validation │ │
│ └────────────────────────────────────────┘ │
└──────────────────┬──────────────────────────┘
│ (HTTP REST API)
│
┌──────────────────▼──────────────────────────┐
│ Self-Hosted GitLab Instance │
│ (or gitlab.com) │
└─────────────────────────────────────────────┘トラブルシューティング
設定の問題
"GITLAB_URL environment variable is not set"
.envファイルが存在することを確認:ls -la .env.envに GITLAB_URL があるか確認:grep GITLAB_URL .envサーバー実行時に
.envが作業ディレクトリにあることを確認
"GITLAB_TOKEN environment variable is not set"
GITLAB_TOKENを.envに追加トークン形式:
glpat-xxx(GitLab パーソナルアクセストークン)トークンに正しいスコープがあるか確認:
api,read_api,read_repository
"GitLab authentication successful" だがツールが失敗する
GitLab インスタンスにアクセス可能か確認:
curl -H "PRIVATE-TOKEN: $TOKEN" $GITLAB_URL/api/v4/userトークンに正しいスコープがあるか確認
GitLab インスタンスへのファイアウォール/ネットワークアクセスを確認
Git の問題
"Not a git repository"
git リポジトリ内にいることを確認:
git remote -vサポートされているリモート形式:
git@gitlab.host:group/project.githttps://gitlab.host/group/project.githttps://gitlab.host/group/project(.git なし)http://gitlab.host/group/project(HTTP, HTTPS ではない)
"Unable to parse git remote URL"
git リモート形式を確認:
git remote -vSSH と HTTPS は両方とも標準の GitLab 形式である必要があります
ネストされたグループをサポート:
company/team/project
パイプライン/ジョブの問題
"No pipeline found for branch"
ブランチがプッシュされていることを確認:
git pushGitLab でパイプライントリガーが設定されているか確認
明示的なコミット SHA で試す:
check_pipeline_status(dir, commit="abc123")
"Job not found: test"
ジョブ名が完全に一致しているか確認 (大文字小文字を区別)
パイプラインにジョブがあるか確認 (空の可能性がある)
ジョブの一覧表示:
check_pipeline_status(dir)で全ジョブを確認
ジョブポーリングがタイムアウトする (30 秒)
ジョブが 2 分以内に開始されていない
ツールを再実行して現在のステータスを確認可能
ツールはタイムアウト後も最後に確認された状態を返却
デバッグモード
詳細ログを有効にする:
# In .env
DEBUG=true
# Or as environment variable
DEBUG=true python -m src.serverツール呼び出し中のログを確認して詳細なエラーメッセージを確認してください。
検証とテスト
テスト結果
============================= 35 passed in 12.73s ===============================
✅ test_git_utils.py (11 tests)
✅ test_gitlab_client.py (9 tests)
✅ test_mcp_tools.py (10 tests)
✅ test_server.py (5 tests)テスト内容
✅ モックレスポンスを使用した GitLab API クライアント
✅ リトライロジックと指数バックオフ
✅ プロジェクト ID キャッシュメカニズム
✅ Git URL 解析 (SSH, HTTPS, ネストされたグループ)
✅ タイムアウト付きジョブポーリング
✅ レスポンスのフォーマット
✅ サーバーの初期化と設定
✅ エラーハンドリングと検証
実際の GitLab インスタンスなしでのテスト
すべてのテストはモック化された GitLab API を使用します (実際の API 呼び出しは不要):
python -m pytest tests/ -vパフォーマンス
標準的な応答時間
初回 API 呼び出し: 1~3 秒 (ネットワークに依存)
後続の呼び出し: <500ms (キャッシュされたプロジェクト ID)
ジョブポーリング: 2 秒間隔
テストスイート全体: 約 13 秒
キャッシュ戦略
プロジェクト ID: サーバーセッションごとにキャッシュ
リセット: サーバー再起動でキャッシュをクリア
利点: 繰り返し操作の API 呼び出しを削減
実装の詳細
リトライロジック
Attempt 1: Immediate call
↓ (fails)
Wait 1 second
Attempt 2: Retry
↓ (fails)
Wait 5 seconds
Attempt 3: Final retry
↓ (fails)
Raise GitLabClientErrorURL 解析の例
SSH: git@gitlab.com:group/project.git → group/project
HTTPS: https://gitlab.com/group/project.git → group/project
HTTPS: https://gitlab.com/group/project → group/project
SSH: git@host:company/team/subteam/project.git → company/team/subteam/projectジョブポーリングの動作
Initial check: Get job status immediately
↓
If terminal state (success/failed/canceled/skipped): Return
↓
If not started: Polling loop
├─ Check every 2 seconds
├─ Max 30 seconds total
└─ Return with polling_timeout flag if timeout occursサポートされている Git リポジトリ
✅ セルフホスト型 GitLab インスタンス (任意のバージョン) ✅ gitlab.com (パブリック GitLab) ✅ ネストされたグループ (company/team/project/...) ✅ SSH および HTTPS リモート
❌ サポート対象外: GitHub, Bitbucket など (GitLab のみ)
次のステップ
1. ローカルテスト
# Test git utilities
python -c "
from src.git_utils import get_project_path_from_working_dir
print(get_project_path_from_working_dir('.'))
"2. GitLab 接続のテスト
python -c "
import os
from dotenv import load_dotenv
from src.gitlab_client import GitLabClient
load_dotenv()
client = GitLabClient(os.getenv('GITLAB_URL'), os.getenv('GITLAB_TOKEN'))
client.gl.auth()
print('✓ GitLab auth successful')
"3. サーバーの起動
./run.sh
# Then configure in IntelliJ IDEA GitHub Copilot plugin4. Copilot での使用
IntelliJ IDEA の Copilot で以下のように使用:
"パイプラインのステータスを確認して"
"test ジョブのステータスはどう?"
"最新のパイプラインを表示して"
貢献
テストや機能を追加する場合:
tests/ディレクトリにテストファイルを作成GitLab API のモックを使用:
patch('src.gitlab_client.gitlab.Gitlab')テストを実行:
python -m pytest tests/ -vコミット前にすべてのテストが合格することを確認
依存関係
ランタイム
fastmcp>=2.14.0- Model Context Protocol サーバーpython-gitlab>=4.0.0- GitLab API クライアントpython-dotenv>=1.0.0- 環境変数読み込みGitPython>=3.1.0- Git 操作
開発/テスト
pytest>=8.0.0- テストフレームワークrequests-mock>=1.11.0- HTTP モック (オプション)
実装ステータス
機能 | ステータス | テスト |
パイプラインステータス監視 | ✅ 完了 | 4 |
ジョブステータス検索 | ✅ 完了 | 5 |
ジョブポーリング | ✅ 完了 | 4 |
Git URL 解析 | ✅ 完了 | 8 |
リトライロジック | ✅ 完了 | 1 |
エラーハンドリング | ✅ 完了 | 3 |
サーバー初期化 | ✅ 完了 | 5 |
設定検証 | ✅ 完了 | 5 |
サポート
問題や質問がある場合:
デバッグログを有効にする:
.envでDEBUG=trueを設定ログを確認: ツール呼び出し中のサーバー出力を確認
セットアップを検証: 上記のトラブルシューティングセクションに従う
テストを確認: 使用例については
tests/を確認git リモートを確認:
git remote -vが有効な GitLab URL である必要がある
ライセンス
[ここにライセンスを追加]
最終検証日: 2026年2月10日 テストスイート: 35/35 合格 ✅ ステータス: 本番環境対応 🚀
This server cannot be deployed
Maintenance
Related MCP Connectors
Agentic CI operations for build inspection, failure diagnosis, and runner troubleshooting.
Plan Salesforce deploys, open pull requests and trigger pipelines from your AI client.
Direct access to Cypress tests results and accessibility reports in your AI workflow.
Live status and health checks for AI coding providers: Claude, Cursor, Copilot, Codex and more.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI clients to manage GitLab pipelines through natural language commands. Supports triggering pipelines, checking status, listing pipelines, viewing jobs, and canceling pipelines across multiple GitLab instances.107 npmISC
- FlicenseAqualityCmaintenanceConnects AI assistants to GitLab to interact with merge requests, reviews, discussions, pipelines, and test results through natural language queries. Supports viewing MR details, responding to comments, checking test summaries, and analyzing job logs.122-
- FlicenseNot gradedqualityNot gradedmaintenanceConnects AI assistants to GitLab projects, enabling natural language queries for merge requests, code reviews, test results, pipelines, and discussions. Supports viewing MR details, responding to comments, and analyzing CI/CD job logs.-
- AlicenseNot gradedqualityCmaintenanceIntegrates GitLab with AI assistants to manage merge requests, analyze CI/CD pipelines, and create Architecture Decision Records. It enables seamless code searching, pipeline triggering, and deployment management through the Model Context Protocol.1MIT