@zereight/mcp-gitlab 2.2.2 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +41 -12
- package/README.md +42 -13
- package/README.pt-BR.md +41 -12
- package/README.zh-CN.md +41 -12
- package/build/config.js +15 -1
- package/build/index.js +2 -1
- package/build/personal-access-token.js +75 -0
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
# GitLab MCP Server
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@zereight/mcp-gitlab)
|
|
4
|
-
[](vscode
|
|
4
|
+
[](https://vscode.dev/redirect/mcp/install?name=zereight.gitlab-mcp&config=%7B%22type%22%3A%22stdio%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40zereight%2Fmcp-gitlab%40latest%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab-token%7D%22%2C%22GITLAB_API_URL%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%2C%22GITLAB_PERMISSION_MODE%22%3A%22full%22%7D%7D)
|
|
5
|
+
[](https://cursor.com/en/install-mcp?name=zereight.gitlab-mcp&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkB6ZXJlaWdodC9tY3AtZ2l0bGFiQGxhdGVzdCJdLCJlbnYiOnsiR0lUTEFCX1BFUlNPTkFMX0FDQ0VTU19UT0tFTiI6IiR7ZW52OkdJVExBQl9QRVJTT05BTF9BQ0NFU1NfVE9LRU59IiwiR0lUTEFCX0FQSV9VUkwiOiJodHRwczovL2dpdGxhYi5jb20vYXBpL3Y0IiwiR0lUTEFCX1BFUk1JU1NJT05fTU9ERSI6ImZ1bGwifX0%3D)
|
|
5
6
|
|
|
6
7
|
[English](./README.md) | [한국어](./README.ko.md) | [简体中文](./README.zh-CN.md) | [Português (Brasil)](./README.pt-BR.md)
|
|
7
8
|
|
|
8
9
|
📖 **[문서 →](https://zereight.github.io/gitlab-mcp/)** 설정 가이드, 환경 변수, 전체 도구 레퍼런스는 호스팅된 문서 사이트에서 확인할 수 있습니다.
|
|
9
10
|
|
|
11
|
+
`@zereight/mcp-gitlab`의 권장 로컬 PAT 설치입니다. 명령 인자는 [Claude Code](./docs/clients/claude-code.md)와 [Codex](./docs/clients/codex.md) 가이드와 같습니다.
|
|
12
|
+
|
|
13
|
+
`zereight-mcp-gitlab` 바이너리를 먼저 설치하세요. `npm install -g @zereight/mcp-gitlab`, 또는 Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` 다음 `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`.
|
|
14
|
+
|
|
15
|
+
토큰을 화면에 표시하지 않고 읽은 다음 export 하세요. 셸 기록에는 변수 이름만 남습니다.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| 클라이언트 | 설치 |
|
|
22
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
23
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
24
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
25
|
+
| Cursor | [Cursor 설정 가이드](./docs/clients/cursor.md) |
|
|
26
|
+
| VS Code | [VS Code 설정 가이드](./docs/clients/vscode.md) |
|
|
27
|
+
| JSON 클라이언트 | [JSON 기반 MCP 클라이언트 설정 가이드](./docs/clients/json-clients.md) |
|
|
28
|
+
|
|
10
29
|
[](https://www.star-history.com/?repos=zereight%2Fgitlab-mcp&type=date&legend=top-left)
|
|
11
30
|
|
|
12
31
|
## @zereight/mcp-gitlab
|
|
@@ -28,15 +47,23 @@ PAT, OAuth, 읽기 전용 모드, 동적 API URL, 원격 인증을 지원하며
|
|
|
28
47
|
|
|
29
48
|
### 비교 요약
|
|
30
49
|
|
|
31
|
-
|
|
|
32
|
-
|
|
33
|
-
| **적합한 경우** | AI 에이전트 워크플로우
|
|
34
|
-
| **도구 모델**
|
|
35
|
-
| **MR 리뷰**
|
|
36
|
-
| **Node.js**
|
|
37
|
-
| **라이선스**
|
|
50
|
+
| | @zereight/mcp-gitlab | GitLab MCP A (커뮤니티 CQRS형) | GitLab 공식 MCP 서버 |
|
|
51
|
+
| --------------- | ---------------------------------------------------------------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| **적합한 경우** | AI 에이전트 워크플로우 | 엔터프라이즈 멀티 인스턴스 / 그룹형 도구 | GitLab에 내장, 별도 설치 없음 |
|
|
53
|
+
| **도구 모델** | 274개 도구: toolset 272개 + `execute_graphql` + `discover_tools` | ~50–60개 `browse_*` / `manage_*` 그룹 도구 | HTTP 헤더로 고르는 toolset |
|
|
54
|
+
| **MR 리뷰** | 2단계 배치 diff | 서버마다 다름 | `get_merge_request`에 diffs |
|
|
55
|
+
| **Node.js** | >=18.17 | 보통 >=24 | stdio는 `mcp-remote`, Node.js 20+ |
|
|
56
|
+
| **라이선스** | MIT | 서버마다 다름 | GitLab의 일부 |
|
|
57
|
+
|
|
58
|
+
[GitLab MCP A 전체 비교 →](./docs/comparison/community-gitlab-mcp-a.md)
|
|
38
59
|
|
|
39
|
-
[
|
|
60
|
+
GitLab은 [공식 MCP 서버](https://docs.gitlab.com/user/model_context_protocol/mcp_server/)도 제공합니다.
|
|
61
|
+
|
|
62
|
+
- Free, Premium, Ultimate. GitLab 19.2에서 Premium에서 Free로 옮겨졌고, GitLab 19.5에서 GA입니다.
|
|
63
|
+
- GitLab.com에서는 최상위 그룹 Owner가 MCP 서버 접근을 허용합니다. GitLab Self-Managed와 GitLab Dedicated는 인스턴스 설정입니다. 기본값 규칙은 공식 페이지에 있습니다.
|
|
64
|
+
- 원격 클라이언트는 HTTP `https://<gitlab.example.com>/api/v4/mcp`와 OAuth 2.0 동적 클라이언트 등록을 사용합니다.
|
|
65
|
+
- stdio는 `mcp-remote`를 거치며 Node.js 20 이상이 필요합니다.
|
|
66
|
+
- Toolset은 `X-Gitlab-Enabled-Mcp-Server-Toolsets` 헤더를 사용합니다. 선택 헤더 `X-Gitlab-Mcp-Server-Tool-Name-Prefix`는 도구 이름 접두사의 앞 32자만 유지합니다.
|
|
40
67
|
|
|
41
68
|
빠른 시작: 아래에서 Personal Access Token 또는 OAuth2 설정 중 하나를 선택하고 `@zereight/mcp-gitlab`을 설치한 뒤 MCP 클라이언트 설정에서 `zereight-mcp-gitlab`을 사용하세요.
|
|
42
69
|
|
|
@@ -63,7 +90,7 @@ PAT, OAuth, 읽기 전용 모드, 동적 API URL, 원격 인증을 지원하며
|
|
|
63
90
|
|
|
64
91
|
**로컬/데스크톱 사용**(가장 일반적):
|
|
65
92
|
|
|
66
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — 가장 단순한 설정
|
|
93
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` 또는 `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — 가장 단순한 설정
|
|
67
94
|
2. **OAuth2 — 로컬 브라우저** (`GITLAB_USE_OAUTH`) — 더 나은 보안을 위해 권장
|
|
68
95
|
|
|
69
96
|
**서버/원격 배포**:
|
|
@@ -111,7 +138,7 @@ command = lib.getExe inputs.gitlab-mcp.packages.${system}.default;
|
|
|
111
138
|
|
|
112
139
|
예시는 기존 `mcp-gitlab`보다 충돌 가능성이 낮은 `zereight-mcp-gitlab` 별칭을 사용합니다. MCP 클라이언트가 찾지 못하면 `which zereight-mcp-gitlab`의 절대 경로를 사용하세요.
|
|
113
140
|
|
|
114
|
-
전역 설치를 쓰지 않으려면 `npx -y @zereight/mcp-gitlab@2.2.
|
|
141
|
+
전역 설치를 쓰지 않으려면 `npx -y @zereight/mcp-gitlab@2.2.3`처럼 직전 안정 버전(문서가 권장하는 버전)으로 고정하세요. 항상 최신 버전을 원하면 `npx -y @zereight/mcp-gitlab@latest`를 사용하세요. 새 버전이 나오면 서버가 시작 시 stderr로 알려줍니다(`GITLAB_DISABLE_VERSION_CHECK=true`로 비활성화 가능).
|
|
115
142
|
|
|
116
143
|
#### CLI 인자 사용하기(환경 변수 문제가 있는 클라이언트용)
|
|
117
144
|
|
|
@@ -177,10 +204,12 @@ CLI 인자는 환경 변수보다 우선합니다.
|
|
|
177
204
|
|
|
178
205
|
- sse
|
|
179
206
|
|
|
207
|
+
변수 이름만 넘기세요. Docker 클라이언트는 export한 `GITLAB_PERSONAL_ACCESS_TOKEN` 값을 컨테이너로 복사합니다.
|
|
208
|
+
|
|
180
209
|
```shell
|
|
181
210
|
docker run -i --rm \
|
|
182
211
|
-e HOST=0.0.0.0 \
|
|
183
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
212
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
184
213
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
185
214
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
186
215
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/README.md
CHANGED
|
@@ -4,14 +4,33 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@zereight/mcp-gitlab)
|
|
5
5
|
[](https://www.npmjs.com/package/@zereight/mcp-gitlab)
|
|
6
6
|
[](https://github.com/zereight/gitlab-mcp/blob/main/LICENSE)
|
|
7
|
-
[](vscode
|
|
8
|
-
[](https://vscode.dev/redirect/mcp/install?name=zereight.gitlab-mcp&config=%7B%22type%22%3A%22stdio%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40zereight%2Fmcp-gitlab%40latest%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab-token%7D%22%2C%22GITLAB_API_URL%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%2C%22GITLAB_PERMISSION_MODE%22%3A%22full%22%7D%7D)
|
|
8
|
+
[](https://cursor.com/en/install-mcp?name=zereight.gitlab-mcp&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkB6ZXJlaWdodC9tY3AtZ2l0bGFiQGxhdGVzdCJdLCJlbnYiOnsiR0lUTEFCX1BFUlNPTkFMX0FDQ0VTU19UT0tFTiI6IiR7ZW52OkdJVExBQl9QRVJTT05BTF9BQ0NFU1NfVE9LRU59IiwiR0lUTEFCX0FQSV9VUkwiOiJodHRwczovL2dpdGxhYi5jb20vYXBpL3Y0IiwiR0lUTEFCX1BFUk1JU1NJT05fTU9ERSI6ImZ1bGwifX0%3D)
|
|
9
|
+
[](https://deepwiki.com/zereight/gitlab-mcp)
|
|
9
10
|
[](https://mcptoplist.com/server/io.github.zereight%2Fgitlab-mcp) [](https://mcpindex.ai/server/io-github-zereight-gitlab-mcp)
|
|
10
11
|
|
|
11
12
|
[English](./README.md) | [한국어](./README.ko.md) | [简体中文](./README.zh-CN.md) | [Português (Brasil)](./README.pt-BR.md)
|
|
12
13
|
|
|
13
14
|
📖 **[Documentation →](https://zereight.github.io/gitlab-mcp/)** Setup guides, environment variables, and the full tool reference live on the hosted docs site.
|
|
14
15
|
|
|
16
|
+
Install `@zereight/mcp-gitlab` with the recommended local personal-access-token setup. These commands use the same arguments as the [Claude Code](./docs/clients/claude-code.md) and [Codex](./docs/clients/codex.md) guides.
|
|
17
|
+
|
|
18
|
+
Install the `zereight-mcp-gitlab` binary first with `npm install -g @zereight/mcp-gitlab`, or Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` and `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`.
|
|
19
|
+
|
|
20
|
+
Read the token without echo, then export it. The shell history keeps the variable name.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
| Client | Install |
|
|
27
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
28
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
29
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
30
|
+
| Cursor | [Cursor setup guide](./docs/clients/cursor.md) |
|
|
31
|
+
| VS Code | [VS Code setup guide](./docs/clients/vscode.md) |
|
|
32
|
+
| JSON clients | [JSON-based MCP clients setup guide](./docs/clients/json-clients.md) |
|
|
33
|
+
|
|
15
34
|
[](https://www.star-history.com/?repos=zereight%2Fgitlab-mcp&type=date&legend=top-left)
|
|
16
35
|
|
|
17
36
|
## @zereight/mcp-gitlab
|
|
@@ -33,15 +52,23 @@ Supports PAT, OAuth, read-only mode, dynamic API URLs, and remote authorization
|
|
|
33
52
|
|
|
34
53
|
### How we compare
|
|
35
54
|
|
|
36
|
-
|
|
|
37
|
-
|
|
38
|
-
| **Best for**
|
|
39
|
-
| **Tool model** | 274 tools: 272 in toolsets + `execute_graphql` + `discover_tools` | ~50–60 grouped `browse_*` / `manage_*` tools |
|
|
40
|
-
| **MR review**
|
|
41
|
-
| **Node.js**
|
|
42
|
-
| **License**
|
|
55
|
+
| | @zereight/mcp-gitlab | GitLab MCP A (community CQRS-style) | GitLab official MCP server |
|
|
56
|
+
| -------------- | ----------------------------------------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
57
|
+
| **Best for** | AI agent workflows | Enterprise multi-instance / grouped tools | Built into GitLab, no separate install |
|
|
58
|
+
| **Tool model** | 274 tools: 272 in toolsets + `execute_graphql` + `discover_tools` | ~50–60 grouped `browse_*` / `manage_*` tools | Toolsets chosen with an HTTP header |
|
|
59
|
+
| **MR review** | 2-step batched diff | Varies | `get_merge_request` with diffs |
|
|
60
|
+
| **Node.js** | >=18.17 | Often >=24 | Node.js 20+ for stdio via `mcp-remote` |
|
|
61
|
+
| **License** | MIT | Varies | Part of GitLab |
|
|
62
|
+
|
|
63
|
+
[Full comparison with GitLab MCP A →](./docs/comparison/community-gitlab-mcp-a.md)
|
|
43
64
|
|
|
44
|
-
[
|
|
65
|
+
GitLab also ships an [official MCP server](https://docs.gitlab.com/user/model_context_protocol/mcp_server/).
|
|
66
|
+
|
|
67
|
+
- Free, Premium, and Ultimate. Moved from Premium to Free in GitLab 19.2. Generally available in GitLab 19.5.
|
|
68
|
+
- On GitLab.com, a top-level group Owner allows access to the MCP server. On GitLab Self-Managed and GitLab Dedicated, an administrator controls the instance setting. Default rules are on the official page.
|
|
69
|
+
- Remote clients use HTTP `https://<gitlab.example.com>/api/v4/mcp` with OAuth 2.0 dynamic client registration.
|
|
70
|
+
- stdio goes through `mcp-remote` and needs Node.js 20 or later.
|
|
71
|
+
- Toolsets use the `X-Gitlab-Enabled-Mcp-Server-Toolsets` header. An optional `X-Gitlab-Mcp-Server-Tool-Name-Prefix` header keeps the first 32 characters of a tool-name prefix.
|
|
45
72
|
|
|
46
73
|
Quick start: choose either Personal Access Token or OAuth2 setup below, install `@zereight/mcp-gitlab`, and use `zereight-mcp-gitlab` in your MCP client configuration.
|
|
47
74
|
|
|
@@ -68,7 +95,7 @@ The server supports four authentication methods:
|
|
|
68
95
|
|
|
69
96
|
**For local/desktop use** (most common):
|
|
70
97
|
|
|
71
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — simplest setup
|
|
98
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` or `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — simplest setup
|
|
72
99
|
2. **OAuth2 — Local Browser** (`GITLAB_USE_OAUTH`) — recommended for better security
|
|
73
100
|
|
|
74
101
|
**For server/remote deployments**:
|
|
@@ -116,7 +143,7 @@ The store path is pinned by your lock file; update it with `nix flake update git
|
|
|
116
143
|
|
|
117
144
|
The examples use `zereight-mcp-gitlab`, a less collision-prone alias for the legacy `mcp-gitlab` binary. If your MCP client cannot find it, use the absolute path from `which zereight-mcp-gitlab`.
|
|
118
145
|
|
|
119
|
-
No global install? Pin `npx` to the previous stable release (the version these docs recommend), for example `npx -y @zereight/mcp-gitlab@2.2.
|
|
146
|
+
No global install? Pin `npx` to the previous stable release (the version these docs recommend), for example `npx -y @zereight/mcp-gitlab@2.2.3`. If you always want the newest release, use `npx -y @zereight/mcp-gitlab@latest` instead. The server prints a notice to stderr on startup when a newer version is available (disable with `GITLAB_DISABLE_VERSION_CHECK=true`).
|
|
120
147
|
|
|
121
148
|
#### Using CLI Arguments (for clients with env var issues)
|
|
122
149
|
|
|
@@ -183,10 +210,12 @@ The same binary is also a `gh`-style GitLab CLI (`tool <name>` or curated forms
|
|
|
183
210
|
|
|
184
211
|
- sse
|
|
185
212
|
|
|
213
|
+
Pass the variable name only. The Docker client copies the exported `GITLAB_PERSONAL_ACCESS_TOKEN` into the container.
|
|
214
|
+
|
|
186
215
|
```shell
|
|
187
216
|
docker run -i --rm \
|
|
188
217
|
-e HOST=0.0.0.0 \
|
|
189
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
218
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
190
219
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
191
220
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
192
221
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/README.pt-BR.md
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
# GitLab MCP Server
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@zereight/mcp-gitlab)
|
|
4
|
-
[](vscode
|
|
4
|
+
[](https://vscode.dev/redirect/mcp/install?name=zereight.gitlab-mcp&config=%7B%22type%22%3A%22stdio%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40zereight%2Fmcp-gitlab%40latest%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab-token%7D%22%2C%22GITLAB_API_URL%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%2C%22GITLAB_PERMISSION_MODE%22%3A%22full%22%7D%7D)
|
|
5
|
+
[](https://cursor.com/en/install-mcp?name=zereight.gitlab-mcp&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkB6ZXJlaWdodC9tY3AtZ2l0bGFiQGxhdGVzdCJdLCJlbnYiOnsiR0lUTEFCX1BFUlNPTkFMX0FDQ0VTU19UT0tFTiI6IiR7ZW52OkdJVExBQl9QRVJTT05BTF9BQ0NFU1NfVE9LRU59IiwiR0lUTEFCX0FQSV9VUkwiOiJodHRwczovL2dpdGxhYi5jb20vYXBpL3Y0IiwiR0lUTEFCX1BFUk1JU1NJT05fTU9ERSI6ImZ1bGwifX0%3D)
|
|
5
6
|
|
|
6
7
|
[English](./README.md) | [한국어](./README.ko.md) | [简体中文](./README.zh-CN.md) | [Português (Brasil)](./README.pt-BR.md)
|
|
7
8
|
|
|
8
9
|
📖 **[Documentação →](https://zereight.github.io/gitlab-mcp/)** Guias de configuração, variáveis de ambiente e a referência completa de ferramentas estão disponíveis no site de documentação.
|
|
9
10
|
|
|
11
|
+
Instalação local recomendada com PAT para `@zereight/mcp-gitlab`. Os argumentos são os mesmos dos guias de [Claude Code](./docs/clients/claude-code.md) e [Codex](./docs/clients/codex.md).
|
|
12
|
+
|
|
13
|
+
Instale o binário `zereight-mcp-gitlab` antes. `npm install -g @zereight/mcp-gitlab`, ou Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` e `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`.
|
|
14
|
+
|
|
15
|
+
Leia o token sem eco e exporte. O histórico do shell fica só com o nome da variável.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Cliente | Instalação |
|
|
22
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
23
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
24
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
25
|
+
| Cursor | [Guia de configuração do Cursor](./docs/clients/cursor.md) |
|
|
26
|
+
| VS Code | [Guia de configuração do VS Code](./docs/clients/vscode.md) |
|
|
27
|
+
| Clientes JSON | [Guia para clientes MCP baseados em JSON](./docs/clients/json-clients.md) |
|
|
28
|
+
|
|
10
29
|
[](https://www.star-history.com/?repos=zereight%2Fgitlab-mcp&type=date&legend=top-left)
|
|
11
30
|
|
|
12
31
|
## @zereight/mcp-gitlab
|
|
@@ -28,15 +47,23 @@ Suporta PAT, OAuth, modo somente leitura, URLs de API dinâmicas e autorização
|
|
|
28
47
|
|
|
29
48
|
### Comparação
|
|
30
49
|
|
|
31
|
-
| | @zereight/mcp-gitlab
|
|
32
|
-
| ------------------------- |
|
|
33
|
-
| **Mais indicado para** | Workflows de agentes de IA
|
|
34
|
-
| **Modelo de ferramentas** | 274 ferramentas: 272 em toolsets + `execute_graphql` + `discover_tools` | ~50–60 ferramentas agrupadas `browse_*` / `manage_*` |
|
|
35
|
-
| **Revisão de MR** | Diff em lote em 2 etapas
|
|
36
|
-
| **Node.js** | >=18.17
|
|
37
|
-
| **Licença** | MIT
|
|
50
|
+
| | @zereight/mcp-gitlab | GitLab MCP A (comunidade, estilo CQRS) | Servidor MCP oficial do GitLab |
|
|
51
|
+
| ------------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| **Mais indicado para** | Workflows de agentes de IA | Múltiplas instâncias corporativas / ferramentas agrupadas | Integrado ao GitLab, sem instalação separada |
|
|
53
|
+
| **Modelo de ferramentas** | 274 ferramentas: 272 em toolsets + `execute_graphql` + `discover_tools` | ~50–60 ferramentas agrupadas `browse_*` / `manage_*` | Toolsets escolhidos por cabeçalho HTTP |
|
|
54
|
+
| **Revisão de MR** | Diff em lote em 2 etapas | Varia | `get_merge_request` com diffs |
|
|
55
|
+
| **Node.js** | >=18.17 | Frequentemente >=24 | Node.js 20+ para stdio via `mcp-remote` |
|
|
56
|
+
| **Licença** | MIT | Varia | Parte do GitLab |
|
|
57
|
+
|
|
58
|
+
[Comparação completa com o GitLab MCP A →](./docs/comparison/community-gitlab-mcp-a.md)
|
|
38
59
|
|
|
39
|
-
[
|
|
60
|
+
O GitLab também inclui um [servidor MCP oficial](https://docs.gitlab.com/user/model_context_protocol/mcp_server/).
|
|
61
|
+
|
|
62
|
+
- Free, Premium e Ultimate. Passou de Premium para Free no GitLab 19.2. Disponibilidade geral no GitLab 19.5.
|
|
63
|
+
- No GitLab.com, o Owner do grupo de nível superior permite o acesso ao servidor MCP. No GitLab Self-Managed e no GitLab Dedicated, um administrador controla a configuração da instância. As regras padrão estão na página oficial.
|
|
64
|
+
- Clientes remotos usam HTTP `https://<gitlab.example.com>/api/v4/mcp` com OAuth 2.0 dynamic client registration.
|
|
65
|
+
- O stdio passa por `mcp-remote` e exige Node.js 20 ou posterior.
|
|
66
|
+
- Os toolsets usam o cabeçalho `X-Gitlab-Enabled-Mcp-Server-Toolsets`. O cabeçalho opcional `X-Gitlab-Mcp-Server-Tool-Name-Prefix` mantém os primeiros 32 caracteres de um prefixo de nome de ferramenta.
|
|
40
67
|
|
|
41
68
|
Início rápido: escolha abaixo uma configuração com Personal Access Token ou OAuth2, instale `@zereight/mcp-gitlab` e use `zereight-mcp-gitlab` na configuração do seu cliente MCP.
|
|
42
69
|
|
|
@@ -63,7 +90,7 @@ O servidor suporta quatro métodos de autenticação.
|
|
|
63
90
|
|
|
64
91
|
**Para uso local/desktop** (mais comum):
|
|
65
92
|
|
|
66
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — configuração mais simples
|
|
93
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` ou `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — configuração mais simples
|
|
67
94
|
2. **OAuth2 — navegador local** (`GITLAB_USE_OAUTH`) — recomendado para maior segurança
|
|
68
95
|
|
|
69
96
|
**Para implantações em servidor/remotas**:
|
|
@@ -111,7 +138,7 @@ O caminho no store é fixado pelo seu lock file; atualize-o com `nix flake updat
|
|
|
111
138
|
|
|
112
139
|
Os exemplos usam `zereight-mcp-gitlab`, um alias com menor chance de conflito que o binário legado `mcp-gitlab`. Se o seu cliente MCP não o encontrar, use o caminho absoluto retornado por `which zereight-mcp-gitlab`.
|
|
113
140
|
|
|
114
|
-
Não quer instalar globalmente? Fixe o `npx` na versão estável anterior (a versão recomendada por esta documentação), por exemplo `npx -y @zereight/mcp-gitlab@2.2.
|
|
141
|
+
Não quer instalar globalmente? Fixe o `npx` na versão estável anterior (a versão recomendada por esta documentação), por exemplo `npx -y @zereight/mcp-gitlab@2.2.3`. Se quiser sempre a versão mais recente, use `npx -y @zereight/mcp-gitlab@latest`. O servidor exibe um aviso no stderr durante a inicialização quando existe uma versão mais nova disponível (desative com `GITLAB_DISABLE_VERSION_CHECK=true`).
|
|
115
142
|
|
|
116
143
|
#### Usando argumentos de CLI (para clientes com problemas com variáveis de ambiente)
|
|
117
144
|
|
|
@@ -177,10 +204,12 @@ O mesmo binário também é uma CLI do GitLab no estilo `gh` (`tool <name>` ou f
|
|
|
177
204
|
|
|
178
205
|
- sse
|
|
179
206
|
|
|
207
|
+
Passe só o nome da variável. O cliente Docker copia o `GITLAB_PERSONAL_ACCESS_TOKEN` exportado para o contêiner.
|
|
208
|
+
|
|
180
209
|
```shell
|
|
181
210
|
docker run -i --rm \
|
|
182
211
|
-e HOST=0.0.0.0 \
|
|
183
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
212
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
184
213
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
185
214
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
186
215
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/README.zh-CN.md
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
# GitLab MCP Server
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@zereight/mcp-gitlab)
|
|
4
|
-
[](vscode
|
|
4
|
+
[](https://vscode.dev/redirect/mcp/install?name=zereight.gitlab-mcp&config=%7B%22type%22%3A%22stdio%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40zereight%2Fmcp-gitlab%40latest%22%5D%2C%22env%22%3A%7B%22GITLAB_PERSONAL_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitlab-token%7D%22%2C%22GITLAB_API_URL%22%3A%22https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%22%2C%22GITLAB_PERMISSION_MODE%22%3A%22full%22%7D%7D)
|
|
5
|
+
[](https://cursor.com/en/install-mcp?name=zereight.gitlab-mcp&config=eyJ0eXBlIjoic3RkaW8iLCJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkB6ZXJlaWdodC9tY3AtZ2l0bGFiQGxhdGVzdCJdLCJlbnYiOnsiR0lUTEFCX1BFUlNPTkFMX0FDQ0VTU19UT0tFTiI6IiR7ZW52OkdJVExBQl9QRVJTT05BTF9BQ0NFU1NfVE9LRU59IiwiR0lUTEFCX0FQSV9VUkwiOiJodHRwczovL2dpdGxhYi5jb20vYXBpL3Y0IiwiR0lUTEFCX1BFUk1JU1NJT05fTU9ERSI6ImZ1bGwifX0%3D)
|
|
5
6
|
|
|
6
7
|
[English](./README.md) | [한국어](./README.ko.md) | [简体中文](./README.zh-CN.md) | [Português (Brasil)](./README.pt-BR.md)
|
|
7
8
|
|
|
8
9
|
📖 **[文档 →](https://zereight.github.io/gitlab-mcp/)** 设置指南、环境变量和完整工具参考请查看托管文档站点。
|
|
9
10
|
|
|
11
|
+
下面是 `@zereight/mcp-gitlab` 的推荐本地 PAT 安装。命令参数与 [Claude Code](./docs/clients/claude-code.md) 和 [Codex](./docs/clients/codex.md) 指南相同。
|
|
12
|
+
|
|
13
|
+
先安装 `zereight-mcp-gitlab` 二进制。`npm install -g @zereight/mcp-gitlab`,或 Homebrew `brew tap zereight/gitlab-mcp https://github.com/zereight/gitlab-mcp` 然后 `brew install zereight/gitlab-mcp/zereight-mcp-gitlab`。
|
|
14
|
+
|
|
15
|
+
先不回显地读取令牌,再 export。shell 历史里只保留变量名。
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
read -rs GITLAB_PERSONAL_ACCESS_TOKEN && export GITLAB_PERSONAL_ACCESS_TOKEN
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| 客户端 | 安装 |
|
|
22
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
23
|
+
| Claude Code | `claude mcp add gitlab --transport stdio --scope local --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
24
|
+
| Codex | `codex mcp add gitlab --env GITLAB_PERSONAL_ACCESS_TOKEN="$GITLAB_PERSONAL_ACCESS_TOKEN" --env GITLAB_API_URL=https://gitlab.com/api/v4 -- zereight-mcp-gitlab` |
|
|
25
|
+
| Cursor | [Cursor 设置指南](./docs/clients/cursor.md) |
|
|
26
|
+
| VS Code | [VS Code 设置指南](./docs/clients/vscode.md) |
|
|
27
|
+
| JSON 客户端 | [基于 JSON 的 MCP 客户端设置指南](./docs/clients/json-clients.md) |
|
|
28
|
+
|
|
10
29
|
[](https://www.star-history.com/?repos=zereight%2Fgitlab-mcp&type=date&legend=top-left)
|
|
11
30
|
|
|
12
31
|
## @zereight/mcp-gitlab
|
|
@@ -28,15 +47,23 @@
|
|
|
28
47
|
|
|
29
48
|
### 对比摘要
|
|
30
49
|
|
|
31
|
-
|
|
|
32
|
-
|
|
33
|
-
| **更适合**
|
|
34
|
-
| **工具模型** | 274 个工具:toolset 中 272 个 + `execute_graphql` + `discover_tools` | ~50–60 个 `browse_*` / `manage_*` 分组工具 |
|
|
35
|
-
| **MR 审查**
|
|
36
|
-
| **Node.js**
|
|
37
|
-
| **许可证**
|
|
50
|
+
| | @zereight/mcp-gitlab | GitLab MCP A(社区 CQRS 型) | GitLab 官方 MCP 服务器 |
|
|
51
|
+
| ------------ | -------------------------------------------------------------------- | ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| **更适合** | AI 代理工作流 | 企业多实例 / 分组工具 | 内置于 GitLab,无需单独安装 |
|
|
53
|
+
| **工具模型** | 274 个工具:toolset 中 272 个 + `execute_graphql` + `discover_tools` | ~50–60 个 `browse_*` / `manage_*` 分组工具 | 用 HTTP 头选择 toolset |
|
|
54
|
+
| **MR 审查** | 两步批量 diff | 因服务器而异 | `get_merge_request` 带 diffs |
|
|
55
|
+
| **Node.js** | >=18.17 | 通常 >=24 | stdio 经 `mcp-remote`,需要 Node.js 20+ |
|
|
56
|
+
| **许可证** | MIT | 因服务器而异 | GitLab 的一部分 |
|
|
57
|
+
|
|
58
|
+
[与 GitLab MCP A 的完整对比 →](./docs/comparison/community-gitlab-mcp-a.md)
|
|
38
59
|
|
|
39
|
-
[
|
|
60
|
+
GitLab 还提供[官方 MCP 服务器](https://docs.gitlab.com/user/model_context_protocol/mcp_server/)。
|
|
61
|
+
|
|
62
|
+
- Free、Premium、Ultimate。GitLab 19.2 从 Premium 移到 Free。GitLab 19.5 正式可用。
|
|
63
|
+
- 在 GitLab.com 上,顶级群组 Owner 允许访问 MCP 服务器。GitLab Self-Managed 和 GitLab Dedicated 使用实例设置。默认规则见官方页面。
|
|
64
|
+
- 远程客户端使用 HTTP `https://<gitlab.example.com>/api/v4/mcp` 和 OAuth 2.0 动态客户端注册。
|
|
65
|
+
- stdio 通过 `mcp-remote`,需要 Node.js 20 或更高版本。
|
|
66
|
+
- Toolset 使用请求头 `X-Gitlab-Enabled-Mcp-Server-Toolsets`。可选请求头 `X-Gitlab-Mcp-Server-Tool-Name-Prefix` 只保留工具名前缀的前 32 个字符。
|
|
40
67
|
|
|
41
68
|
快速开始:在下面选择 Personal Access Token 或 OAuth2 设置,安装 `@zereight/mcp-gitlab`,并在 MCP 客户端配置中使用 `zereight-mcp-gitlab`。
|
|
42
69
|
|
|
@@ -63,7 +90,7 @@
|
|
|
63
90
|
|
|
64
91
|
**本地/桌面使用**(最常见):
|
|
65
92
|
|
|
66
|
-
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN`) — 最简单的设置
|
|
93
|
+
1. **Personal Access Token** (`GITLAB_PERSONAL_ACCESS_TOKEN` 或 `GITLAB_PERSONAL_ACCESS_TOKEN_FILE`) — 最简单的设置
|
|
67
94
|
2. **OAuth2 — 本地浏览器** (`GITLAB_USE_OAUTH`) — 推荐用于更好的安全性
|
|
68
95
|
|
|
69
96
|
**服务器/远程部署**:
|
|
@@ -111,7 +138,7 @@ command = lib.getExe inputs.gitlab-mcp.packages.${system}.default;
|
|
|
111
138
|
|
|
112
139
|
示例使用 `zereight-mcp-gitlab`,这是比旧的 `mcp-gitlab` 更不容易冲突的别名。如果 MCP 客户端找不到它,请使用 `which zereight-mcp-gitlab` 输出的绝对路径。
|
|
113
140
|
|
|
114
|
-
如果不想全局安装,请将 `npx` 固定到上一个稳定版本(即文档推荐的版本),例如 `npx -y @zereight/mcp-gitlab@2.2.
|
|
141
|
+
如果不想全局安装,请将 `npx` 固定到上一个稳定版本(即文档推荐的版本),例如 `npx -y @zereight/mcp-gitlab@2.2.3`。如果始终想使用最新版本,请改用 `npx -y @zereight/mcp-gitlab@latest`。有新版本发布时,服务器会在启动时通过 stderr 提示(可用 `GITLAB_DISABLE_VERSION_CHECK=true` 关闭)。
|
|
115
142
|
|
|
116
143
|
#### 使用 CLI 参数(适用于环境变量有问题的客户端)
|
|
117
144
|
|
|
@@ -176,10 +203,12 @@ CLI 参数优先于环境变量。
|
|
|
176
203
|
|
|
177
204
|
- sse
|
|
178
205
|
|
|
206
|
+
只传变量名。Docker 客户端把已 export 的 `GITLAB_PERSONAL_ACCESS_TOKEN` 复制进容器。
|
|
207
|
+
|
|
179
208
|
```shell
|
|
180
209
|
docker run -i --rm \
|
|
181
210
|
-e HOST=0.0.0.0 \
|
|
182
|
-
-e GITLAB_PERSONAL_ACCESS_TOKEN
|
|
211
|
+
-e GITLAB_PERSONAL_ACCESS_TOKEN \
|
|
183
212
|
-e GITLAB_API_URL="https://gitlab.com/api/v4" \
|
|
184
213
|
-e GITLAB_PERMISSION_MODE=readonly \
|
|
185
214
|
-e GITLAB_TOOLSETS=core,wiki,milestones,pipelines \
|
package/build/config.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { parseCliArgs } from "./cli-boolean-flags.js";
|
|
2
2
|
import { deprecatedEnvInputFromSources } from "./deprecated-env.js";
|
|
3
|
+
import { readPersonalAccessTokenFile, resolvePersonalAccessToken, } from "./personal-access-token.js";
|
|
3
4
|
import { parseToolProfile } from "./tools/tool-profile.js";
|
|
4
5
|
import { parseCompactToolAllowlist } from "./utils/compact-tool-allowlist.js";
|
|
6
|
+
import { createLogger, flushStartupLogs } from "./utils/logger.js";
|
|
5
7
|
// Parse CLI arguments before anything else
|
|
6
8
|
export const cliArgs = parseCliArgs(process.argv.slice(2));
|
|
7
9
|
export function getConfig(cliKey, envKey, defaultValue) {
|
|
@@ -10,7 +12,19 @@ export function getConfig(cliKey, envKey, defaultValue) {
|
|
|
10
12
|
// ---------------------------------------------------------------------------
|
|
11
13
|
// Authentication
|
|
12
14
|
// ---------------------------------------------------------------------------
|
|
13
|
-
|
|
15
|
+
function warnIgnoredPersonalAccessTokenFile(message) {
|
|
16
|
+
const startupLogger = createLogger();
|
|
17
|
+
startupLogger.warn(message);
|
|
18
|
+
flushStartupLogs(startupLogger);
|
|
19
|
+
}
|
|
20
|
+
// Read once at module load. Later auth checks use this constant and do not reopen the file.
|
|
21
|
+
export const GITLAB_PERSONAL_ACCESS_TOKEN = resolvePersonalAccessToken({
|
|
22
|
+
cliToken: cliArgs.token,
|
|
23
|
+
envToken: process.env.GITLAB_PERSONAL_ACCESS_TOKEN,
|
|
24
|
+
filePath: process.env.GITLAB_PERSONAL_ACCESS_TOKEN_FILE,
|
|
25
|
+
readFile: readPersonalAccessTokenFile,
|
|
26
|
+
warn: warnIgnoredPersonalAccessTokenFile,
|
|
27
|
+
});
|
|
14
28
|
export const GITLAB_JOB_TOKEN = getConfig("job-token", "GITLAB_JOB_TOKEN");
|
|
15
29
|
export const GITLAB_AUTH_COOKIE_PATH = getConfig("cookie-path", "GITLAB_AUTH_COOKIE_PATH");
|
|
16
30
|
export const USE_OAUTH = getConfig("use-oauth", "GITLAB_USE_OAUTH") === "true";
|
package/build/index.js
CHANGED
|
@@ -743,7 +743,8 @@ function validateConfiguration() {
|
|
|
743
743
|
// Validate auth configuration
|
|
744
744
|
const remoteAuth = getConfig("remote-auth", "REMOTE_AUTHORIZATION") === "true";
|
|
745
745
|
const useOAuth = getConfig("use-oauth", "GITLAB_USE_OAUTH") === "true";
|
|
746
|
-
|
|
746
|
+
// getConfig() would ignore GITLAB_PERSONAL_ACCESS_TOKEN_FILE.
|
|
747
|
+
const hasToken = !!GITLAB_PERSONAL_ACCESS_TOKEN;
|
|
747
748
|
const hasJobToken = !!getConfig("job-token", "GITLAB_JOB_TOKEN");
|
|
748
749
|
const hasCookie = !!getConfig("cookie-path", "GITLAB_AUTH_COOKIE_PATH");
|
|
749
750
|
const mcpOAuth = getConfig("mcp-oauth", "GITLAB_MCP_OAUTH") === "true";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
const EMPTY_FILE_CODE = "EMPTY";
|
|
3
|
+
export class PersonalAccessTokenFileError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
filePath;
|
|
6
|
+
constructor(filePath, code) {
|
|
7
|
+
super(`Cannot load GITLAB_PERSONAL_ACCESS_TOKEN_FILE at ${filePath} (${code})`);
|
|
8
|
+
this.name = "PersonalAccessTokenFileError";
|
|
9
|
+
this.filePath = filePath;
|
|
10
|
+
this.code = code;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function presentInlineToken(value) {
|
|
14
|
+
if (value === undefined || value.length === 0) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function configuredFilePath(filePath) {
|
|
20
|
+
if (filePath === undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const trimmed = filePath.trim();
|
|
24
|
+
if (trimmed.length === 0) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return trimmed;
|
|
28
|
+
}
|
|
29
|
+
function errnoCode(error) {
|
|
30
|
+
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
31
|
+
return "EIO";
|
|
32
|
+
}
|
|
33
|
+
const code = error.code;
|
|
34
|
+
if (typeof code !== "string" || code.length === 0) {
|
|
35
|
+
return "EIO";
|
|
36
|
+
}
|
|
37
|
+
return code;
|
|
38
|
+
}
|
|
39
|
+
export function readPersonalAccessTokenFile(filePath) {
|
|
40
|
+
return readFileSync(filePath, { encoding: "utf8" });
|
|
41
|
+
}
|
|
42
|
+
function ignoredFileWarning(filePath) {
|
|
43
|
+
return `Ignoring GITLAB_PERSONAL_ACCESS_TOKEN_FILE at ${filePath} because an inline personal access token is set`;
|
|
44
|
+
}
|
|
45
|
+
function readTokenFile(source, filePath) {
|
|
46
|
+
try {
|
|
47
|
+
return source.readFile(filePath);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new PersonalAccessTokenFileError(filePath, errnoCode(error));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the personal access token once.
|
|
55
|
+
* `--token` wins, then a non-empty GITLAB_PERSONAL_ACCESS_TOKEN, then the file.
|
|
56
|
+
* Job tokens, OAuth, cookies, and remote authorization are not inputs.
|
|
57
|
+
*/
|
|
58
|
+
export function resolvePersonalAccessToken(source) {
|
|
59
|
+
const inline = presentInlineToken(source.cliToken) ?? presentInlineToken(source.envToken);
|
|
60
|
+
const filePath = configuredFilePath(source.filePath);
|
|
61
|
+
if (inline !== undefined) {
|
|
62
|
+
if (filePath !== undefined) {
|
|
63
|
+
source.warn(ignoredFileWarning(filePath));
|
|
64
|
+
}
|
|
65
|
+
return inline;
|
|
66
|
+
}
|
|
67
|
+
if (filePath === undefined) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const token = readTokenFile(source, filePath).trim();
|
|
71
|
+
if (token.length === 0) {
|
|
72
|
+
throw new PersonalAccessTokenFileError(filePath, EMPTY_FILE_CODE);
|
|
73
|
+
}
|
|
74
|
+
return token;
|
|
75
|
+
}
|
package/package.json
CHANGED