@zereight/mcp-gitlab 2.1.69 → 2.2.0

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 (155) hide show
  1. package/README.ko.md +10 -4
  2. package/README.md +238 -233
  3. package/README.pt-BR.md +4 -4
  4. package/README.zh-CN.md +6 -4
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +47 -0
  7. package/build/index.js +456 -237
  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 +226 -57
  16. package/build/tools/tool-profile.js +66 -0
  17. package/build/utils/compact-tool-allowlist.js +14 -0
  18. package/build/utils/logger.js +34 -12
  19. package/build/utils/url.js +15 -0
  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/exposure.test.js +0 -104
  32. package/build/test/cli/load-config-snapshot.js +0 -5
  33. package/build/test/cli/output.test.js +0 -74
  34. package/build/test/cli/replay-command.test.js +0 -37
  35. package/build/test/cli/router.test.js +0 -183
  36. package/build/test/client-pool-test.js +0 -109
  37. package/build/test/clients/client.js +0 -34
  38. package/build/test/clients/custom-header-client.js +0 -122
  39. package/build/test/clients/sse-client.js +0 -95
  40. package/build/test/clients/stdio-client.js +0 -113
  41. package/build/test/clients/streamable-http-client.js +0 -95
  42. package/build/test/config-allowed-groups.test.js +0 -97
  43. package/build/test/create-commit-actions.test.js +0 -102
  44. package/build/test/draft-note-schema.test.js +0 -44
  45. package/build/test/dynamic-api-url-allowlist.test.js +0 -121
  46. package/build/test/dynamic-api-url-test.js +0 -304
  47. package/build/test/dynamic-routing-tests.js +0 -495
  48. package/build/test/get-merge-request-discussion-schema.test.js +0 -30
  49. package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
  50. package/build/test/gitlab-diff-schema.test.js +0 -36
  51. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  52. package/build/test/gitlab-tag-schema.test.js +0 -51
  53. package/build/test/group-milestone-schema.test.js +0 -45
  54. package/build/test/mcp-oauth-tests.js +0 -905
  55. package/build/test/mcp-server-name.test.js +0 -87
  56. package/build/test/merge-merge-request-schema.test.js +0 -75
  57. package/build/test/multi-server-test.js +0 -190
  58. package/build/test/no-proxy-integration-test.js +0 -183
  59. package/build/test/no-proxy-test.js +0 -149
  60. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  61. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  62. package/build/test/oauth-device-flow-tests.js +0 -450
  63. package/build/test/oauth-startup.test.js +0 -204
  64. package/build/test/oauth-tests.js +0 -428
  65. package/build/test/path-segment-encoding.test.js +0 -98
  66. package/build/test/remote-auth-simple-test.js +0 -277
  67. package/build/test/remote-auth-tests.js +0 -314
  68. package/build/test/response-masking.test.js +0 -445
  69. package/build/test/schema-tests.js +0 -1679
  70. package/build/test/server/metrics.test.js +0 -47
  71. package/build/test/server/request-helpers.test.js +0 -48
  72. package/build/test/server/version.test.js +0 -13
  73. package/build/test/sse-auth-guard.test.js +0 -96
  74. package/build/test/sse-session-limits.test.js +0 -273
  75. package/build/test/stateless/callback-proxy.test.js +0 -510
  76. package/build/test/stateless/client-id.test.js +0 -177
  77. package/build/test/stateless/codec.test.js +0 -328
  78. package/build/test/stateless/config-ttl.test.js +0 -149
  79. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  80. package/build/test/stateless/session-id-integration.test.js +0 -675
  81. package/build/test/stateless/session-id.test.js +0 -157
  82. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  83. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  84. package/build/test/streamable-http-sse-stream.test.js +0 -350
  85. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  86. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  87. package/build/test/test-all-transport-server.js +0 -255
  88. package/build/test/test-auth-retry.js +0 -195
  89. package/build/test/test-blank-filters.js +0 -156
  90. package/build/test/test-ci-catalog.js +0 -177
  91. package/build/test/test-ci-lint.js +0 -191
  92. package/build/test/test-ci-variables.js +0 -309
  93. package/build/test/test-create-repository.js +0 -120
  94. package/build/test/test-dependency-proxy.js +0 -195
  95. package/build/test/test-deployment-tools.js +0 -463
  96. package/build/test/test-download-attachment.js +0 -190
  97. package/build/test/test-dynamic-project-scope.js +0 -524
  98. package/build/test/test-empty-toolsets.js +0 -535
  99. package/build/test/test-get-file-blame.js +0 -145
  100. package/build/test/test-get-file-contents.js +0 -128
  101. package/build/test/test-geteffectiveprojectid.js +0 -812
  102. package/build/test/test-health-check.js +0 -115
  103. package/build/test/test-issue-description-patch.js +0 -256
  104. package/build/test/test-job-artifacts.js +0 -275
  105. package/build/test/test-json-schema.js +0 -166
  106. package/build/test/test-list-group-members.js +0 -150
  107. package/build/test/test-list-group-merge-requests.js +0 -165
  108. package/build/test/test-list-issues.js +0 -170
  109. package/build/test/test-list-merge-requests.js +0 -201
  110. package/build/test/test-list-milestones.js +0 -145
  111. package/build/test/test-list-project-members.js +0 -132
  112. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  113. package/build/test/test-merge-request-approvals.js +0 -187
  114. package/build/test/test-merge-request-pipelines.js +0 -106
  115. package/build/test/test-mr-diffs-filter.js +0 -132
  116. package/build/test/test-mr-file-diffs.js +0 -251
  117. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  118. package/build/test/test-orbit.js +0 -155
  119. package/build/test/test-permission-mode.js +0 -424
  120. package/build/test/test-pipeline-schedules.js +0 -482
  121. package/build/test/test-protected-branches.js +0 -174
  122. package/build/test/test-remote-downloads.js +0 -510
  123. package/build/test/test-search-code.js +0 -275
  124. package/build/test/test-snippets.js +0 -735
  125. package/build/test/test-tags.js +0 -220
  126. package/build/test/test-todos.js +0 -195
  127. package/build/test/test-token-optimizations.js +0 -691
  128. package/build/test/test-toolset-filtering.js +0 -499
  129. package/build/test/test-update-issue-slim.js +0 -141
  130. package/build/test/test-update-project.js +0 -112
  131. package/build/test/test-upload-markdown.js +0 -206
  132. package/build/test/test-vulnerabilities.js +0 -399
  133. package/build/test/test-webhooks.js +0 -218
  134. package/build/test/tool-description-quality.test.js +0 -50
  135. package/build/test/utils/bulk-publish-options.test.js +0 -32
  136. package/build/test/utils/download-token.test.js +0 -35
  137. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  138. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  139. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  140. package/build/test/utils/graphql-query.test.js +0 -168
  141. package/build/test/utils/helpers-path.test.js +0 -104
  142. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  143. package/build/test/utils/masking.test.js +0 -384
  144. package/build/test/utils/merge-request-position.test.js +0 -57
  145. package/build/test/utils/mock-gitlab-server.js +0 -614
  146. package/build/test/utils/proxy-client-ip.test.js +0 -28
  147. package/build/test/utils/redact-sensitive.test.js +0 -32
  148. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  149. package/build/test/utils/server-launcher.js +0 -231
  150. package/build/test/utils/tool-args.test.js +0 -210
  151. package/build/test/utils/url.test.js +0 -128
  152. package/build/test/utils/version-check.test.js +0 -239
  153. package/build/test/utils/wiki-title.test.js +0 -21
  154. package/build/test-note.js +0 -54
  155. package/build/test-resolve-issue-note.js +0 -127
@@ -1,399 +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-12345";
6
- const TEST_PROJECT_ID = "456";
7
- const TEST_PROJECT_FULL_PATH = "test-group/test-project";
8
- const TEST_VULNERABILITY_ID = "789";
9
- const TEST_VULNERABILITY_GID = `gid://gitlab/Vulnerability/${TEST_VULNERABILITY_ID}`;
10
- const mockVulnerability = {
11
- id: TEST_VULNERABILITY_GID,
12
- title: "Hard-coded credential detected",
13
- description: "A hard-coded credential was found in source code",
14
- state: "DETECTED",
15
- severity: "CRITICAL",
16
- reportType: "SECRET_DETECTION",
17
- detectedAt: "2024-06-01T10:00:00Z",
18
- confirmedAt: null,
19
- resolvedAt: null,
20
- dismissedAt: null,
21
- dismissalReason: null,
22
- webUrl: "https://gitlab.mock/test-group/test-project/-/security/vulnerabilities/789",
23
- scanner: { name: "GitLeaks", externalId: "gitleaks", vendor: "GitLab" },
24
- identifiers: [
25
- { externalType: "cve", externalId: "CVE-2024-0001", name: "CVE-2024-0001", url: null },
26
- ],
27
- links: [{ name: "More info", url: "https://example.com/vuln/789" }],
28
- location: { file: "config/secrets.yml", startLine: 42, endLine: 42 },
29
- };
30
- const mockVulnerabilityList = [
31
- mockVulnerability,
32
- {
33
- ...mockVulnerability,
34
- id: "gid://gitlab/Vulnerability/790",
35
- title: "SQL Injection in login form",
36
- state: "CONFIRMED",
37
- severity: "HIGH",
38
- reportType: "SAST",
39
- confirmedAt: "2024-06-03T09:00:00Z",
40
- location: { file: "src/auth/login.ts", startLine: 18, endLine: 22 },
41
- },
42
- {
43
- ...mockVulnerability,
44
- id: "gid://gitlab/Vulnerability/791",
45
- title: "Outdated dependency with known CVE",
46
- state: "DISMISSED",
47
- severity: "MEDIUM",
48
- reportType: "DEPENDENCY_SCANNING",
49
- dismissedAt: "2024-05-20T14:00:00Z",
50
- dismissalReason: "ACCEPTABLE_RISK",
51
- location: { file: "package.json", dependency: { package: { name: "foo" }, version: "1.2.3" } },
52
- },
53
- ];
54
- async function callTool(toolName, args, env) {
55
- return new Promise((resolve, reject) => {
56
- const proc = spawn("node", ["build/index.js"], {
57
- stdio: ["pipe", "pipe", "pipe"],
58
- env: {
59
- ...process.env,
60
- ...env,
61
- USE_PIPELINE: "true",
62
- },
63
- });
64
- let output = "";
65
- let errorOutput = "";
66
- proc.stdout?.on("data", (d) => (output += d));
67
- proc.stderr?.on("data", (d) => (errorOutput += d));
68
- proc.on("close", code => {
69
- if (code !== 0) {
70
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
71
- }
72
- const line = output.split("\n").find(l => l.startsWith("{"));
73
- if (!line) {
74
- return reject(new Error("No JSON output found"));
75
- }
76
- try {
77
- const response = JSON.parse(line);
78
- if (response.error) {
79
- reject(response.error);
80
- }
81
- else {
82
- const content = response.result?.content?.[0]?.text;
83
- if (content) {
84
- try {
85
- resolve(JSON.parse(content));
86
- }
87
- catch {
88
- resolve(content);
89
- }
90
- }
91
- else {
92
- resolve(response.result);
93
- }
94
- }
95
- }
96
- catch (e) {
97
- reject(e);
98
- }
99
- });
100
- proc.stdin?.end(JSON.stringify({
101
- jsonrpc: "2.0",
102
- id: 1,
103
- method: "tools/call",
104
- params: { name: toolName, arguments: args },
105
- }) + "\n");
106
- });
107
- }
108
- describe("vulnerability tools", () => {
109
- let mockGitLab;
110
- let mockGitLabUrl;
111
- // Capture variables for verifying GraphQL payloads
112
- let lastListVariables = null;
113
- let lastDismissInput = null;
114
- let lastConfirmInput = null;
115
- let lastGetId = null;
116
- const baseEnv = () => ({
117
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
118
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
119
- GITLAB_TOOLSETS: "vulnerabilities",
120
- });
121
- before(async () => {
122
- const mockPort = await findMockServerPort();
123
- mockGitLab = new MockGitLabServer({
124
- port: mockPort,
125
- validTokens: [MOCK_TOKEN],
126
- });
127
- // All four tools go through POST /api/graphql; dispatch on operation name
128
- mockGitLab.addRootHandler("post", "/api/graphql", (req, res) => {
129
- const query = req.body.query || "";
130
- const variables = req.body.variables || {};
131
- if (query.includes("vulnerabilityDismiss")) {
132
- lastDismissInput = variables.input;
133
- res.json({
134
- data: {
135
- vulnerabilityDismiss: {
136
- vulnerability: {
137
- id: TEST_VULNERABILITY_GID,
138
- state: "DISMISSED",
139
- dismissedAt: "2024-06-10T12:00:00Z",
140
- dismissalReason: variables.input?.dismissalReason || null,
141
- },
142
- errors: [],
143
- },
144
- },
145
- });
146
- return;
147
- }
148
- if (query.includes("vulnerabilityConfirm")) {
149
- lastConfirmInput = variables.input;
150
- res.json({
151
- data: {
152
- vulnerabilityConfirm: {
153
- vulnerability: {
154
- id: TEST_VULNERABILITY_GID,
155
- state: "CONFIRMED",
156
- confirmedAt: "2024-06-10T12:00:00Z",
157
- },
158
- errors: [],
159
- },
160
- },
161
- });
162
- return;
163
- }
164
- if (query.includes("listProjectVulnerabilities")) {
165
- lastListVariables = variables;
166
- let nodes = mockVulnerabilityList;
167
- if (variables.state) {
168
- nodes = nodes.filter(v => variables.state.includes(v.state));
169
- }
170
- if (variables.severity) {
171
- nodes = nodes.filter(v => variables.severity.includes(v.severity));
172
- }
173
- if (variables.reportType) {
174
- nodes = nodes.filter(v => variables.reportType.includes(v.reportType));
175
- }
176
- res.json({
177
- data: {
178
- project: {
179
- vulnerabilities: {
180
- nodes,
181
- pageInfo: { endCursor: "cursor-abc", hasNextPage: false },
182
- },
183
- },
184
- },
185
- });
186
- return;
187
- }
188
- if (query.includes("getVulnerability")) {
189
- lastGetId = variables.id;
190
- res.json({
191
- data: {
192
- vulnerability: {
193
- ...mockVulnerability,
194
- project: {
195
- id: "gid://gitlab/Project/456",
196
- name: "Test Project",
197
- fullPath: TEST_PROJECT_FULL_PATH,
198
- },
199
- },
200
- },
201
- });
202
- return;
203
- }
204
- res
205
- .status(400)
206
- .json({ errors: [{ message: `Unexpected GraphQL query: ${query.slice(0, 80)}` }] });
207
- });
208
- await mockGitLab.start();
209
- mockGitLabUrl = mockGitLab.getUrl();
210
- });
211
- after(async () => {
212
- await mockGitLab.stop();
213
- });
214
- test("list_project_vulnerabilities returns vulnerabilities with pageInfo", async () => {
215
- const result = await callTool("list_project_vulnerabilities", { project_id: TEST_PROJECT_ID }, baseEnv());
216
- assert.ok(Array.isArray(result.vulnerabilities), "Response should contain vulnerabilities array");
217
- assert.strictEqual(result.vulnerabilities.length, 3, "Should return 3 vulnerabilities");
218
- assert.strictEqual(result.vulnerabilities[0].id, TEST_VULNERABILITY_GID);
219
- assert.strictEqual(result.vulnerabilities[0].title, "Hard-coded credential detected");
220
- assert.ok(result.pageInfo, "Response should include pageInfo for cursor pagination");
221
- assert.strictEqual(result.pageInfo.hasNextPage, false);
222
- });
223
- test("list_project_vulnerabilities resolves numeric project ID to full path", async () => {
224
- lastListVariables = null;
225
- await callTool("list_project_vulnerabilities", { project_id: TEST_PROJECT_ID }, baseEnv());
226
- assert.ok(lastListVariables, "GraphQL variables should have been captured");
227
- assert.strictEqual(lastListVariables.fullPath, TEST_PROJECT_FULL_PATH, "Numeric project ID should be resolved to the project full path");
228
- });
229
- test("list_project_vulnerabilities passes state filter as GraphQL enum", async () => {
230
- lastListVariables = null;
231
- const result = await callTool("list_project_vulnerabilities", { project_id: TEST_PROJECT_ID, state: "detected" }, baseEnv());
232
- assert.ok(lastListVariables, "GraphQL variables should have been captured");
233
- assert.deepStrictEqual(lastListVariables.state, ["DETECTED"], "state should be uppercased enum array");
234
- assert.strictEqual(result.vulnerabilities.length, 1, "Mock should filter to only DETECTED");
235
- });
236
- test("list_project_vulnerabilities passes severity filter as GraphQL enum", async () => {
237
- lastListVariables = null;
238
- const result = await callTool("list_project_vulnerabilities", { project_id: TEST_PROJECT_ID, severity: "critical" }, baseEnv());
239
- assert.ok(lastListVariables, "GraphQL variables should have been captured");
240
- assert.deepStrictEqual(lastListVariables.severity, ["CRITICAL"]);
241
- assert.strictEqual(result.vulnerabilities.length, 1, "Mock should filter to only CRITICAL");
242
- });
243
- test("list_project_vulnerabilities passes report_type filter as GraphQL enum", async () => {
244
- lastListVariables = null;
245
- const result = await callTool("list_project_vulnerabilities", { project_id: TEST_PROJECT_ID, report_type: "secret_detection" }, baseEnv());
246
- assert.ok(lastListVariables, "GraphQL variables should have been captured");
247
- assert.deepStrictEqual(lastListVariables.reportType, ["SECRET_DETECTION"]);
248
- assert.strictEqual(result.vulnerabilities.length, 1, "Mock should filter to only SECRET_DETECTION");
249
- });
250
- test("list_project_vulnerabilities forwards cursor pagination", async () => {
251
- lastListVariables = null;
252
- await callTool("list_project_vulnerabilities", { project_id: TEST_PROJECT_ID, first: 50, after: "cursor-abc" }, baseEnv());
253
- assert.ok(lastListVariables, "GraphQL variables should have been captured");
254
- assert.strictEqual(lastListVariables.first, 50);
255
- assert.strictEqual(lastListVariables.after, "cursor-abc");
256
- });
257
- test("get_vulnerability returns full vulnerability object via GID", async () => {
258
- lastGetId = null;
259
- const result = await callTool("get_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, baseEnv());
260
- assert.strictEqual(lastGetId, TEST_VULNERABILITY_GID, "Numeric ID should be converted to a GraphQL global ID");
261
- assert.strictEqual(result.id, TEST_VULNERABILITY_GID);
262
- assert.strictEqual(result.title, "Hard-coded credential detected");
263
- assert.strictEqual(result.description, "A hard-coded credential was found in source code");
264
- assert.strictEqual(result.state, "DETECTED");
265
- assert.strictEqual(result.severity, "CRITICAL");
266
- assert.strictEqual(result.reportType, "SECRET_DETECTION");
267
- assert.strictEqual(result.location.file, "config/secrets.yml");
268
- assert.strictEqual(result.location.startLine, 42);
269
- assert.strictEqual(result.identifiers[0].name, "CVE-2024-0001");
270
- assert.strictEqual(result.links[0].url, "https://example.com/vuln/789");
271
- assert.strictEqual(result.project.fullPath, TEST_PROJECT_FULL_PATH);
272
- });
273
- test("dismiss_vulnerability sends dismissalReason in mutation input", async () => {
274
- lastDismissInput = null;
275
- const result = await callTool("dismiss_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID, reason: "false_positive" }, baseEnv());
276
- assert.ok(lastDismissInput, "Mutation input should have been captured");
277
- assert.strictEqual(lastDismissInput.id, TEST_VULNERABILITY_GID);
278
- assert.strictEqual(lastDismissInput.dismissalReason, "FALSE_POSITIVE", "Reason should be mapped to the GraphQL enum");
279
- assert.strictEqual(result.state, "DISMISSED");
280
- assert.strictEqual(result.dismissalReason, "FALSE_POSITIVE");
281
- });
282
- test("dismiss_vulnerability includes comment when provided", async () => {
283
- lastDismissInput = null;
284
- await callTool("dismiss_vulnerability", {
285
- vulnerability_id: TEST_VULNERABILITY_ID,
286
- reason: "acceptable_risk",
287
- comment: "Reviewed by security team, risk accepted",
288
- }, baseEnv());
289
- assert.ok(lastDismissInput, "Mutation input should have been captured");
290
- assert.strictEqual(lastDismissInput.dismissalReason, "ACCEPTABLE_RISK");
291
- assert.strictEqual(lastDismissInput.comment, "Reviewed by security team, risk accepted");
292
- });
293
- test("dismiss_vulnerability accepts mitigating_control and not_applicable reasons", async () => {
294
- lastDismissInput = null;
295
- await callTool("dismiss_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID, reason: "mitigating_control" }, baseEnv());
296
- assert.strictEqual(lastDismissInput.dismissalReason, "MITIGATING_CONTROL");
297
- lastDismissInput = null;
298
- await callTool("dismiss_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID, reason: "not_applicable" }, baseEnv());
299
- assert.strictEqual(lastDismissInput.dismissalReason, "NOT_APPLICABLE");
300
- });
301
- test("confirm_vulnerability sends mutation with GID", async () => {
302
- lastConfirmInput = null;
303
- const result = await callTool("confirm_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, baseEnv());
304
- assert.ok(lastConfirmInput, "Mutation input should have been captured");
305
- assert.strictEqual(lastConfirmInput.id, TEST_VULNERABILITY_GID);
306
- assert.strictEqual(result.state, "CONFIRMED");
307
- assert.strictEqual(result.confirmedAt, "2024-06-10T12:00:00Z");
308
- });
309
- test("confirm_vulnerability includes comment when provided", async () => {
310
- lastConfirmInput = null;
311
- await callTool("confirm_vulnerability", {
312
- vulnerability_id: TEST_VULNERABILITY_ID,
313
- comment: "Confirmed after manual verification",
314
- }, baseEnv());
315
- assert.ok(lastConfirmInput, "Mutation input should have been captured");
316
- assert.strictEqual(lastConfirmInput.comment, "Confirmed after manual verification");
317
- });
318
- // Read-only mode tests
319
- test("read-only mode: list_project_vulnerabilities succeeds", async () => {
320
- const result = await callTool("list_project_vulnerabilities", { project_id: TEST_PROJECT_ID }, { ...baseEnv(), GITLAB_PERMISSION_MODE: "readonly" });
321
- assert.ok(Array.isArray(result.vulnerabilities), "Should return vulnerabilities in readonly mode");
322
- assert.strictEqual(result.vulnerabilities.length, 3);
323
- });
324
- test("read-only mode: get_vulnerability succeeds", async () => {
325
- const result = await callTool("get_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, { ...baseEnv(), GITLAB_PERMISSION_MODE: "readonly" });
326
- assert.strictEqual(result.id, TEST_VULNERABILITY_GID);
327
- assert.strictEqual(result.title, "Hard-coded credential detected");
328
- });
329
- test("read-only mode: dismiss_vulnerability is rejected", async () => {
330
- await assert.rejects(() => callTool("dismiss_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID, reason: "false_positive" }, { ...baseEnv(), GITLAB_PERMISSION_MODE: "readonly" }), (err) => {
331
- const msg = typeof err === "string" ? err : err?.message || JSON.stringify(err);
332
- assert.ok(msg.toLowerCase().includes("not allowed") ||
333
- msg.toLowerCase().includes("read-only") ||
334
- msg.toLowerCase().includes("readonly") ||
335
- msg.toLowerCase().includes("not available"), `Expected read-only rejection, got: ${msg}`);
336
- return true;
337
- });
338
- });
339
- test("read-only mode: confirm_vulnerability is rejected", async () => {
340
- await assert.rejects(() => callTool("confirm_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, { ...baseEnv(), GITLAB_PERMISSION_MODE: "readonly" }), (err) => {
341
- const msg = typeof err === "string" ? err : err?.message || JSON.stringify(err);
342
- assert.ok(msg.toLowerCase().includes("not allowed") ||
343
- msg.toLowerCase().includes("read-only") ||
344
- msg.toLowerCase().includes("readonly") ||
345
- msg.toLowerCase().includes("not available"), `Expected read-only rejection, got: ${msg}`);
346
- return true;
347
- });
348
- });
349
- // GITLAB_ALLOWED_PROJECT_IDS tests: the mock vulnerability belongs to
350
- // project 456 (test-group/test-project), so an allowlist of "999" must
351
- // deny all id-only vulnerability tools.
352
- const assertAccessDenied = (err) => {
353
- const msg = typeof err === "string" ? err : err?.message || JSON.stringify(err);
354
- assert.ok(msg.includes("Access denied"), `Expected allowlist rejection, got: ${msg}`);
355
- return true;
356
- };
357
- test("allowlist: get_vulnerability is rejected for a vulnerability outside allowed projects", async () => {
358
- await assert.rejects(() => callTool("get_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, { ...baseEnv(), GITLAB_ALLOWED_PROJECT_IDS: "999" }), assertAccessDenied);
359
- });
360
- test("allowlist: get_vulnerability succeeds when project is allowed by numeric ID", async () => {
361
- const result = await callTool("get_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, { ...baseEnv(), GITLAB_ALLOWED_PROJECT_IDS: TEST_PROJECT_ID });
362
- assert.strictEqual(result.id, TEST_VULNERABILITY_GID);
363
- });
364
- test("allowlist: get_vulnerability succeeds when project is allowed by full path", async () => {
365
- const result = await callTool("get_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, { ...baseEnv(), GITLAB_ALLOWED_PROJECT_IDS: `999,${TEST_PROJECT_FULL_PATH}` });
366
- assert.strictEqual(result.id, TEST_VULNERABILITY_GID);
367
- });
368
- test("allowlist: dismiss_vulnerability is rejected before the mutation is sent", async () => {
369
- lastDismissInput = null;
370
- await assert.rejects(() => callTool("dismiss_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID, reason: "false_positive" }, { ...baseEnv(), GITLAB_ALLOWED_PROJECT_IDS: "999" }), assertAccessDenied);
371
- assert.strictEqual(lastDismissInput, null, "vulnerabilityDismiss mutation must not be sent for a denied project");
372
- });
373
- test("allowlist: confirm_vulnerability is rejected before the mutation is sent", async () => {
374
- lastConfirmInput = null;
375
- await assert.rejects(() => callTool("confirm_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID }, { ...baseEnv(), GITLAB_ALLOWED_PROJECT_IDS: "999" }), assertAccessDenied);
376
- assert.strictEqual(lastConfirmInput, null, "vulnerabilityConfirm mutation must not be sent for a denied project");
377
- });
378
- test("allowlist: dismiss_vulnerability succeeds when the vulnerability's project is allowed", async () => {
379
- lastDismissInput = null;
380
- const result = await callTool("dismiss_vulnerability", { vulnerability_id: TEST_VULNERABILITY_ID, reason: "false_positive" }, { ...baseEnv(), GITLAB_ALLOWED_PROJECT_IDS: TEST_PROJECT_ID });
381
- assert.ok(lastDismissInput, "Mutation should be sent after the allowlist check passes");
382
- assert.strictEqual(lastDismissInput.id, TEST_VULNERABILITY_GID);
383
- assert.strictEqual(result.state, "DISMISSED");
384
- });
385
- // GID validation tests: only numeric IDs and Vulnerability GIDs are accepted
386
- const assertInvalidVulnerabilityId = (err) => {
387
- const msg = typeof err === "string" ? err : err?.message || JSON.stringify(err);
388
- assert.ok(msg.includes("Invalid vulnerability ID"), `Expected invalid-ID rejection, got: ${msg}`);
389
- return true;
390
- };
391
- test("gid validation: get_vulnerability rejects non-Vulnerability GIDs", async () => {
392
- await assert.rejects(() => callTool("get_vulnerability", { vulnerability_id: "gid://gitlab/Project/456" }, baseEnv()), assertInvalidVulnerabilityId);
393
- });
394
- test("gid validation: dismiss_vulnerability rejects a non-numeric ID before any request", async () => {
395
- lastDismissInput = null;
396
- await assert.rejects(() => callTool("dismiss_vulnerability", { vulnerability_id: "not-a-vuln-id", reason: "false_positive" }, baseEnv()), assertInvalidVulnerabilityId);
397
- assert.strictEqual(lastDismissInput, null, "vulnerabilityDismiss mutation must not be sent for an invalid ID");
398
- });
399
- });
@@ -1,218 +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-webhooks";
6
- const TEST_PROJECT_ID = "123";
7
- const TEST_GROUP_ID = "my-group";
8
- const TEST_HOOK_ID = 42;
9
- const MOCK_PROJECT_HOOK = {
10
- id: TEST_HOOK_ID,
11
- url: "https://example.com/hook",
12
- name: "AI Hook",
13
- description: "Registered by MCP",
14
- project_id: Number(TEST_PROJECT_ID),
15
- push_events: true,
16
- issues_events: false,
17
- enable_ssl_verification: true,
18
- };
19
- const MOCK_GROUP_HOOK = {
20
- id: TEST_HOOK_ID,
21
- url: "https://example.com/group-hook",
22
- name: "Group Hook",
23
- group_id: 3,
24
- push_events: true,
25
- member_events: true,
26
- enable_ssl_verification: true,
27
- };
28
- function isRecord(value) {
29
- return typeof value === "object" && value !== null && !Array.isArray(value);
30
- }
31
- async function callTool(toolName, args, env) {
32
- return new Promise((resolve, reject) => {
33
- const proc = spawn("node", ["build/index.js"], {
34
- stdio: ["pipe", "pipe", "pipe"],
35
- env: { ...process.env, ...env },
36
- });
37
- let output = "";
38
- let errorOutput = "";
39
- proc.stdout?.on("data", (d) => (output += d));
40
- proc.stderr?.on("data", (d) => (errorOutput += d));
41
- proc.on("close", code => {
42
- if (code !== 0) {
43
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
44
- }
45
- const line = output.split("\n").find(l => l.startsWith("{"));
46
- if (!line)
47
- return reject(new Error("No JSON output found"));
48
- try {
49
- const response = JSON.parse(line);
50
- if (response.error) {
51
- reject(new Error(response.error?.message ?? String(response.error)));
52
- }
53
- else {
54
- const content = response.result?.content?.[0]?.text;
55
- resolve(content ? JSON.parse(content) : response.result);
56
- }
57
- }
58
- catch (e) {
59
- reject(e);
60
- }
61
- });
62
- proc.stdin?.end(JSON.stringify({
63
- jsonrpc: "2.0",
64
- id: 1,
65
- method: "tools/call",
66
- params: { name: toolName, arguments: args },
67
- }) + "\n");
68
- });
69
- }
70
- describe("When managing webhooks", () => {
71
- let mockServer;
72
- let baseEnv;
73
- let lastCreateBody;
74
- let lastUpdateBody;
75
- let lastDeletePath;
76
- before(async () => {
77
- mockServer = new MockGitLabServer({
78
- port: await findMockServerPort(),
79
- validTokens: [MOCK_TOKEN],
80
- });
81
- mockServer.addMockHandler("post", `/projects/${TEST_PROJECT_ID}/hooks`, (req, res) => {
82
- lastCreateBody = isRecord(req.body) ? req.body : undefined;
83
- res.status(201).json({ ...MOCK_PROJECT_HOOK, ...lastCreateBody });
84
- });
85
- mockServer.addMockHandler("put", `/projects/${TEST_PROJECT_ID}/hooks/${TEST_HOOK_ID}`, (req, res) => {
86
- lastUpdateBody = isRecord(req.body) ? req.body : undefined;
87
- res.json({ ...MOCK_PROJECT_HOOK, ...lastUpdateBody, id: TEST_HOOK_ID });
88
- });
89
- mockServer.addMockHandler("delete", `/projects/${TEST_PROJECT_ID}/hooks/${TEST_HOOK_ID}`, (req, res) => {
90
- lastDeletePath = req.path;
91
- res.status(204).send();
92
- });
93
- mockServer.addMockHandler("post", `/groups/${TEST_GROUP_ID}/hooks`, (req, res) => {
94
- lastCreateBody = isRecord(req.body) ? req.body : undefined;
95
- res.status(201).json({ ...MOCK_GROUP_HOOK, ...lastCreateBody });
96
- });
97
- mockServer.addMockHandler("put", `/groups/${TEST_GROUP_ID}/hooks/${TEST_HOOK_ID}`, (req, res) => {
98
- lastUpdateBody = isRecord(req.body) ? req.body : undefined;
99
- res.json({ ...MOCK_GROUP_HOOK, ...lastUpdateBody, id: TEST_HOOK_ID });
100
- });
101
- mockServer.addMockHandler("delete", `/groups/${TEST_GROUP_ID}/hooks/${TEST_HOOK_ID}`, (req, res) => {
102
- lastDeletePath = req.path;
103
- res.status(204).send();
104
- });
105
- await mockServer.start();
106
- baseEnv = {
107
- GITLAB_API_URL: mockServer.getUrl() + "/api/v4",
108
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
109
- GITLAB_TOOLSETS: "webhooks",
110
- GITLAB_READ_ONLY_MODE: "false",
111
- };
112
- });
113
- after(async () => {
114
- if (mockServer)
115
- await mockServer.stop();
116
- });
117
- describe("with create_webhook on a project", () => {
118
- test("should create a webhook and return the GitLab response", async () => {
119
- lastCreateBody = undefined;
120
- const result = await callTool("create_webhook", {
121
- project_id: TEST_PROJECT_ID,
122
- url: "https://example.com/hook",
123
- name: "AI Hook",
124
- push_events: true,
125
- issues_events: true,
126
- }, baseEnv);
127
- assert.deepStrictEqual(lastCreateBody, {
128
- url: "https://example.com/hook",
129
- name: "AI Hook",
130
- push_events: true,
131
- issues_events: true,
132
- });
133
- assert.ok(isRecord(result));
134
- assert.strictEqual(result.url, "https://example.com/hook");
135
- assert.strictEqual(result.name, "AI Hook");
136
- });
137
- });
138
- describe("with update_webhook on a project", () => {
139
- test("should update a webhook and return the GitLab response", async () => {
140
- lastUpdateBody = undefined;
141
- const result = await callTool("update_webhook", {
142
- project_id: TEST_PROJECT_ID,
143
- hook_id: TEST_HOOK_ID,
144
- url: "https://example.com/hook-updated",
145
- name: "Renamed Hook",
146
- }, baseEnv);
147
- assert.deepStrictEqual(lastUpdateBody, {
148
- url: "https://example.com/hook-updated",
149
- name: "Renamed Hook",
150
- });
151
- assert.ok(isRecord(result));
152
- assert.strictEqual(result.url, "https://example.com/hook-updated");
153
- });
154
- });
155
- describe("with delete_webhook on a project", () => {
156
- test("should delete a webhook and return a deleted status", async () => {
157
- lastDeletePath = undefined;
158
- const result = await callTool("delete_webhook", {
159
- project_id: TEST_PROJECT_ID,
160
- hook_id: TEST_HOOK_ID,
161
- }, baseEnv);
162
- assert.strictEqual(lastDeletePath, `/projects/${TEST_PROJECT_ID}/hooks/${TEST_HOOK_ID}`);
163
- assert.deepStrictEqual(result, { status: "deleted", hook_id: TEST_HOOK_ID });
164
- });
165
- });
166
- describe("with create_webhook on a group", () => {
167
- test("should create a group webhook", async () => {
168
- lastCreateBody = undefined;
169
- const result = await callTool("create_webhook", {
170
- group_id: TEST_GROUP_ID,
171
- url: "https://example.com/group-hook",
172
- member_events: true,
173
- }, baseEnv);
174
- assert.ok(lastCreateBody);
175
- assert.strictEqual(lastCreateBody["url"], "https://example.com/group-hook");
176
- assert.strictEqual(lastCreateBody["member_events"], true);
177
- assert.ok(isRecord(result));
178
- assert.strictEqual(result["url"], "https://example.com/group-hook");
179
- });
180
- });
181
- describe("with update_webhook on a group", () => {
182
- test("should update a group webhook", async () => {
183
- lastUpdateBody = undefined;
184
- const result = await callTool("update_webhook", {
185
- group_id: TEST_GROUP_ID,
186
- hook_id: TEST_HOOK_ID,
187
- url: "https://example.com/group-hook-updated",
188
- name: "Renamed Group Hook",
189
- }, baseEnv);
190
- assert.deepStrictEqual(lastUpdateBody, {
191
- url: "https://example.com/group-hook-updated",
192
- name: "Renamed Group Hook",
193
- });
194
- assert.ok(isRecord(result));
195
- assert.strictEqual(result.url, "https://example.com/group-hook-updated");
196
- });
197
- });
198
- describe("with delete_webhook on a group", () => {
199
- test("should delete a group webhook", async () => {
200
- lastDeletePath = undefined;
201
- const result = await callTool("delete_webhook", {
202
- group_id: TEST_GROUP_ID,
203
- hook_id: TEST_HOOK_ID,
204
- }, baseEnv);
205
- assert.strictEqual(lastDeletePath, `/groups/${TEST_GROUP_ID}/hooks/${TEST_HOOK_ID}`);
206
- assert.deepStrictEqual(result, { status: "deleted", hook_id: TEST_HOOK_ID });
207
- });
208
- });
209
- describe("with invalid scope", () => {
210
- test("should reject when both project_id and group_id are provided", async () => {
211
- await assert.rejects(() => callTool("create_webhook", {
212
- project_id: TEST_PROJECT_ID,
213
- group_id: TEST_GROUP_ID,
214
- url: "https://example.com/hook",
215
- }, baseEnv), /project_id or group_id/);
216
- });
217
- });
218
- });
@@ -1,50 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, it } from "node:test";
3
- import { allTools, TOOLSET_DEFINITIONS } from "../tools/registry.js";
4
- function getExposedTool(name) {
5
- const tool = allTools.find(candidate => candidate.name === name);
6
- assert.ok(tool);
7
- return tool;
8
- }
9
- function getDefaultToolNames() {
10
- return new Set(TOOLSET_DEFINITIONS.filter(definition => definition.isDefault).flatMap(definition => [
11
- ...definition.tools,
12
- ]));
13
- }
14
- describe("When MCP tool descriptions are exposed", () => {
15
- describe("with the default toolsets", () => {
16
- it("should provide enough context for first-attempt tool selection", () => {
17
- const defaultToolNames = getDefaultToolNames();
18
- const defaultTools = allTools.filter(tool => defaultToolNames.has(tool.name));
19
- assert.ok(defaultTools.length > 0);
20
- assert.ok(defaultTools.every(tool => tool.description.length >= 120));
21
- });
22
- });
23
- describe("with create_branch", () => {
24
- it("should explain its source revision and neighboring branch operations", () => {
25
- const tool = getExposedTool("create_branch");
26
- assert.match(tool.description, /source branch|tag|commit[\s\S]*protect_branch[\s\S]*already-exists/i);
27
- });
28
- });
29
- describe("with list_issues", () => {
30
- it("should include issue-management guidance and omit group_id", () => {
31
- const tool = getExposedTool("list_issues");
32
- assert.match(tool.description, /issue management/i);
33
- assert.doesNotMatch(tool.description, /group_id/);
34
- });
35
- });
36
- describe("with my_issues", () => {
37
- it("should include issue-management guidance and omit group_id", () => {
38
- const tool = getExposedTool("my_issues");
39
- assert.match(tool.description, /issue management/i);
40
- assert.doesNotMatch(tool.description, /group_id/);
41
- });
42
- });
43
- describe("with get_issue", () => {
44
- it("should include issue-management guidance and omit group_id", () => {
45
- const tool = getExposedTool("get_issue");
46
- assert.match(tool.description, /issue management/i);
47
- assert.doesNotMatch(tool.description, /group_id/);
48
- });
49
- });
50
- });