@zereight/mcp-gitlab 2.1.56 → 2.1.58

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.
@@ -0,0 +1,362 @@
1
+ import { describe, test, before, after } from "node:test";
2
+ import assert from "node:assert";
3
+ import { cleanupServers, findAvailablePort, HOST, launchServer, TransportMode, } from "./utils/server-launcher.js";
4
+ import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
5
+ import { CustomHeaderClient } from "./clients/custom-header-client.js";
6
+ const MOCK_TOKEN = "glpat-dynamic-scope-token";
7
+ const SCOPE_HEADER = "x-gitlab-allowed-project-ids";
8
+ async function connectClient(mcpUrl, scope) {
9
+ const headers = { authorization: `Bearer ${MOCK_TOKEN}` };
10
+ if (scope !== undefined) {
11
+ headers[SCOPE_HEADER] = scope;
12
+ }
13
+ const client = new CustomHeaderClient(headers);
14
+ await client.connect(mcpUrl);
15
+ return client;
16
+ }
17
+ async function getProjectId(client, projectId) {
18
+ const result = await client.callTool("get_project", { project_id: projectId });
19
+ assert.ok(result.content, "Should have content");
20
+ const content = result.content[0];
21
+ assert.ok("text" in content, "Content should have text");
22
+ const project = JSON.parse(content.text);
23
+ return project.id.toString();
24
+ }
25
+ describe("Dynamic project scope", { concurrency: 1 }, () => {
26
+ describe("with GITLAB_ALLOWED_PROJECT_IDS set", () => {
27
+ let mockGitLab;
28
+ const servers = [];
29
+ let mcpUrl;
30
+ before(async () => {
31
+ const mockPort = await findMockServerPort();
32
+ mockGitLab = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
33
+ mockGitLab.addMockHandler("get", "/projects", (req, res) => {
34
+ if (req.query.search === "no-totals") {
35
+ const requestedPage = Number(req.query.page ?? "1");
36
+ if (requestedPage < 3) {
37
+ res.set("x-next-page", String(requestedPage + 1));
38
+ }
39
+ }
40
+ else {
41
+ res.set("x-total", "3");
42
+ res.set("x-total-pages", "2");
43
+ }
44
+ res.json(["1", "2", "3"].map(id => ({
45
+ id: Number(id),
46
+ name: `Project ${id}`,
47
+ path: `project-${id}`,
48
+ path_with_namespace: `group/project-${id}`,
49
+ description: null,
50
+ visibility: "private",
51
+ namespace: { id: 1, name: "Group", path: "group", kind: "group", full_path: "group" },
52
+ })));
53
+ });
54
+ await mockGitLab.start();
55
+ const mcpPort = await findAvailablePort(3200);
56
+ const server = await launchServer({
57
+ mode: TransportMode.STREAMABLE_HTTP,
58
+ port: mcpPort,
59
+ timeout: 5000,
60
+ env: {
61
+ STREAMABLE_HTTP: "true",
62
+ REMOTE_AUTHORIZATION: "true",
63
+ ENABLE_DYNAMIC_PROJECT_SCOPE: "true",
64
+ ENABLE_STRICT_PROJECT_SCOPE: "true",
65
+ GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
66
+ GITLAB_ALLOWED_PROJECT_IDS: "1,2",
67
+ },
68
+ });
69
+ servers.push(server);
70
+ mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
71
+ });
72
+ after(async () => {
73
+ cleanupServers(servers);
74
+ await mockGitLab?.stop();
75
+ });
76
+ test("header narrows the allowlist to the requested projects", async () => {
77
+ const client = await connectClient(mcpUrl, "1");
78
+ try {
79
+ assert.strictEqual(await getProjectId(client, ""), "1");
80
+ await assert.rejects(() => client.callTool("get_project", { project_id: "2" }), /Access denied/);
81
+ }
82
+ finally {
83
+ await client.disconnect();
84
+ }
85
+ });
86
+ test("project outside GITLAB_ALLOWED_PROJECT_IDS rejects the session", async () => {
87
+ const client = new CustomHeaderClient({
88
+ authorization: `Bearer ${MOCK_TOKEN}`,
89
+ [SCOPE_HEADER]: "1,3",
90
+ });
91
+ let connected = false;
92
+ try {
93
+ await client.connect(mcpUrl);
94
+ connected = true;
95
+ await client.callTool("get_project", { project_id: "1" });
96
+ }
97
+ catch {
98
+ // Expected: the session is rejected before any tool call is possible.
99
+ }
100
+ finally {
101
+ await client.disconnect();
102
+ }
103
+ assert.strictEqual(connected, false, "out-of-scope header must not initialize a session");
104
+ });
105
+ test("empty header rejects the session", async () => {
106
+ const client = new CustomHeaderClient({
107
+ authorization: `Bearer ${MOCK_TOKEN}`,
108
+ [SCOPE_HEADER]: " ",
109
+ });
110
+ let connected = false;
111
+ try {
112
+ await client.connect(mcpUrl);
113
+ connected = true;
114
+ await client.callTool("get_project", { project_id: "1" });
115
+ }
116
+ catch {
117
+ // Expected: the session is rejected before any tool call is possible.
118
+ }
119
+ finally {
120
+ await client.disconnect();
121
+ }
122
+ assert.strictEqual(connected, false, "an empty header must not initialize a session");
123
+ });
124
+ test("scoped session refuses non-scopable tools", async () => {
125
+ const client = await connectClient(mcpUrl, "1");
126
+ try {
127
+ await assert.rejects(() => client.callTool("execute_graphql", { query: "query { currentUser { id } }" }), /not allowed while a project allowlist is in effect/);
128
+ }
129
+ finally {
130
+ await client.disconnect();
131
+ }
132
+ });
133
+ test("session without the header keeps the full env allowlist", async () => {
134
+ const client = await connectClient(mcpUrl);
135
+ try {
136
+ assert.strictEqual(await getProjectId(client, "2"), "2");
137
+ }
138
+ finally {
139
+ await client.disconnect();
140
+ }
141
+ });
142
+ test("list_issues without project_id stays within the session scope", async () => {
143
+ const client = await connectClient(mcpUrl, "1");
144
+ try {
145
+ const result = await client.callTool("list_issues", {});
146
+ assert.ok(result.content, "Should have content");
147
+ const content = result.content[0];
148
+ assert.ok("text" in content, "Content should have text");
149
+ const issues = JSON.parse(content.text);
150
+ assert.ok(issues.every(issue => issue.web_url.includes("/project/1/")), "Should only return issues of the scoped project");
151
+ }
152
+ finally {
153
+ await client.disconnect();
154
+ }
155
+ });
156
+ test("list_todos is refused under strict scope", async () => {
157
+ const client = await connectClient(mcpUrl, "1");
158
+ try {
159
+ await assert.rejects(() => client.callTool("list_todos", {}), /not allowed while a project allowlist is in effect/);
160
+ }
161
+ finally {
162
+ await client.disconnect();
163
+ }
164
+ });
165
+ test("search_repositories keeps the unfiltered pagination totals", async () => {
166
+ const client = await connectClient(mcpUrl, "1");
167
+ try {
168
+ const result = await client.callTool("search_repositories", { search: "project" });
169
+ assert.ok(result.content, "Should have content");
170
+ const content = result.content[0];
171
+ assert.ok("text" in content, "Content should have text");
172
+ const search = JSON.parse(content.text);
173
+ assert.deepStrictEqual(search.items.map(item => item.id), ["1"]);
174
+ assert.strictEqual(search.count, 3, "count must reflect the unfiltered GitLab total");
175
+ assert.strictEqual(search.total_pages, 2, "total_pages must cover the unfiltered pages");
176
+ }
177
+ finally {
178
+ await client.disconnect();
179
+ }
180
+ });
181
+ test("search_repositories follows next_page across all pages when totals are missing", async () => {
182
+ const client = await connectClient(mcpUrl, "1");
183
+ try {
184
+ let page = 1;
185
+ const visited = [];
186
+ while (page !== undefined) {
187
+ const result = await client.callTool("search_repositories", {
188
+ search: "no-totals",
189
+ page,
190
+ });
191
+ assert.ok(result.content, "Should have content");
192
+ const content = result.content[0];
193
+ assert.ok("text" in content, "Content should have text");
194
+ const search = JSON.parse(content.text);
195
+ assert.strictEqual(search.total_pages, undefined, "total_pages must stay unset");
196
+ assert.deepStrictEqual(search.items.map(item => item.id), ["1"]);
197
+ visited.push(search.current_page);
198
+ page = search.next_page;
199
+ }
200
+ assert.deepStrictEqual(visited, [1, 2, 3], "next_page must make every page reachable");
201
+ }
202
+ finally {
203
+ await client.disconnect();
204
+ }
205
+ });
206
+ test("list_projects is filtered to the session scope", async () => {
207
+ const client = await connectClient(mcpUrl, "1");
208
+ try {
209
+ const result = await client.callTool("list_projects", {});
210
+ assert.ok(result.content, "Should have content");
211
+ const content = result.content[0];
212
+ assert.ok("text" in content, "Content should have text");
213
+ const projects = JSON.parse(content.text);
214
+ assert.deepStrictEqual(projects.map(project => project.id), ["1"]);
215
+ }
216
+ finally {
217
+ await client.disconnect();
218
+ }
219
+ });
220
+ test("list_projects is filtered to the env allowlist without the header", async () => {
221
+ const client = await connectClient(mcpUrl);
222
+ try {
223
+ const result = await client.callTool("list_projects", {});
224
+ assert.ok(result.content, "Should have content");
225
+ const content = result.content[0];
226
+ assert.ok("text" in content, "Content should have text");
227
+ const projects = JSON.parse(content.text);
228
+ assert.deepStrictEqual(projects.map(project => project.id), ["1", "2"]);
229
+ }
230
+ finally {
231
+ await client.disconnect();
232
+ }
233
+ });
234
+ });
235
+ describe("without GITLAB_ALLOWED_PROJECT_IDS", () => {
236
+ let mockGitLab;
237
+ const servers = [];
238
+ let mcpUrl;
239
+ before(async () => {
240
+ const mockPort = await findMockServerPort();
241
+ mockGitLab = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
242
+ mockGitLab.addRootHandler("post", "/api/graphql", (req, res) => {
243
+ const { query } = req.body;
244
+ if (query.includes("vulnerability(")) {
245
+ res.json({
246
+ data: {
247
+ vulnerability: {
248
+ id: "gid://gitlab/Vulnerability/42",
249
+ title: "Mock vulnerability",
250
+ project: {
251
+ id: "gid://gitlab/Project/8",
252
+ name: "Other project",
253
+ fullPath: "other/project",
254
+ },
255
+ },
256
+ },
257
+ });
258
+ return;
259
+ }
260
+ res.status(500).json({ message: `Unexpected GraphQL query: ${query}` });
261
+ });
262
+ await mockGitLab.start();
263
+ const mcpPort = await findAvailablePort(3200);
264
+ const server = await launchServer({
265
+ mode: TransportMode.STREAMABLE_HTTP,
266
+ port: mcpPort,
267
+ timeout: 5000,
268
+ env: {
269
+ STREAMABLE_HTTP: "true",
270
+ REMOTE_AUTHORIZATION: "true",
271
+ ENABLE_DYNAMIC_PROJECT_SCOPE: "true",
272
+ GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
273
+ },
274
+ });
275
+ servers.push(server);
276
+ mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
277
+ });
278
+ after(async () => {
279
+ cleanupServers(servers);
280
+ await mockGitLab?.stop();
281
+ });
282
+ test("header bounds an otherwise unrestricted server", async () => {
283
+ const client = await connectClient(mcpUrl, "7");
284
+ try {
285
+ assert.strictEqual(await getProjectId(client, ""), "7");
286
+ await assert.rejects(() => client.callTool("get_project", { project_id: "8" }), /Access denied/);
287
+ await assert.rejects(() => client.callTool("execute_graphql", { query: "query { currentUser { id } }" }), /not allowed while a project allowlist is in effect/);
288
+ }
289
+ finally {
290
+ await client.disconnect();
291
+ }
292
+ });
293
+ test("session without the header stays unrestricted", async () => {
294
+ const client = await connectClient(mcpUrl);
295
+ try {
296
+ assert.strictEqual(await getProjectId(client, "8"), "8");
297
+ }
298
+ finally {
299
+ await client.disconnect();
300
+ }
301
+ });
302
+ test("scoped session cannot reach vulnerabilities of other projects", async () => {
303
+ const client = await connectClient(mcpUrl, "7");
304
+ try {
305
+ await assert.rejects(() => client.callTool("get_vulnerability", { vulnerability_id: "42" }), /Access denied/);
306
+ }
307
+ finally {
308
+ await client.disconnect();
309
+ }
310
+ });
311
+ test("unscoped session can reach vulnerabilities", async () => {
312
+ const client = await connectClient(mcpUrl);
313
+ try {
314
+ const result = await client.callTool("get_vulnerability", { vulnerability_id: "42" });
315
+ assert.ok(result.content, "Should have content");
316
+ const content = result.content[0];
317
+ assert.ok("text" in content, "Content should have text");
318
+ const vulnerability = JSON.parse(content.text);
319
+ assert.strictEqual(vulnerability.project.fullPath, "other/project");
320
+ }
321
+ finally {
322
+ await client.disconnect();
323
+ }
324
+ });
325
+ });
326
+ describe("with ENABLE_DYNAMIC_PROJECT_SCOPE disabled", () => {
327
+ let mockGitLab;
328
+ const servers = [];
329
+ let mcpUrl;
330
+ before(async () => {
331
+ const mockPort = await findMockServerPort();
332
+ mockGitLab = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
333
+ await mockGitLab.start();
334
+ const mcpPort = await findAvailablePort(3200);
335
+ const server = await launchServer({
336
+ mode: TransportMode.STREAMABLE_HTTP,
337
+ port: mcpPort,
338
+ timeout: 5000,
339
+ env: {
340
+ STREAMABLE_HTTP: "true",
341
+ REMOTE_AUTHORIZATION: "true",
342
+ GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
343
+ },
344
+ });
345
+ servers.push(server);
346
+ mcpUrl = `http://${HOST}:${mcpPort}/mcp`;
347
+ });
348
+ after(async () => {
349
+ cleanupServers(servers);
350
+ await mockGitLab?.stop();
351
+ });
352
+ test("header is ignored when the feature flag is off", async () => {
353
+ const client = await connectClient(mcpUrl, "1");
354
+ try {
355
+ assert.strictEqual(await getProjectId(client, "2"), "2");
356
+ }
357
+ finally {
358
+ await client.disconnect();
359
+ }
360
+ });
361
+ });
362
+ });
@@ -58,6 +58,7 @@ const DELETE_SAMPLE_TOOLS = [
58
58
  "delete_milestone",
59
59
  "delete_group_milestone",
60
60
  "delete_project_variable",
61
+ "delete_webhook",
61
62
  ];
62
63
  const MODIFY_SAMPLE_TOOLS = [
63
64
  "create_issue",
@@ -31,7 +31,7 @@ const TOOLSET_TOOL_COUNTS = {
31
31
  users: 7,
32
32
  search: 3,
33
33
  workitems: 18,
34
- webhooks: 3,
34
+ webhooks: 6,
35
35
  groups: 1,
36
36
  variables: 10,
37
37
  dependency_proxy: 4,
@@ -83,7 +83,7 @@ const TOOLSET_SAMPLE_TOOLS = {
83
83
  tags: ["list_tags", "create_tag", "get_tag_signature"],
84
84
  users: ["get_users", "upload_markdown", "download_attachment"],
85
85
  search: ["search_code", "search_project_code", "search_group_code"],
86
- webhooks: ["list_webhooks", "list_webhook_events", "get_webhook_event"],
86
+ webhooks: ["list_webhooks", "create_webhook", "update_webhook", "delete_webhook", "list_webhook_events", "get_webhook_event"],
87
87
  groups: ["create_group"],
88
88
  variables: ["list_project_variables", "create_project_variable", "delete_project_variable", "list_group_variables", "create_group_variable", "delete_group_variable"],
89
89
  dependency_proxy: ["get_dependency_proxy_settings", "list_dependency_proxy_blobs", "purge_dependency_proxy_cache"],
@@ -0,0 +1,218 @@
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
+ });
@@ -3,7 +3,6 @@
3
3
  * with the fixed endpoint URL construction that uses plural resource names
4
4
  * (issues instead of issue, merge_requests instead of merge_request).
5
5
  */
6
- import fetch from "node-fetch";
7
6
  // GitLab API configuration (replace with actual values when testing)
8
7
  const GITLAB_API_URL = process.env.GITLAB_API_URL || "https://gitlab.com";
9
8
  const GITLAB_PERSONAL_ACCESS_TOKEN = process.env.GITLAB_TOKEN || "";
@@ -3,7 +3,6 @@
3
3
  * It shows how to use the update_issue_note tool to resolve or unresolve
4
4
  * issue discussion threads.
5
5
  */
6
- import fetch from "node-fetch";
7
6
  // GitLab API configuration (replace with actual values when testing)
8
7
  const GITLAB_API_URL = process.env.GITLAB_API_URL || "https://gitlab.com";
9
8
  const GITLAB_PERSONAL_ACCESS_TOKEN = process.env.GITLAB_TOKEN || "";