@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.
package/build/schemas.js CHANGED
@@ -1229,6 +1229,7 @@ export const GitLabCreateUpdateFileResponseSchema = z.object({
1229
1229
  export const GitLabSearchResponseSchema = z.object({
1230
1230
  count: z.coerce.number().optional(),
1231
1231
  total_pages: z.coerce.number().optional(),
1232
+ next_page: z.coerce.number().optional(),
1232
1233
  current_page: z.coerce.number().optional(),
1233
1234
  items: z.array(GitLabRepositorySchema),
1234
1235
  });
@@ -4091,6 +4092,14 @@ export const CreateTimelineEventSchema = z.object({
4091
4092
  .describe("Timeline event tags to attach. Available: 'Start time', 'End time', 'Impact detected', 'Response initiated', 'Impact mitigated', 'Cause identified'."),
4092
4093
  });
4093
4094
  // --- Webhook schemas ---
4095
+ function hasExactlyOneWebhookScope(data) {
4096
+ const hasProject = Boolean(data.project_id);
4097
+ const hasGroup = Boolean(data.group_id);
4098
+ return (hasProject || hasGroup) && !(hasProject && hasGroup);
4099
+ }
4100
+ const EXACTLY_ONE_WEBHOOK_SCOPE = {
4101
+ message: "Provide exactly one of project_id or group_id",
4102
+ };
4094
4103
  export const ListWebhooksSchema = z
4095
4104
  .object({
4096
4105
  project_id: z.coerce
@@ -4103,9 +4112,7 @@ export const ListWebhooksSchema = z
4103
4112
  .describe("Group ID or URL-encoded path. Provide either project_id or group_id, not both."),
4104
4113
  })
4105
4114
  .merge(PaginationOptionsSchema)
4106
- .refine(data => (data.project_id || data.group_id) && !(data.project_id && data.group_id), {
4107
- message: "Provide exactly one of project_id or group_id",
4108
- });
4115
+ .refine(hasExactlyOneWebhookScope, EXACTLY_ONE_WEBHOOK_SCOPE);
4109
4116
  export const ListWebhookEventsSchema = z
4110
4117
  .object({
4111
4118
  project_id: z.coerce
@@ -4128,9 +4135,7 @@ export const ListWebhookEventsSchema = z
4128
4135
  per_page: z.number().max(20).optional().default(20).describe("Number of events per page"),
4129
4136
  page: z.coerce.number().optional().describe("Page number for pagination"),
4130
4137
  })
4131
- .refine(data => (data.project_id || data.group_id) && !(data.project_id && data.group_id), {
4132
- message: "Provide exactly one of project_id or group_id",
4133
- });
4138
+ .refine(hasExactlyOneWebhookScope, EXACTLY_ONE_WEBHOOK_SCOPE);
4134
4139
  export const GetWebhookEventSchema = z
4135
4140
  .object({
4136
4141
  project_id: z.coerce
@@ -4148,9 +4153,115 @@ export const GetWebhookEventSchema = z
4148
4153
  .optional()
4149
4154
  .describe("If known, the page where the event is located (from list_webhook_events). Skips auto-pagination and fetches only this page."),
4150
4155
  })
4151
- .refine(data => (data.project_id || data.group_id) && !(data.project_id && data.group_id), {
4152
- message: "Provide exactly one of project_id or group_id",
4156
+ .refine(hasExactlyOneWebhookScope, EXACTLY_ONE_WEBHOOK_SCOPE);
4157
+ const WebhookCustomHeaderSchema = z.object({
4158
+ key: z.string().min(1).describe("Custom header name"),
4159
+ value: z.string().describe("Custom header value"),
4153
4160
  });
4161
+ const WebhookMutationFields = {
4162
+ url: z.string().url().describe("Webhook destination URL"),
4163
+ name: z.string().optional().describe("Display name for the webhook"),
4164
+ description: z.string().optional().describe("Description of the webhook"),
4165
+ token: z
4166
+ .string()
4167
+ .optional()
4168
+ .describe("Secret token to validate received payloads. Not returned by GitLab in responses."),
4169
+ signing_token: z
4170
+ .string()
4171
+ .optional()
4172
+ .describe("HMAC signing token in whsec_<base64> form, where the Base64 suffix encodes a 32-byte key. Used for the webhook-signature header. Not returned by GitLab in responses."),
4173
+ enable_ssl_verification: z
4174
+ .boolean()
4175
+ .optional()
4176
+ .describe("Verify SSL when delivering the webhook"),
4177
+ push_events: z.boolean().optional().describe("Trigger on push events"),
4178
+ push_events_branch_filter: z
4179
+ .string()
4180
+ .optional()
4181
+ .describe("Only trigger push events for matching branches"),
4182
+ branch_filter_strategy: z
4183
+ .enum(["wildcard", "regex", "all_branches"])
4184
+ .optional()
4185
+ .describe("How push_events_branch_filter is interpreted"),
4186
+ issues_events: z.boolean().optional().describe("Trigger on issue events"),
4187
+ confidential_issues_events: z
4188
+ .boolean()
4189
+ .optional()
4190
+ .describe("Trigger on confidential issue events"),
4191
+ merge_requests_events: z.boolean().optional().describe("Trigger on merge request events"),
4192
+ tag_push_events: z.boolean().optional().describe("Trigger on tag push events"),
4193
+ note_events: z.boolean().optional().describe("Trigger on note/comment events"),
4194
+ confidential_note_events: z
4195
+ .boolean()
4196
+ .optional()
4197
+ .describe("Trigger on confidential note events"),
4198
+ job_events: z.boolean().optional().describe("Trigger on job events"),
4199
+ pipeline_events: z.boolean().optional().describe("Trigger on pipeline events"),
4200
+ wiki_page_events: z.boolean().optional().describe("Trigger on wiki page events"),
4201
+ deployment_events: z.boolean().optional().describe("Trigger on deployment events"),
4202
+ feature_flag_events: z.boolean().optional().describe("Trigger on feature flag events"),
4203
+ releases_events: z.boolean().optional().describe("Trigger on release events"),
4204
+ milestone_events: z.boolean().optional().describe("Trigger on milestone events"),
4205
+ resource_access_token_events: z
4206
+ .boolean()
4207
+ .optional()
4208
+ .describe("Trigger on access token expiry events"),
4209
+ resource_deploy_token_events: z
4210
+ .boolean()
4211
+ .optional()
4212
+ .describe("Trigger on project deploy token expiry events (project webhooks)"),
4213
+ member_events: z.boolean().optional().describe("Trigger on member events (group webhooks)"),
4214
+ project_events: z.boolean().optional().describe("Trigger on project events (group webhooks)"),
4215
+ subgroup_events: z.boolean().optional().describe("Trigger on subgroup events (group webhooks)"),
4216
+ custom_webhook_template: z
4217
+ .string()
4218
+ .optional()
4219
+ .describe("Custom JSON payload template for the webhook"),
4220
+ custom_headers: z
4221
+ .array(WebhookCustomHeaderSchema)
4222
+ .optional()
4223
+ .describe("Custom HTTP headers sent with the webhook. Each item has key and value strings."),
4224
+ };
4225
+ export const CreateWebhookSchema = z
4226
+ .object({
4227
+ project_id: z.coerce
4228
+ .string()
4229
+ .optional()
4230
+ .describe("Project ID or URL-encoded path. Provide either project_id or group_id, not both."),
4231
+ group_id: z.coerce
4232
+ .string()
4233
+ .optional()
4234
+ .describe("Group ID or URL-encoded path. Provide either project_id or group_id, not both."),
4235
+ ...WebhookMutationFields,
4236
+ })
4237
+ .refine(hasExactlyOneWebhookScope, EXACTLY_ONE_WEBHOOK_SCOPE);
4238
+ export const UpdateWebhookSchema = z
4239
+ .object({
4240
+ project_id: z.coerce
4241
+ .string()
4242
+ .optional()
4243
+ .describe("Project ID or URL-encoded path. Provide either project_id or group_id, not both."),
4244
+ group_id: z.coerce
4245
+ .string()
4246
+ .optional()
4247
+ .describe("Group ID or URL-encoded path. Provide either project_id or group_id, not both."),
4248
+ hook_id: z.coerce.number().describe("ID of the webhook to update"),
4249
+ ...WebhookMutationFields,
4250
+ })
4251
+ .refine(hasExactlyOneWebhookScope, EXACTLY_ONE_WEBHOOK_SCOPE);
4252
+ export const DeleteWebhookSchema = z
4253
+ .object({
4254
+ project_id: z.coerce
4255
+ .string()
4256
+ .optional()
4257
+ .describe("Project ID or URL-encoded path. Provide either project_id or group_id, not both."),
4258
+ group_id: z.coerce
4259
+ .string()
4260
+ .optional()
4261
+ .describe("Group ID or URL-encoded path. Provide either project_id or group_id, not both."),
4262
+ hook_id: z.coerce.number().describe("ID of the webhook to delete"),
4263
+ })
4264
+ .refine(hasExactlyOneWebhookScope, EXACTLY_ONE_WEBHOOK_SCOPE);
4154
4265
  export const HealthCheckSchema = z.object({});
4155
4266
  // --- CI/CD Variable types ---
4156
4267
  export const GitLabCiVariableSchema = z.object({
@@ -101,7 +101,7 @@ const GROUP_META = {
101
101
  },
102
102
  webhooks: {
103
103
  title: "Webhooks",
104
- blurb: "List webhooks configured on projects or groups, and inspect recent webhook events.",
104
+ blurb: "Create, update, and delete project or group webhooks, and inspect recent webhook events.",
105
105
  },
106
106
  search: {
107
107
  title: "Search",
@@ -35,6 +35,9 @@ export function mintSessionId(material, input) {
35
35
  h: input.header,
36
36
  t: input.token,
37
37
  u: input.apiUrl,
38
+ ...(input.allowedProjectIds && input.allowedProjectIds.length > 0
39
+ ? { p: input.allowedProjectIds }
40
+ : {}),
38
41
  };
39
42
  return seal(material, STATELESS_PURPOSES.SESSION_ID, payload);
40
43
  }
@@ -51,7 +54,9 @@ export function openSessionId(material, sid, ttlSeconds, now) {
51
54
  payload.h !== "JOB-TOKEN") ||
52
55
  typeof payload.t !== "string" ||
53
56
  payload.t.length === 0 ||
54
- typeof payload.u !== "string") {
57
+ typeof payload.u !== "string" ||
58
+ (payload.p !== undefined &&
59
+ (!Array.isArray(payload.p) || payload.p.some(id => typeof id !== "string")))) {
55
60
  return null;
56
61
  }
57
62
  return payload;
@@ -134,5 +134,16 @@ describe('NO_PROXY Pattern Matching', () => {
134
134
  assert.strictEqual(agent1.constructor.name, 'Agent', 'Should match case-insensitively (lowercase)');
135
135
  assert.strictEqual(agent2.constructor.name, 'Agent', 'Should match case-insensitively (uppercase)');
136
136
  });
137
+ test('should re-evaluate NO_PROXY for redirect origins', () => {
138
+ const pool = new GitLabClientPool({
139
+ httpProxy: 'http://proxy.example.com:8080',
140
+ httpsProxy: 'http://proxy.example.com:8080',
141
+ noProxy: 'gitlab.internal.com',
142
+ });
143
+ const proxyToBypass = pool.getDispatcherForOrigin('https://gitlab.external.com/api/v4', 'https://gitlab.internal.com/api/v4');
144
+ const bypassToProxy = pool.getDispatcherForOrigin('https://gitlab.internal.com/api/v4', 'https://gitlab.external.com/api/v4');
145
+ assert.strictEqual(proxyToBypass.constructor.name, 'Agent', 'redirect onto NO_PROXY host should bypass');
146
+ assert.notStrictEqual(bypassToProxy.constructor.name, 'Agent', 'redirect onto proxied host should use proxy');
147
+ });
137
148
  });
138
149
  console.log('✅ NO_PROXY tests completed');
@@ -4,7 +4,6 @@
4
4
  */
5
5
  import { describe, test, after, before } from 'node:test';
6
6
  import assert from 'node:assert';
7
- import fetch from 'node-fetch';
8
7
  import { launchServer, findAvailablePort, cleanupServers, TransportMode, checkHealthEndpoint, HOST } from './utils/server-launcher.js';
9
8
  console.log('🔐 Remote Authorization Tests');
10
9
  console.log('');
@@ -19,6 +19,32 @@ function load(current, previous) {
19
19
  return m;
20
20
  }
21
21
  describe("mintSessionId / openSessionId", () => {
22
+ test("seals and restores a narrowed project scope", () => {
23
+ const s = secret();
24
+ const a = load(s);
25
+ const b = load(s);
26
+ const sid = mintSessionId(a, {
27
+ header: "Private-Token",
28
+ token: "glpat-ABCDEFG123456789-abcdef",
29
+ apiUrl: "https://gitlab.example.com/api/v4",
30
+ allowedProjectIds: ["42", "org/theorg"],
31
+ });
32
+ const opened = openSessionId(b, sid, 3600);
33
+ assert.ok(opened);
34
+ assert.deepEqual(opened.p, ["42", "org/theorg"]);
35
+ });
36
+ test("omits the scope field when no scope was narrowed", () => {
37
+ const s = secret();
38
+ const m = load(s);
39
+ const sid = mintSessionId(m, {
40
+ header: "Private-Token",
41
+ token: "glpat-ABCDEFG123456789-abcdef",
42
+ apiUrl: "https://gitlab.example.com/api/v4",
43
+ });
44
+ const opened = openSessionId(m, sid, 3600);
45
+ assert.ok(opened);
46
+ assert.equal(opened.p, undefined);
47
+ });
22
48
  test("roundtrips across pods", () => {
23
49
  const s = secret();
24
50
  const a = load(s);
@@ -6,20 +6,18 @@
6
6
  */
7
7
  import { describe, test } from "node:test";
8
8
  import assert from "node:assert";
9
- import { Headers, Response } from "node-fetch";
9
+ import { Readable } from "node:stream";
10
+ import { Response } from "undici";
10
11
  import { headersToPlainObject, isNonReplayableBody, wrapWithAuthRetry, } from "../auth-retry.js";
11
- // ---------------------------------------------------------------------------
12
- // Helpers
13
- // ---------------------------------------------------------------------------
14
12
  function mockFetch(status) {
15
- return (async () => new Response("", { status }));
13
+ return async () => new Response("", { status });
16
14
  }
17
15
  function mockFetchThenRetry() {
18
16
  let callCount = 0;
19
- return (async () => {
17
+ return async () => {
20
18
  callCount++;
21
19
  return new Response("", { status: callCount === 1 ? 401 : 200 });
22
- });
20
+ };
23
21
  }
24
22
  function makeConfig(overrides) {
25
23
  return {
@@ -30,9 +28,6 @@ function makeConfig(overrides) {
30
28
  ...overrides,
31
29
  };
32
30
  }
33
- // ---------------------------------------------------------------------------
34
- // headersToPlainObject
35
- // ---------------------------------------------------------------------------
36
31
  describe("headersToPlainObject", () => {
37
32
  test("null returns empty object", () => {
38
33
  assert.deepStrictEqual(headersToPlainObject(null), {});
@@ -63,9 +58,6 @@ describe("headersToPlainObject", () => {
63
58
  });
64
59
  });
65
60
  });
66
- // ---------------------------------------------------------------------------
67
- // isNonReplayableBody
68
- // ---------------------------------------------------------------------------
69
61
  describe("isNonReplayableBody", () => {
70
62
  test("null returns false", () => {
71
63
  assert.strictEqual(isNonReplayableBody(null), false);
@@ -85,16 +77,15 @@ describe("isNonReplayableBody", () => {
85
77
  test("object with .read() returns true (stream-like)", () => {
86
78
  assert.strictEqual(isNonReplayableBody({ read: () => { } }), true);
87
79
  });
88
- test("object with .getBuffer() and .getBoundary() returns true (FormData-like)", () => {
89
- assert.strictEqual(isNonReplayableBody({ getBuffer: () => { }, getBoundary: () => { } }), true);
90
- });
91
- test("object with only .getBuffer() (no .getBoundary()) returns false", () => {
92
- assert.strictEqual(isNonReplayableBody({ getBuffer: () => { } }), false);
80
+ test("Web ReadableStream returns true", () => {
81
+ const stream = new ReadableStream({
82
+ start(controller) {
83
+ controller.close();
84
+ },
85
+ });
86
+ assert.strictEqual(isNonReplayableBody(stream), true);
93
87
  });
94
88
  });
95
- // ---------------------------------------------------------------------------
96
- // wrapWithAuthRetry
97
- // ---------------------------------------------------------------------------
98
89
  describe("wrapWithAuthRetry", () => {
99
90
  test("non-401 response passes through unchanged", async () => {
100
91
  const wrapped = wrapWithAuthRetry(mockFetch(200), makeConfig());
@@ -137,7 +128,29 @@ describe("wrapWithAuthRetry", () => {
137
128
  });
138
129
  const wrapped = wrapWithAuthRetry(mockFetch(401), config);
139
130
  const res = await wrapped("http://example.com", {
140
- body: { pipe: () => { } }, // stream-like
131
+ body: Readable.from([]),
132
+ duplex: "half",
133
+ });
134
+ assert.strictEqual(res.status, 401);
135
+ assert.strictEqual(refreshCalled, false);
136
+ });
137
+ test("401 with Web ReadableStream body skips retry", async () => {
138
+ let refreshCalled = false;
139
+ const config = makeConfig({
140
+ refreshToken: async () => {
141
+ refreshCalled = true;
142
+ return "tok";
143
+ },
144
+ });
145
+ const stream = new ReadableStream({
146
+ start(controller) {
147
+ controller.close();
148
+ },
149
+ });
150
+ const wrapped = wrapWithAuthRetry(mockFetch(401), config);
151
+ const res = await wrapped("http://example.com", {
152
+ body: stream,
153
+ duplex: "half",
141
154
  });
142
155
  assert.strictEqual(res.status, 401);
143
156
  assert.strictEqual(refreshCalled, false);
@@ -148,27 +161,21 @@ describe("wrapWithAuthRetry", () => {
148
161
  const config = makeConfig({
149
162
  refreshToken: () => {
150
163
  refreshCount++;
151
- return new Promise((resolve) => {
164
+ return new Promise(resolve => {
152
165
  resolveRefresh = resolve;
153
166
  });
154
167
  },
155
168
  buildAuthHeaders: () => ({ Authorization: "Bearer stamped" }),
156
169
  });
157
- // Each call returns 401 first, then 200 on retry
158
170
  let callCount = 0;
159
- const base = (async () => {
171
+ const base = async () => {
160
172
  callCount++;
161
- // First two calls are the initial requests (both 401)
162
- // Next two are the retries (both 200)
163
173
  return new Response("", { status: callCount <= 2 ? 401 : 200 });
164
- });
174
+ };
165
175
  const wrapped = wrapWithAuthRetry(base, config);
166
- // Fire two concurrent requests
167
176
  const p1 = wrapped("http://example.com/a");
168
177
  const p2 = wrapped("http://example.com/b");
169
- // Wait a tick for both to hit the refresh path
170
- await new Promise((r) => setTimeout(r, 10));
171
- // Resolve the single pending refresh
178
+ await new Promise(r => setTimeout(r, 10));
172
179
  resolveRefresh("stamped-token");
173
180
  const [r1, r2] = await Promise.all([p1, p2]);
174
181
  assert.strictEqual(r1.status, 200);