@zereight/mcp-gitlab 2.1.70 → 2.2.1

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.
Files changed (158) hide show
  1. package/README.ko.md +9 -5
  2. package/README.md +15 -11
  3. package/README.pt-BR.md +9 -5
  4. package/README.zh-CN.md +9 -5
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +63 -0
  7. package/build/index.js +430 -200
  8. package/build/oauth-device-flow.js +80 -0
  9. package/build/oauth.js +135 -18
  10. package/build/schemas.js +1 -1
  11. package/build/server/remote-http-stack.js +39 -0
  12. package/build/tools/discover-activation.js +38 -0
  13. package/build/tools/exposed-tools.js +35 -0
  14. package/build/tools/listed-tools.js +76 -0
  15. package/build/tools/registry.js +232 -63
  16. package/build/tools/tool-descriptions.js +3 -3
  17. package/build/tools/tool-profile.js +66 -0
  18. package/build/utils/compact-tool-allowlist.js +14 -0
  19. package/build/utils/logger.js +34 -12
  20. package/package.json +3 -3
  21. package/build/scripts/check-skill-sync.js +0 -143
  22. package/build/scripts/generate-server-card.js +0 -39
  23. package/build/scripts/generate-tool-coverage.js +0 -58
  24. package/build/scripts/generate-tool-docs.js +0 -430
  25. package/build/scripts/tool-coverage/coverage.js +0 -341
  26. package/build/scripts/tool-coverage/coverage.test.js +0 -142
  27. package/build/test/callback-proxy-tests.js +0 -321
  28. package/build/test/cli/args.test.js +0 -175
  29. package/build/test/cli/boolean-flags.test.js +0 -106
  30. package/build/test/cli/compact-mcp-result.test.js +0 -93
  31. package/build/test/cli/credentials.test.js +0 -153
  32. package/build/test/cli/exposure.test.js +0 -104
  33. package/build/test/cli/load-config-snapshot.js +0 -5
  34. package/build/test/cli/output.test.js +0 -74
  35. package/build/test/cli/replay-command.test.js +0 -37
  36. package/build/test/cli/router.test.js +0 -183
  37. package/build/test/client-pool-test.js +0 -109
  38. package/build/test/clients/client.js +0 -34
  39. package/build/test/clients/custom-header-client.js +0 -122
  40. package/build/test/clients/sse-client.js +0 -95
  41. package/build/test/clients/stdio-client.js +0 -113
  42. package/build/test/clients/streamable-http-client.js +0 -95
  43. package/build/test/config-allowed-groups.test.js +0 -97
  44. package/build/test/create-commit-actions.test.js +0 -102
  45. package/build/test/draft-note-schema.test.js +0 -44
  46. package/build/test/dynamic-api-url-allowlist.test.js +0 -121
  47. package/build/test/dynamic-api-url-test.js +0 -304
  48. package/build/test/dynamic-routing-tests.js +0 -495
  49. package/build/test/get-merge-request-discussion-schema.test.js +0 -30
  50. package/build/test/gitlab-api-tool-errors.test.js +0 -112
  51. package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
  52. package/build/test/gitlab-diff-schema.test.js +0 -36
  53. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  54. package/build/test/gitlab-tag-schema.test.js +0 -51
  55. package/build/test/group-milestone-schema.test.js +0 -45
  56. package/build/test/mcp-oauth-tests.js +0 -905
  57. package/build/test/mcp-server-name.test.js +0 -87
  58. package/build/test/merge-merge-request-schema.test.js +0 -75
  59. package/build/test/multi-server-test.js +0 -190
  60. package/build/test/no-proxy-integration-test.js +0 -183
  61. package/build/test/no-proxy-test.js +0 -149
  62. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  63. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  64. package/build/test/oauth-device-flow-tests.js +0 -450
  65. package/build/test/oauth-download-url.test.js +0 -157
  66. package/build/test/oauth-startup.test.js +0 -204
  67. package/build/test/oauth-tests.js +0 -428
  68. package/build/test/path-segment-encoding.test.js +0 -98
  69. package/build/test/remote-auth-simple-test.js +0 -277
  70. package/build/test/remote-auth-tests.js +0 -314
  71. package/build/test/response-masking.test.js +0 -445
  72. package/build/test/schema-tests.js +0 -1679
  73. package/build/test/server/metrics.test.js +0 -47
  74. package/build/test/server/request-helpers.test.js +0 -48
  75. package/build/test/server/version.test.js +0 -13
  76. package/build/test/sse-auth-guard.test.js +0 -96
  77. package/build/test/sse-session-limits.test.js +0 -273
  78. package/build/test/stateless/callback-proxy.test.js +0 -510
  79. package/build/test/stateless/client-id.test.js +0 -177
  80. package/build/test/stateless/codec.test.js +0 -328
  81. package/build/test/stateless/config-ttl.test.js +0 -149
  82. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  83. package/build/test/stateless/session-id-integration.test.js +0 -675
  84. package/build/test/stateless/session-id.test.js +0 -157
  85. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  86. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  87. package/build/test/streamable-http-sse-stream.test.js +0 -350
  88. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  89. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  90. package/build/test/test-all-transport-server.js +0 -255
  91. package/build/test/test-auth-retry.js +0 -195
  92. package/build/test/test-blank-filters.js +0 -156
  93. package/build/test/test-ci-catalog.js +0 -177
  94. package/build/test/test-ci-lint.js +0 -191
  95. package/build/test/test-ci-variables.js +0 -309
  96. package/build/test/test-create-repository.js +0 -120
  97. package/build/test/test-dependency-proxy.js +0 -195
  98. package/build/test/test-deployment-tools.js +0 -463
  99. package/build/test/test-download-attachment.js +0 -190
  100. package/build/test/test-dynamic-project-scope.js +0 -524
  101. package/build/test/test-empty-toolsets.js +0 -535
  102. package/build/test/test-get-file-blame.js +0 -145
  103. package/build/test/test-get-file-contents.js +0 -128
  104. package/build/test/test-geteffectiveprojectid.js +0 -804
  105. package/build/test/test-health-check.js +0 -115
  106. package/build/test/test-issue-description-patch.js +0 -256
  107. package/build/test/test-job-artifacts.js +0 -275
  108. package/build/test/test-json-schema.js +0 -166
  109. package/build/test/test-list-group-members.js +0 -150
  110. package/build/test/test-list-group-merge-requests.js +0 -165
  111. package/build/test/test-list-issues.js +0 -170
  112. package/build/test/test-list-merge-requests.js +0 -201
  113. package/build/test/test-list-milestones.js +0 -145
  114. package/build/test/test-list-project-members.js +0 -132
  115. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  116. package/build/test/test-merge-request-approvals.js +0 -187
  117. package/build/test/test-merge-request-pipelines.js +0 -106
  118. package/build/test/test-mr-diffs-filter.js +0 -132
  119. package/build/test/test-mr-file-diffs.js +0 -251
  120. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  121. package/build/test/test-orbit.js +0 -155
  122. package/build/test/test-permission-mode.js +0 -424
  123. package/build/test/test-pipeline-schedules.js +0 -484
  124. package/build/test/test-protected-branches.js +0 -174
  125. package/build/test/test-remote-downloads.js +0 -510
  126. package/build/test/test-search-code.js +0 -275
  127. package/build/test/test-snippets.js +0 -735
  128. package/build/test/test-tags.js +0 -220
  129. package/build/test/test-todos.js +0 -195
  130. package/build/test/test-token-optimizations.js +0 -691
  131. package/build/test/test-toolset-filtering.js +0 -499
  132. package/build/test/test-update-issue-slim.js +0 -141
  133. package/build/test/test-update-project.js +0 -112
  134. package/build/test/test-upload-markdown.js +0 -206
  135. package/build/test/test-vulnerabilities.js +0 -399
  136. package/build/test/test-webhooks.js +0 -218
  137. package/build/test/tool-description-quality.test.js +0 -50
  138. package/build/test/utils/bulk-publish-options.test.js +0 -32
  139. package/build/test/utils/download-token.test.js +0 -35
  140. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  141. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  142. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  143. package/build/test/utils/graphql-query.test.js +0 -168
  144. package/build/test/utils/helpers-path.test.js +0 -104
  145. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  146. package/build/test/utils/masking.test.js +0 -384
  147. package/build/test/utils/merge-request-position.test.js +0 -57
  148. package/build/test/utils/mock-gitlab-server.js +0 -614
  149. package/build/test/utils/proxy-client-ip.test.js +0 -28
  150. package/build/test/utils/redact-sensitive.test.js +0 -32
  151. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  152. package/build/test/utils/server-launcher.js +0 -231
  153. package/build/test/utils/tool-args.test.js +0 -210
  154. package/build/test/utils/url.test.js +0 -141
  155. package/build/test/utils/version-check.test.js +0 -239
  156. package/build/test/utils/wiki-title.test.js +0 -21
  157. package/build/test-note.js +0 -54
  158. package/build/test-resolve-issue-note.js +0 -127
@@ -1,309 +0,0 @@
1
- import { describe, test, before, after } from "node:test";
2
- import assert from "node:assert";
3
- import { spawn } from "child_process";
4
- import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
5
- const MOCK_TOKEN = "glpat-mock-token-ci-variables";
6
- const TEST_PROJECT_ID = "123";
7
- const TEST_GROUP_ID = "my-group";
8
- const TEST_VAR_KEY = "DB_URL";
9
- const TEST_GROUP_VAR_KEY = "SHARED_SECRET";
10
- const TEST_HIDDEN_VAR_KEY = "HIDDEN_VAR";
11
- const TEST_SCOPE = "production";
12
- const MOCK_PROJECT_VARIABLE = {
13
- variable_type: "env_var",
14
- key: TEST_VAR_KEY,
15
- value: "postgres://localhost/db",
16
- protected: false,
17
- masked: true,
18
- raw: false,
19
- environment_scope: "*",
20
- description: "Database connection URL",
21
- };
22
- const MOCK_GROUP_VARIABLE = {
23
- variable_type: "env_var",
24
- key: TEST_GROUP_VAR_KEY,
25
- value: "s3cr3t",
26
- protected: false,
27
- masked: true,
28
- raw: false,
29
- environment_scope: "*",
30
- description: null,
31
- };
32
- const MOCK_HIDDEN_PROJECT_VARIABLE = {
33
- ...MOCK_PROJECT_VARIABLE,
34
- key: TEST_HIDDEN_VAR_KEY,
35
- value: null,
36
- hidden: true,
37
- description: null,
38
- };
39
- async function callTool(toolName, args, env) {
40
- return new Promise((resolve, reject) => {
41
- const proc = spawn("node", ["build/index.js"], {
42
- stdio: ["pipe", "pipe", "pipe"],
43
- env: { ...process.env, ...env },
44
- });
45
- let output = "";
46
- let errorOutput = "";
47
- proc.stdout?.on("data", (d) => (output += d));
48
- proc.stderr?.on("data", (d) => (errorOutput += d));
49
- proc.on("close", code => {
50
- if (code !== 0) {
51
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
52
- }
53
- const line = output.split("\n").find(l => l.startsWith("{"));
54
- if (!line)
55
- return reject(new Error("No JSON output found"));
56
- try {
57
- const response = JSON.parse(line);
58
- if (response.error) {
59
- reject(new Error(response.error?.message ?? String(response.error)));
60
- }
61
- else {
62
- const content = response.result?.content?.[0]?.text;
63
- resolve(content ? JSON.parse(content) : response.result);
64
- }
65
- }
66
- catch (e) {
67
- reject(e);
68
- }
69
- });
70
- proc.stdin?.end(JSON.stringify({
71
- jsonrpc: "2.0",
72
- id: 1,
73
- method: "tools/call",
74
- params: { name: toolName, arguments: args },
75
- }) + "\n");
76
- });
77
- }
78
- describe("CI/CD variable tools", () => {
79
- let mockServer;
80
- let mockApiUrl;
81
- let baseEnv;
82
- let lastReceivedFilterScope;
83
- before(async () => {
84
- mockServer = new MockGitLabServer({
85
- port: await findMockServerPort(),
86
- validTokens: [MOCK_TOKEN],
87
- });
88
- // --- Project variable endpoints ---
89
- mockServer.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/variables`, (_req, res) => {
90
- res.json([MOCK_PROJECT_VARIABLE]);
91
- });
92
- mockServer.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/variables/${TEST_VAR_KEY}`, (req, res) => {
93
- const scope = req.query["filter[environment_scope]"];
94
- lastReceivedFilterScope = scope;
95
- res.json({ ...MOCK_PROJECT_VARIABLE, environment_scope: scope ?? "*" });
96
- });
97
- mockServer.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/variables/${TEST_HIDDEN_VAR_KEY}`, (_req, res) => {
98
- res.json(MOCK_HIDDEN_PROJECT_VARIABLE);
99
- });
100
- mockServer.addMockHandler("post", `/projects/${TEST_PROJECT_ID}/variables`, (req, res) => {
101
- res.status(201).json({ ...MOCK_PROJECT_VARIABLE, ...req.body });
102
- });
103
- mockServer.addMockHandler("put", `/projects/${TEST_PROJECT_ID}/variables/${TEST_VAR_KEY}`, (req, res) => {
104
- const scope = req.query["filter[environment_scope]"];
105
- lastReceivedFilterScope = scope;
106
- res.json({ ...MOCK_PROJECT_VARIABLE, ...req.body, environment_scope: scope ?? "*" });
107
- });
108
- mockServer.addMockHandler("delete", `/projects/${TEST_PROJECT_ID}/variables/${TEST_VAR_KEY}`, (req, res) => {
109
- lastReceivedFilterScope = req.query["filter[environment_scope]"];
110
- res.status(204).send();
111
- });
112
- // --- Group variable endpoints ---
113
- mockServer.addMockHandler("get", `/groups/${TEST_GROUP_ID}/variables`, (_req, res) => {
114
- res.json([MOCK_GROUP_VARIABLE]);
115
- });
116
- mockServer.addMockHandler("get", `/groups/${TEST_GROUP_ID}/variables/${TEST_GROUP_VAR_KEY}`, (_req, res) => {
117
- res.json(MOCK_GROUP_VARIABLE);
118
- });
119
- mockServer.addMockHandler("post", `/groups/${TEST_GROUP_ID}/variables`, (req, res) => {
120
- res.status(201).json({ ...MOCK_GROUP_VARIABLE, ...req.body });
121
- });
122
- mockServer.addMockHandler("put", `/groups/${TEST_GROUP_ID}/variables/${TEST_GROUP_VAR_KEY}`, (req, res) => {
123
- res.json({ ...MOCK_GROUP_VARIABLE, ...req.body });
124
- });
125
- mockServer.addMockHandler("delete", `/groups/${TEST_GROUP_ID}/variables/${TEST_GROUP_VAR_KEY}`, (_req, res) => {
126
- res.status(204).send();
127
- });
128
- await mockServer.start();
129
- mockApiUrl = `${mockServer.getUrl()}/api/v4`;
130
- baseEnv = {
131
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
132
- GITLAB_API_URL: mockApiUrl,
133
- GITLAB_TOOLSETS: "variables",
134
- };
135
- });
136
- after(async () => {
137
- await mockServer.stop();
138
- });
139
- // --- Project variable tests ---
140
- test("list_project_variables returns variable array", async () => {
141
- const result = await callTool("list_project_variables", { project_id: TEST_PROJECT_ID }, baseEnv);
142
- assert.ok(Array.isArray(result));
143
- assert.strictEqual(result.length, 1);
144
- assert.strictEqual(result[0].key, TEST_VAR_KEY);
145
- assert.strictEqual(result[0].value, MOCK_PROJECT_VARIABLE.value);
146
- assert.strictEqual(result[0].masked, true);
147
- });
148
- test("get_project_variable returns single variable", async () => {
149
- const result = await callTool("get_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY }, baseEnv);
150
- assert.strictEqual(result.key, TEST_VAR_KEY);
151
- assert.strictEqual(result.environment_scope, "*");
152
- assert.strictEqual(result.variable_type, "env_var");
153
- });
154
- test("get_project_variable returns hidden variable with null value", async () => {
155
- const result = await callTool("get_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_HIDDEN_VAR_KEY }, baseEnv);
156
- assert.strictEqual(result.key, TEST_HIDDEN_VAR_KEY);
157
- assert.strictEqual(result.value, null);
158
- assert.strictEqual(result.hidden, true);
159
- });
160
- test("create_project_variable returns created variable", async () => {
161
- const result = await callTool("create_project_variable", {
162
- project_id: TEST_PROJECT_ID,
163
- key: TEST_VAR_KEY,
164
- value: "new-value",
165
- masked: true,
166
- }, baseEnv);
167
- assert.strictEqual(result.key, TEST_VAR_KEY);
168
- assert.strictEqual(result.value, "new-value");
169
- });
170
- test("update_project_variable returns updated variable", async () => {
171
- const result = await callTool("update_project_variable", {
172
- project_id: TEST_PROJECT_ID,
173
- key: TEST_VAR_KEY,
174
- value: "updated-value",
175
- }, baseEnv);
176
- assert.strictEqual(result.value, "updated-value");
177
- });
178
- test("delete_project_variable returns success status", async () => {
179
- const result = await callTool("delete_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY }, baseEnv);
180
- assert.strictEqual(result.status, "success");
181
- assert.ok(result.message.includes(TEST_VAR_KEY));
182
- });
183
- // --- Group variable tests ---
184
- test("list_group_variables returns variable array", async () => {
185
- const result = await callTool("list_group_variables", { group_id: TEST_GROUP_ID }, baseEnv);
186
- assert.ok(Array.isArray(result));
187
- assert.strictEqual(result.length, 1);
188
- assert.strictEqual(result[0].key, TEST_GROUP_VAR_KEY);
189
- assert.strictEqual(result[0].masked, true);
190
- });
191
- test("get_group_variable returns single variable", async () => {
192
- const result = await callTool("get_group_variable", { group_id: TEST_GROUP_ID, key: TEST_GROUP_VAR_KEY }, baseEnv);
193
- assert.strictEqual(result.key, TEST_GROUP_VAR_KEY);
194
- assert.strictEqual(result.variable_type, "env_var");
195
- });
196
- test("create_group_variable returns created variable", async () => {
197
- const result = await callTool("create_group_variable", {
198
- group_id: TEST_GROUP_ID,
199
- key: TEST_GROUP_VAR_KEY,
200
- value: "new-secret",
201
- masked: true,
202
- }, baseEnv);
203
- assert.strictEqual(result.key, TEST_GROUP_VAR_KEY);
204
- assert.strictEqual(result.value, "new-secret");
205
- });
206
- test("update_group_variable returns updated variable", async () => {
207
- const result = await callTool("update_group_variable", {
208
- group_id: TEST_GROUP_ID,
209
- key: TEST_GROUP_VAR_KEY,
210
- value: "updated-secret",
211
- }, baseEnv);
212
- assert.strictEqual(result.value, "updated-secret");
213
- });
214
- test("delete_group_variable returns success status", async () => {
215
- const result = await callTool("delete_group_variable", { group_id: TEST_GROUP_ID, key: TEST_GROUP_VAR_KEY }, baseEnv);
216
- assert.strictEqual(result.status, "success");
217
- assert.ok(result.message.includes(TEST_GROUP_VAR_KEY));
218
- });
219
- // --- filter[environment_scope] tests ---
220
- test("get_project_variable passes filter[environment_scope] to GitLab", async () => {
221
- lastReceivedFilterScope = undefined;
222
- const result = await callTool("get_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY, filter: { environment_scope: TEST_SCOPE } }, baseEnv);
223
- assert.strictEqual(lastReceivedFilterScope, TEST_SCOPE);
224
- assert.strictEqual(result.environment_scope, TEST_SCOPE);
225
- });
226
- test("update_project_variable passes filter[environment_scope] to GitLab", async () => {
227
- lastReceivedFilterScope = undefined;
228
- const result = await callTool("update_project_variable", {
229
- project_id: TEST_PROJECT_ID,
230
- key: TEST_VAR_KEY,
231
- value: "scoped-value",
232
- filter: { environment_scope: TEST_SCOPE },
233
- }, baseEnv);
234
- assert.strictEqual(lastReceivedFilterScope, TEST_SCOPE);
235
- assert.strictEqual(result.environment_scope, TEST_SCOPE);
236
- });
237
- test("delete_project_variable passes filter[environment_scope] to GitLab", async () => {
238
- lastReceivedFilterScope = undefined;
239
- const result = await callTool("delete_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY, filter: { environment_scope: TEST_SCOPE } }, baseEnv);
240
- assert.strictEqual(lastReceivedFilterScope, TEST_SCOPE);
241
- assert.strictEqual(result.status, "success");
242
- });
243
- // --- Toolset behaviour ---
244
- test("variables tools are absent when toolset is not activated", async () => {
245
- return new Promise((resolve, reject) => {
246
- const proc = spawn("node", ["build/index.js"], {
247
- stdio: ["pipe", "pipe", "pipe"],
248
- env: {
249
- ...process.env,
250
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
251
- GITLAB_API_URL: mockApiUrl,
252
- // No GITLAB_TOOLSETS — default toolsets only
253
- },
254
- });
255
- let output = "";
256
- proc.stdout?.on("data", (d) => (output += d));
257
- proc.on("close", () => {
258
- try {
259
- const line = output.split("\n").find(l => l.startsWith("{"));
260
- if (!line)
261
- return reject(new Error("No JSON output found"));
262
- const response = JSON.parse(line);
263
- const names = (response.result?.tools ?? []).map((t) => t.name);
264
- assert.ok(!names.includes("list_project_variables"), "tool should not be in default toolset");
265
- assert.ok(!names.includes("create_project_variable"), "tool should not be in default toolset");
266
- assert.ok(!names.includes("list_group_variables"), "tool should not be in default toolset");
267
- resolve();
268
- }
269
- catch (e) {
270
- reject(e);
271
- }
272
- });
273
- proc.stdin?.end(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }) + "\n");
274
- });
275
- });
276
- test("write tools are absent from tools/list in read-only mode", async () => {
277
- return new Promise((resolve, reject) => {
278
- const proc = spawn("node", ["build/index.js"], {
279
- stdio: ["pipe", "pipe", "pipe"],
280
- env: { ...process.env, ...baseEnv, GITLAB_READ_ONLY_MODE: "true" },
281
- });
282
- let output = "";
283
- proc.stdout?.on("data", (d) => (output += d));
284
- proc.on("close", () => {
285
- try {
286
- const line = output.split("\n").find(l => l.startsWith("{"));
287
- if (!line)
288
- return reject(new Error("No JSON output found"));
289
- const response = JSON.parse(line);
290
- const names = (response.result?.tools ?? []).map((t) => t.name);
291
- assert.ok(!names.includes("create_project_variable"), "create should be absent in read-only mode");
292
- assert.ok(!names.includes("update_project_variable"), "update should be absent in read-only mode");
293
- assert.ok(!names.includes("delete_project_variable"), "delete should be absent in read-only mode");
294
- assert.ok(!names.includes("create_group_variable"), "create should be absent in read-only mode");
295
- assert.ok(!names.includes("delete_group_variable"), "delete should be absent in read-only mode");
296
- assert.ok(names.includes("list_project_variables"), "list should be present in read-only mode");
297
- assert.ok(names.includes("get_project_variable"), "get should be present in read-only mode");
298
- assert.ok(names.includes("list_group_variables"), "list should be present in read-only mode");
299
- assert.ok(names.includes("get_group_variable"), "get should be present in read-only mode");
300
- resolve();
301
- }
302
- catch (e) {
303
- reject(e);
304
- }
305
- });
306
- proc.stdin?.end(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }) + "\n");
307
- });
308
- });
309
- });
@@ -1,120 +0,0 @@
1
- import { describe, test } from "node:test";
2
- import assert from "node:assert";
3
- import { spawn } from "child_process";
4
- import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
5
- const MOCK_TOKEN = "mock-token-create-repository";
6
- const TEST_NAMESPACE_ID = 6;
7
- const MOCK_CREATED_PROJECT = {
8
- id: "99",
9
- name: "my-docs",
10
- path_with_namespace: "my-group/my-docs",
11
- description: null,
12
- visibility: "private",
13
- };
14
- async function callCreateRepository(args, env) {
15
- return new Promise((resolve, reject) => {
16
- const proc = spawn("node", ["build/index.js"], {
17
- stdio: ["pipe", "pipe", "pipe"],
18
- env: { ...process.env, ...env },
19
- });
20
- let output = "";
21
- let errorOutput = "";
22
- proc.stdout?.on("data", (d) => (output += d));
23
- proc.stderr?.on("data", (d) => (errorOutput += d));
24
- proc.on("close", code => {
25
- if (code !== 0) {
26
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
27
- }
28
- const line = output.split("\n").find(l => l.startsWith("{"));
29
- if (!line)
30
- return reject(new Error("No JSON output found"));
31
- try {
32
- const response = JSON.parse(line);
33
- if (response.error) {
34
- reject(new Error(response.error?.message ?? String(response.error)));
35
- }
36
- else {
37
- const content = response.result?.content?.[0]?.text;
38
- resolve(content ? JSON.parse(content) : response.result);
39
- }
40
- }
41
- catch (e) {
42
- reject(e);
43
- }
44
- });
45
- proc.stdin?.end(JSON.stringify({
46
- jsonrpc: "2.0",
47
- id: 1,
48
- method: "tools/call",
49
- params: { name: "create_repository", arguments: args },
50
- }) + "\n");
51
- });
52
- }
53
- describe("When create_repository is called", () => {
54
- describe("with namespace_id", () => {
55
- test("should forward namespace_id in POST /projects body", async () => {
56
- const mockPort = await findMockServerPort();
57
- const mockServer = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
58
- let receivedBody;
59
- mockServer.addMockHandler("post", "/projects", (req, res) => {
60
- receivedBody = req.body;
61
- res.status(201).json(MOCK_CREATED_PROJECT);
62
- });
63
- await mockServer.start();
64
- try {
65
- const result = await callCreateRepository({ name: "my-docs", namespace_id: TEST_NAMESPACE_ID }, {
66
- GITLAB_API_URL: `${mockServer.getUrl()}/api/v4`,
67
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
68
- });
69
- assert.deepStrictEqual(receivedBody?.namespace_id, TEST_NAMESPACE_ID);
70
- assert.strictEqual(result.name, "my-docs");
71
- }
72
- finally {
73
- await mockServer.stop();
74
- }
75
- });
76
- test("should accept string namespace_id from list_namespaces", async () => {
77
- const mockPort = await findMockServerPort();
78
- const mockServer = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
79
- let receivedBody;
80
- mockServer.addMockHandler("post", "/projects", (req, res) => {
81
- receivedBody = req.body;
82
- res.status(201).json(MOCK_CREATED_PROJECT);
83
- });
84
- await mockServer.start();
85
- try {
86
- await callCreateRepository({ name: "my-docs", namespace_id: String(TEST_NAMESPACE_ID) }, {
87
- GITLAB_API_URL: `${mockServer.getUrl()}/api/v4`,
88
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
89
- });
90
- assert.deepStrictEqual(receivedBody?.namespace_id, TEST_NAMESPACE_ID);
91
- }
92
- finally {
93
- await mockServer.stop();
94
- }
95
- });
96
- });
97
- describe("without namespace_id", () => {
98
- test("should omit namespace_id from POST /projects body", async () => {
99
- const mockPort = await findMockServerPort();
100
- const mockServer = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
101
- let receivedBody;
102
- mockServer.addMockHandler("post", "/projects", (req, res) => {
103
- receivedBody = req.body;
104
- res.status(201).json(MOCK_CREATED_PROJECT);
105
- });
106
- await mockServer.start();
107
- try {
108
- await callCreateRepository({ name: "my-docs" }, {
109
- GITLAB_API_URL: `${mockServer.getUrl()}/api/v4`,
110
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
111
- });
112
- assert.ok(receivedBody);
113
- assert.ok(!Object.hasOwn(receivedBody, "namespace_id"));
114
- }
115
- finally {
116
- await mockServer.stop();
117
- }
118
- });
119
- });
120
- });
@@ -1,195 +0,0 @@
1
- import { describe, test, before, after } from "node:test";
2
- import assert from "node:assert";
3
- import { spawn } from "child_process";
4
- import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
5
- const MOCK_TOKEN = "glpat-mock-token-dependency-proxy";
6
- const TEST_GROUP_PATH = "my-group";
7
- async function callTool(toolName, args, env) {
8
- return new Promise((resolve, reject) => {
9
- const proc = spawn("node", ["build/index.js"], {
10
- stdio: ["pipe", "pipe", "pipe"],
11
- env: { ...process.env, ...env },
12
- });
13
- let output = "";
14
- let errorOutput = "";
15
- proc.stdout?.on("data", (d) => (output += d));
16
- proc.stderr?.on("data", (d) => (errorOutput += d));
17
- proc.on("close", code => {
18
- if (code !== 0) {
19
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
20
- }
21
- const line = output.split("\n").find(l => l.startsWith("{"));
22
- if (!line)
23
- return reject(new Error("No JSON output found"));
24
- try {
25
- const response = JSON.parse(line);
26
- if (response.error) {
27
- reject(new Error(response.error?.message ?? String(response.error)));
28
- }
29
- else {
30
- const content = response.result?.content?.[0]?.text;
31
- resolve(content ? JSON.parse(content) : response.result);
32
- }
33
- }
34
- catch (e) {
35
- reject(e);
36
- }
37
- });
38
- proc.stdin?.end(JSON.stringify({
39
- jsonrpc: "2.0",
40
- id: 1,
41
- method: "tools/call",
42
- params: { name: toolName, arguments: args },
43
- }) + "\n");
44
- });
45
- }
46
- describe("dependency proxy tools", () => {
47
- let mockServer;
48
- let mockApiUrl;
49
- let baseEnv;
50
- before(async () => {
51
- mockServer = new MockGitLabServer({
52
- port: await findMockServerPort(),
53
- validTokens: [MOCK_TOKEN],
54
- });
55
- await mockServer.start();
56
- const mockHost = new URL(mockServer.getUrl()).host;
57
- mockApiUrl = `${mockServer.getUrl()}/api/v4`;
58
- // Mock GraphQL endpoint for get/list operations
59
- mockServer.addRootHandler("post", "/api/graphql", (req, res) => {
60
- const { query } = req.body;
61
- if (query.includes("updateDependencyProxySettings")) {
62
- res.json({ data: { updateDependencyProxySettings: { errors: [] } } });
63
- }
64
- else if (query.includes("dependencyProxySetting")) {
65
- res.json({
66
- data: {
67
- group: {
68
- dependencyProxySetting: { enabled: true },
69
- dependencyProxyBlobCount: 3,
70
- dependencyProxyTotalSize: "15728640",
71
- dependencyProxyImagePrefix: `${mockHost}/my-group/dependency_proxy/containers`,
72
- dependencyProxyImageTtlPolicy: { enabled: true, ttl: 90 },
73
- },
74
- },
75
- });
76
- }
77
- else if (query.includes("dependencyProxyBlobs")) {
78
- res.json({
79
- data: {
80
- group: {
81
- dependencyProxyBlobs: {
82
- nodes: [
83
- { fileName: "sha256:abc123", size: "5 MiB", createdAt: "2026-01-01T00:00:00Z" },
84
- { fileName: "sha256:def456", size: "10 MiB", createdAt: "2026-01-02T00:00:00Z" },
85
- ],
86
- pageInfo: { hasNextPage: false, endCursor: null },
87
- },
88
- },
89
- },
90
- });
91
- }
92
- else {
93
- res.status(400).json({ errors: [{ message: "Unexpected GraphQL query" }] });
94
- }
95
- });
96
- // Mock REST endpoint for purge
97
- mockServer.addMockHandler("delete", `/groups/${TEST_GROUP_PATH}/dependency_proxy/cache`, (_req, res) => {
98
- res.status(202).send();
99
- });
100
- baseEnv = {
101
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
102
- GITLAB_API_URL: mockApiUrl,
103
- GITLAB_TOOLSETS: "dependency_proxy",
104
- };
105
- });
106
- after(async () => {
107
- await mockServer.stop();
108
- });
109
- test("get_dependency_proxy_settings returns enabled status and blob info", async () => {
110
- const result = await callTool("get_dependency_proxy_settings", { group_id: TEST_GROUP_PATH }, baseEnv);
111
- assert.strictEqual(result.enabled, true);
112
- assert.strictEqual(result.blob_count, 3);
113
- assert.strictEqual(result.total_size, "15728640");
114
- assert.ok(result.ttl_policy?.enabled);
115
- });
116
- test("list_dependency_proxy_blobs returns blobs with string sizes", async () => {
117
- const result = await callTool("list_dependency_proxy_blobs", { group_id: TEST_GROUP_PATH }, baseEnv);
118
- assert.ok(Array.isArray(result.blobs));
119
- assert.strictEqual(result.blobs.length, 2);
120
- assert.strictEqual(typeof result.blobs[0].size, "string");
121
- assert.strictEqual(result.blobs[0].file_name, "sha256:abc123");
122
- });
123
- test("purge_dependency_proxy_cache returns scheduled status", async () => {
124
- const result = await callTool("purge_dependency_proxy_cache", { group_id: TEST_GROUP_PATH }, baseEnv);
125
- assert.strictEqual(result.status, "success");
126
- assert.ok(result.message.includes("scheduled"));
127
- });
128
- test("update_dependency_proxy_settings enables the proxy and returns settings", async () => {
129
- const result = await callTool("update_dependency_proxy_settings", { group_id: TEST_GROUP_PATH, enabled: true }, baseEnv);
130
- assert.strictEqual(result.enabled, true);
131
- });
132
- test("update_dependency_proxy_settings rejects empty options", async () => {
133
- await assert.rejects(() => callTool("update_dependency_proxy_settings", { group_id: TEST_GROUP_PATH }, baseEnv), /At least one of enabled, identity, or secret must be provided/);
134
- });
135
- test("dependency_proxy tools are absent when toolset is not activated", async () => {
136
- return new Promise((resolve, reject) => {
137
- const proc = spawn("node", ["build/index.js"], {
138
- stdio: ["pipe", "pipe", "pipe"],
139
- env: {
140
- ...process.env,
141
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
142
- GITLAB_API_URL: mockApiUrl,
143
- // No GITLAB_TOOLSETS — default toolsets only
144
- },
145
- });
146
- let output = "";
147
- proc.stdout?.on("data", (d) => (output += d));
148
- proc.on("close", () => {
149
- try {
150
- const line = output.split("\n").find(l => l.startsWith("{"));
151
- if (!line)
152
- return reject(new Error("No JSON output found"));
153
- const response = JSON.parse(line);
154
- const tools = response.result?.tools ?? [];
155
- const names = tools.map(t => t.name);
156
- assert.ok(!names.includes("get_dependency_proxy_settings"), "tool should not be in default toolset");
157
- assert.ok(!names.includes("purge_dependency_proxy_cache"), "tool should not be in default toolset");
158
- resolve();
159
- }
160
- catch (e) {
161
- reject(e);
162
- }
163
- });
164
- proc.stdin?.end(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }) + "\n");
165
- });
166
- });
167
- test("write tools are absent from tools/list in read-only mode", async () => {
168
- return new Promise((resolve, reject) => {
169
- const proc = spawn("node", ["build/index.js"], {
170
- stdio: ["pipe", "pipe", "pipe"],
171
- env: { ...process.env, ...baseEnv, GITLAB_READ_ONLY_MODE: "true" },
172
- });
173
- let output = "";
174
- proc.stdout?.on("data", (d) => (output += d));
175
- proc.on("close", () => {
176
- try {
177
- const line = output.split("\n").find(l => l.startsWith("{"));
178
- if (!line)
179
- return reject(new Error("No JSON output found"));
180
- const response = JSON.parse(line);
181
- const names = (response.result?.tools ?? []).map((t) => t.name);
182
- assert.ok(!names.includes("purge_dependency_proxy_cache"), "purge should be absent in read-only mode");
183
- assert.ok(!names.includes("update_dependency_proxy_settings"), "update should be absent in read-only mode");
184
- assert.ok(names.includes("get_dependency_proxy_settings"), "get should be present in read-only mode");
185
- assert.ok(names.includes("list_dependency_proxy_blobs"), "list should be present in read-only mode");
186
- resolve();
187
- }
188
- catch (e) {
189
- reject(e);
190
- }
191
- });
192
- proc.stdin?.end(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }) + "\n");
193
- });
194
- });
195
- });