Skip to main content
Glama

이 프로젝트는 보관되었습니다

공식 glab mcp 사용을 고려하세요.

{
  "mcpServers": {
    "glab": {
      "type": "stdio",
      "command": "glab",
      "args": ["mcp", "serve"]
    }
  }
}

GitLab MCP 서버

IntelliJ IDEA의 GitHub Copilot과 통합되는 프로덕션 준비 완료 모델 컨텍스트 프로토콜(MCP) 서버입니다. git 원격 저장소에서 GitLab 프로젝트를 자동으로 감지하고, 지능형 폴링으로 파이프라인 및 작업 상태를 모니터링하며, 재시도 로직이 포함된 안정적인 API 통합을 제공합니다.

상태: ✅ 완전 검증됨 (35개 테스트, 통과율 100%)


빠른 시작

1. 의존성 설치

# Runtime dependencies
pip install -r requirements.txt

# Development/test dependencies (optional)
pip install -r requirements-dev.txt

2. 환경 설정

# Copy the example configuration
cp .env.example .env

# Edit .env with your GitLab credentials
# GITLAB_URL=https://your-gitlab-instance.com
# GITLAB_TOKEN=glpat-xxx

GitLab 토큰을 얻는 방법:

  1. GitLab 설정 → 개인 액세스 토큰(Personal Access Tokens)

  2. 다음 범위로 토큰 생성: api, read_api, read_repository

  3. 토큰 값을 .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 stdio

4. IntelliJ IDEA에서 설정

  1. GitHub Copilot 플러그인 설치 (아직 설치되지 않은 경우)

  2. 설정 → 도구(Tools) → GitHub Copilot → MCP 서버

  3. 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, 상태, 개별 상태를 포함한 작업 목록

  • 형식: 사람이 읽기 쉬운 텍스트 보고서

  • 포함 항목: 타이밍, 웹 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 환경 변수가 설정되지 않았습니다"

  • .env 파일 존재 확인: ls -la .env

  • .env에 GITLAB_URL이 있는지 확인: grep GITLAB_URL .env

  • 서버 실행 시 .env가 작업 디렉토리에 있는지 확인

"GITLAB_TOKEN 환경 변수가 설정되지 않았습니다"

  • .envGITLAB_TOKEN 추가

  • 토큰 형식: glpat-xxx (GitLab 개인 액세스 토큰)

  • 토큰에 올바른 범위(api, read_api, read_repository)가 있는지 확인

"GitLab 인증 성공"이지만 도구가 실패하는 경우

  • GitLab 인스턴스 접근 가능 여부 확인: curl -H "PRIVATE-TOKEN: $TOKEN" $GITLAB_URL/api/v4/user

  • 토큰에 올바른 범위가 있는지 확인

  • GitLab 인스턴스에 대한 방화벽/네트워크 접근 확인

Git 문제

"Git 저장소가 아닙니다"

  • git 저장소에 있는지 확인: git remote -v

  • 지원되는 원격 형식:

    • git@gitlab.host:group/project.git

    • https://gitlab.host/group/project.git

    • https://gitlab.host/group/project (.git 제외)

    • http://gitlab.host/group/project (HTTPS가 아닌 HTTP)

"git 원격 URL을 파싱할 수 없습니다"

  • git 원격 형식 확인: git remote -v

  • SSH와 HTTPS 모두 표준 GitLab 형식이어야 함

  • 중첩 그룹 지원: company/team/project

파이프라인/작업 문제

"브랜치에 대한 파이프라인을 찾을 수 없습니다"

  • 브랜치가 푸시되었는지 확인: git push

  • GitLab에서 파이프라인 트리거가 구성되었는지 확인

  • 명시적 커밋 SHA로 시도: check_pipeline_status(dir, commit="abc123")

"작업을 찾을 수 없음: 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 GitLabClientError

URL 파싱 예시

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 plugin

4. Copilot과 함께 사용

Copilot이 설치된 IntelliJ IDEA에서:

  • "파이프라인 상태 확인해줘"

  • "test 작업 상태가 어때?"

  • "최신 파이프라인 보여줘"


기여

테스트나 기능을 추가하려면:

  1. tests/ 디렉토리에 테스트 파일 생성

  2. GitLab API 모킹 사용: patch('src.gitlab_client.gitlab.Gitlab')

  3. 테스트 실행: python -m pytest tests/ -v

  4. 커밋 전 모든 테스트 통과 확인


의존성

런타임

  • fastmcp>=2.14.0 - 모델 컨텍스트 프로토콜 서버

  • 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


지원

문제나 질문이 있는 경우:

  1. 디버그 로깅 활성화: .envDEBUG=true 설정

  2. 로그 확인: 도구 호출 중 서버 출력 검토

  3. 설정 확인: 위의 문제 해결 섹션 참조

  4. 테스트 검토: 사용 예시는 tests/ 확인

  5. git 원격 확인: git remote -v가 유효한 GitLab URL이어야 함


라이선스

[여기에 라이선스 추가]


마지막 검증: 2026년 2월 10일 테스트 스위트: 35/35 통과 ✅ 상태: 프로덕션 준비 완료 🚀

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables 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 npm
    ISC
  • F
    license
    A
    quality
    C
    maintenance
    Connects 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.
    12
    2
    -
  • F
    license
    Not graded
    quality
    Not graded
    maintenance
    Connects 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.
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    Integrates 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.
    1
    MIT