@structured-world/gitlab-mcp 12.0.0 → 12.0.2

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 (133) hide show
  1. package/README.md +1 -1
  2. package/dist/src/config.d.ts +1 -1
  3. package/dist/src/config.js +6 -10
  4. package/dist/src/config.js.map +1 -1
  5. package/dist/src/configuration/default-project.d.ts +8 -0
  6. package/dist/src/configuration/default-project.js +83 -0
  7. package/dist/src/configuration/default-project.js.map +1 -0
  8. package/dist/src/configuration/operator-ownership.d.ts +7 -0
  9. package/dist/src/configuration/operator-ownership.js +216 -0
  10. package/dist/src/configuration/operator-ownership.js.map +1 -0
  11. package/dist/src/configuration/operator-projects.d.ts +16 -0
  12. package/dist/src/configuration/operator-projects.js +117 -0
  13. package/dist/src/configuration/operator-projects.js.map +1 -0
  14. package/dist/src/configuration/policy.d.ts +1 -0
  15. package/dist/src/configuration/policy.js +3 -0
  16. package/dist/src/configuration/policy.js.map +1 -1
  17. package/dist/src/configuration/scope-ids.js +5 -4
  18. package/dist/src/configuration/scope-ids.js.map +1 -1
  19. package/dist/src/configuration/scoped-execution.js +32 -10
  20. package/dist/src/configuration/scoped-execution.js.map +1 -1
  21. package/dist/src/entities/access_tokens/registry.js +7 -6
  22. package/dist/src/entities/access_tokens/registry.js.map +1 -1
  23. package/dist/src/entities/audit_events/registry.js +5 -4
  24. package/dist/src/entities/audit_events/registry.js.map +1 -1
  25. package/dist/src/entities/container_registry/regex.d.ts +5 -0
  26. package/dist/src/entities/container_registry/regex.js +229 -0
  27. package/dist/src/entities/container_registry/regex.js.map +1 -0
  28. package/dist/src/entities/container_registry/registry.js +30 -29
  29. package/dist/src/entities/container_registry/registry.js.map +1 -1
  30. package/dist/src/entities/container_registry/schema.js +8 -14
  31. package/dist/src/entities/container_registry/schema.js.map +1 -1
  32. package/dist/src/entities/context/scope-search.js +5 -0
  33. package/dist/src/entities/context/scope-search.js.map +1 -1
  34. package/dist/src/entities/core/project-handlers.d.ts +4 -0
  35. package/dist/src/entities/core/project-handlers.js +371 -0
  36. package/dist/src/entities/core/project-handlers.js.map +1 -0
  37. package/dist/src/entities/core/project-response.d.ts +3 -0
  38. package/dist/src/entities/core/project-response.js +27 -0
  39. package/dist/src/entities/core/project-response.js.map +1 -0
  40. package/dist/src/entities/core/registry.js +13 -464
  41. package/dist/src/entities/core/registry.js.map +1 -1
  42. package/dist/src/entities/core/schema-readonly.js +1 -1
  43. package/dist/src/entities/core/schema-readonly.js.map +1 -1
  44. package/dist/src/entities/deploy-keys/registry.js +4 -3
  45. package/dist/src/entities/deploy-keys/registry.js.map +1 -1
  46. package/dist/src/entities/environments/registry.js +3 -2
  47. package/dist/src/entities/environments/registry.js.map +1 -1
  48. package/dist/src/entities/files/registry.js +2 -1
  49. package/dist/src/entities/files/registry.js.map +1 -1
  50. package/dist/src/entities/integrations/registry.js +8 -7
  51. package/dist/src/entities/integrations/registry.js.map +1 -1
  52. package/dist/src/entities/iterations/registry.js +3 -2
  53. package/dist/src/entities/iterations/registry.js.map +1 -1
  54. package/dist/src/entities/iterations/schema-readonly.js +1 -1
  55. package/dist/src/entities/iterations/schema-readonly.js.map +1 -1
  56. package/dist/src/entities/job-token-scope/registry.js +2 -1
  57. package/dist/src/entities/job-token-scope/registry.js.map +1 -1
  58. package/dist/src/entities/members/registry.js +13 -12
  59. package/dist/src/entities/members/registry.js.map +1 -1
  60. package/dist/src/entities/members/schema-readonly.js +2 -2
  61. package/dist/src/entities/members/schema-readonly.js.map +1 -1
  62. package/dist/src/entities/members/schema.d.ts +2 -2
  63. package/dist/src/entities/members/schema.js +10 -6
  64. package/dist/src/entities/members/schema.js.map +1 -1
  65. package/dist/src/entities/milestones/registry.js +8 -7
  66. package/dist/src/entities/milestones/registry.js.map +1 -1
  67. package/dist/src/entities/milestones/schema-readonly.js +1 -1
  68. package/dist/src/entities/milestones/schema-readonly.js.map +1 -1
  69. package/dist/src/entities/milestones/schema.js +1 -1
  70. package/dist/src/entities/milestones/schema.js.map +1 -1
  71. package/dist/src/entities/mrs/registry.js +26 -25
  72. package/dist/src/entities/mrs/registry.js.map +1 -1
  73. package/dist/src/entities/mrs/schema-readonly.js +3 -3
  74. package/dist/src/entities/mrs/schema-readonly.js.map +1 -1
  75. package/dist/src/entities/mrs/schema.js +9 -6
  76. package/dist/src/entities/mrs/schema.js.map +1 -1
  77. package/dist/src/entities/pipelines/registry.js +11 -10
  78. package/dist/src/entities/pipelines/registry.js.map +1 -1
  79. package/dist/src/entities/pipelines/schema-readonly.js +5 -5
  80. package/dist/src/entities/pipelines/schema-readonly.js.map +1 -1
  81. package/dist/src/entities/pipelines/schema.js +2 -2
  82. package/dist/src/entities/pipelines/schema.js.map +1 -1
  83. package/dist/src/entities/refs/registry.js +3 -2
  84. package/dist/src/entities/refs/registry.js.map +1 -1
  85. package/dist/src/entities/releases/registry.js +5 -3
  86. package/dist/src/entities/releases/registry.js.map +1 -1
  87. package/dist/src/entities/releases/schema.js +1 -1
  88. package/dist/src/entities/releases/schema.js.map +1 -1
  89. package/dist/src/entities/runners/project-access.js +7 -2
  90. package/dist/src/entities/runners/project-access.js.map +1 -1
  91. package/dist/src/entities/runners/registry.js +2 -1
  92. package/dist/src/entities/runners/registry.js.map +1 -1
  93. package/dist/src/entities/search/registry.js +4 -3
  94. package/dist/src/entities/search/registry.js.map +1 -1
  95. package/dist/src/entities/shared.d.ts +0 -2
  96. package/dist/src/entities/shared.js +0 -2
  97. package/dist/src/entities/shared.js.map +1 -1
  98. package/dist/src/entities/snippets/registry.js +10 -8
  99. package/dist/src/entities/snippets/registry.js.map +1 -1
  100. package/dist/src/entities/snippets/schema-readonly.js +1 -1
  101. package/dist/src/entities/snippets/schema-readonly.js.map +1 -1
  102. package/dist/src/entities/snippets/schema.js +2 -2
  103. package/dist/src/entities/snippets/schema.js.map +1 -1
  104. package/dist/src/entities/utils.d.ts +1 -0
  105. package/dist/src/entities/utils.js +2 -1
  106. package/dist/src/entities/utils.js.map +1 -1
  107. package/dist/src/entities/webhooks/registry.js +10 -8
  108. package/dist/src/entities/webhooks/registry.js.map +1 -1
  109. package/dist/src/entities/webhooks/schema-readonly.js +1 -1
  110. package/dist/src/entities/webhooks/schema-readonly.js.map +1 -1
  111. package/dist/src/entities/webhooks/schema.js +3 -3
  112. package/dist/src/entities/webhooks/schema.js.map +1 -1
  113. package/dist/src/handlers.js +33 -8
  114. package/dist/src/handlers.js.map +1 -1
  115. package/dist/src/profiles/scope-enforcer.d.ts +2 -0
  116. package/dist/src/profiles/scope-enforcer.js +37 -15
  117. package/dist/src/profiles/scope-enforcer.js.map +1 -1
  118. package/dist/src/server.js +19 -0
  119. package/dist/src/server.js.map +1 -1
  120. package/dist/src/utils/api-path.d.ts +5 -0
  121. package/dist/src/utils/api-path.js +54 -0
  122. package/dist/src/utils/api-path.js.map +1 -0
  123. package/dist/src/utils/fetch.js +19 -2
  124. package/dist/src/utils/fetch.js.map +1 -1
  125. package/dist/src/utils/gitlab-api.d.ts +6 -0
  126. package/dist/src/utils/gitlab-api.js +22 -4
  127. package/dist/src/utils/gitlab-api.js.map +1 -1
  128. package/dist/src/utils/namespace.js +2 -1
  129. package/dist/src/utils/namespace.js.map +1 -1
  130. package/dist/src/utils/projectIdentifier.js +10 -12
  131. package/dist/src/utils/projectIdentifier.js.map +1 -1
  132. package/dist/tsconfig.build.tsbuildinfo +1 -1
  133. package/package.json +12 -8
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stripProjectSecrets = stripProjectSecrets;
4
+ exports.withSafeProjectResponse = withSafeProjectResponse;
5
+ function stripProjectSecrets(data) {
6
+ const pending = [data];
7
+ while (pending.length > 0) {
8
+ const value = pending.pop();
9
+ if (value === null || typeof value !== 'object')
10
+ continue;
11
+ const record = value;
12
+ delete record.runners_token;
13
+ delete record.import_url;
14
+ for (const key in record) {
15
+ if (!Object.hasOwn(record, key))
16
+ continue;
17
+ const child = record[key];
18
+ if (child !== null && typeof child === 'object')
19
+ pending.push(child);
20
+ }
21
+ }
22
+ return data;
23
+ }
24
+ function withSafeProjectResponse(handler) {
25
+ return async (args) => stripProjectSecrets(await handler(args));
26
+ }
27
+ //# sourceMappingURL=project-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-response.js","sourceRoot":"","sources":["../../../../src/entities/core/project-response.ts"],"names":[],"mappings":";;AAGA,kDAeC;AAGD,0DAIC;AAtBD,SAAgB,mBAAmB,CAAC,IAAa;IAC/C,MAAM,OAAO,GAAc,CAAC,IAAI,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAS;QAC1D,MAAM,MAAM,GAAG,KAAgC,CAAC;QAChD,OAAO,MAAM,CAAC,aAAa,CAAC;QAC5B,OAAO,MAAM,CAAC,UAAU,CAAC;QACzB,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;gBAAE,SAAS;YAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAGD,SAAgB,uBAAuB,CACrC,OAA0C;IAE1C,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,mBAAmB,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAClE,CAAC"}
@@ -43,28 +43,13 @@ const schema_1 = require("./schema");
43
43
  const fetch_1 = require("../../utils/fetch");
44
44
  const gitlab_base_url_1 = require("../../utils/gitlab-base-url");
45
45
  const projectIdentifier_1 = require("../../utils/projectIdentifier");
46
+ const api_path_1 = require("../../utils/api-path");
46
47
  const smart_user_search_1 = require("../../utils/smart-user-search");
47
48
  const idConversion_1 = require("../../utils/idConversion");
48
49
  const utils_1 = require("../utils");
49
50
  const instance_version_1 = require("../instance-version");
50
- const duo_settings_1 = require("./duo-settings");
51
- const RestoredEntitySchema = z
52
- .object({
53
- id: z.number().int().positive(),
54
- marked_for_deletion_on: z.string().nullable().optional(),
55
- })
56
- .passthrough();
57
- async function restoreEntity(apiUrl) {
58
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, { method: 'POST' });
59
- if (!response.ok) {
60
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
61
- }
62
- const restored = RestoredEntitySchema.safeParse(await response.json());
63
- if (!restored.success) {
64
- throw new Error(`GitLab API error: unexpected restore response shape (${restored.error.issues[0]?.message ?? 'invalid'})`);
65
- }
66
- return restored.data;
67
- }
51
+ const project_response_1 = require("./project-response");
52
+ const project_handlers_1 = require("./project-handlers");
68
53
  const CommitDiffsSchema = z.array(z.looseObject({
69
54
  diff: z.string(),
70
55
  old_path: z.string(),
@@ -93,141 +78,7 @@ exports.coreToolRegistry = new Map([
93
78
  marked_for_deletion_on: { tier: 'premium', minVersion: '17.1' },
94
79
  },
95
80
  },
96
- handler: async (args) => {
97
- const input = schema_readonly_1.BrowseProjectsSchema.parse(args);
98
- (0, utils_1.assertActionAllowed)('browse_projects', input.action);
99
- switch (input.action) {
100
- case 'search': {
101
- const { q, with_programming_language, visibility, order_by, sort, per_page, page } = input;
102
- const queryParams = new URLSearchParams();
103
- if (q) {
104
- let finalSearchTerms = q;
105
- const topicMatches = q.match(/topic:(\w+)/g);
106
- if (topicMatches) {
107
- const topics = topicMatches.map((match) => match.replace('topic:', ''));
108
- queryParams.set('topic', topics.join(','));
109
- finalSearchTerms = finalSearchTerms.replace(/topic:\w+/g, '').trim();
110
- }
111
- if (finalSearchTerms) {
112
- queryParams.set('search', finalSearchTerms);
113
- }
114
- }
115
- if (with_programming_language)
116
- queryParams.set('with_programming_language', with_programming_language);
117
- if (visibility)
118
- queryParams.set('visibility', visibility);
119
- if (order_by)
120
- queryParams.set('order_by', order_by);
121
- if (sort)
122
- queryParams.set('sort', sort);
123
- if (per_page)
124
- queryParams.set('per_page', String(per_page));
125
- if (page)
126
- queryParams.set('page', String(page));
127
- queryParams.set('active', 'true');
128
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects?${queryParams}`;
129
- const response = await (0, fetch_1.enhancedFetch)(apiUrl);
130
- if (!response.ok) {
131
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
132
- }
133
- const projects = await response.json();
134
- return (0, idConversion_1.cleanGidsFromObject)(projects);
135
- }
136
- case 'list': {
137
- const { group_id, search, owned, starred, membership, simple, with_programming_language, include_subgroups, with_shared, include_deleted, marked_for_deletion_on, active, visibility, archived, order_by, sort, per_page, page, } = input;
138
- const queryParams = new URLSearchParams();
139
- if (visibility)
140
- queryParams.set('visibility', visibility);
141
- if (archived !== undefined)
142
- queryParams.set('archived', String(archived));
143
- if (owned !== undefined)
144
- queryParams.set('owned', String(owned));
145
- if (starred !== undefined)
146
- queryParams.set('starred', String(starred));
147
- if (membership !== undefined)
148
- queryParams.set('membership', String(membership));
149
- if (search)
150
- queryParams.set('search', search);
151
- if (simple !== undefined)
152
- queryParams.set('simple', String(simple));
153
- if (order_by)
154
- queryParams.set('order_by', order_by);
155
- if (sort)
156
- queryParams.set('sort', sort);
157
- if (per_page)
158
- queryParams.set('per_page', String(per_page));
159
- if (page)
160
- queryParams.set('page', String(page));
161
- if (include_subgroups !== undefined)
162
- queryParams.set('include_subgroups', String(include_subgroups));
163
- if (with_shared !== undefined)
164
- queryParams.set('with_shared', String(with_shared));
165
- if (with_programming_language)
166
- queryParams.set('with_programming_language', with_programming_language);
167
- if (marked_for_deletion_on)
168
- queryParams.set('marked_for_deletion_on', marked_for_deletion_on);
169
- if (!queryParams.has('order_by'))
170
- queryParams.set('order_by', 'created_at');
171
- if (!queryParams.has('sort'))
172
- queryParams.set('sort', 'desc');
173
- if (!queryParams.has('simple'))
174
- queryParams.set('simple', 'true');
175
- if (!queryParams.has('per_page'))
176
- queryParams.set('per_page', '20');
177
- const applyActiveFilter = (value, nativeSince) => {
178
- if ((0, instance_version_1.instanceAtLeast)(nativeSince)) {
179
- queryParams.delete('archived');
180
- queryParams.set('active', String(value));
181
- }
182
- else {
183
- queryParams.delete('active');
184
- queryParams.set('archived', String(!value));
185
- }
186
- };
187
- let apiUrl;
188
- if (group_id) {
189
- if (active !== undefined)
190
- applyActiveFilter(active, '18.8');
191
- apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/groups/${(0, projectIdentifier_1.normalizeProjectId)(group_id)}/projects?${queryParams}`;
192
- }
193
- else if (include_deleted) {
194
- queryParams.set('include_pending_delete', 'true');
195
- apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects?${queryParams}`;
196
- }
197
- else if (active !== undefined) {
198
- applyActiveFilter(active, '18.5');
199
- apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects?${queryParams}`;
200
- }
201
- else {
202
- queryParams.set('active', 'true');
203
- apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects?${queryParams}`;
204
- }
205
- const response = await (0, fetch_1.enhancedFetch)(apiUrl);
206
- if (!response.ok) {
207
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
208
- }
209
- const projects = await response.json();
210
- return (0, idConversion_1.cleanGidsFromObject)(projects);
211
- }
212
- case 'get': {
213
- const { project_id, statistics, license } = input;
214
- const queryParams = new URLSearchParams();
215
- if (statistics)
216
- queryParams.set('statistics', 'true');
217
- if (license)
218
- queryParams.set('license', 'true');
219
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}?${queryParams}`;
220
- const response = await (0, fetch_1.enhancedFetch)(apiUrl);
221
- if (!response.ok) {
222
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
223
- }
224
- const project = await response.json();
225
- return (0, idConversion_1.cleanGidsFromObject)(project);
226
- }
227
- default:
228
- throw new Error(`Unknown action: ${input.action}`);
229
- }
230
- },
81
+ handler: (0, project_response_1.withSafeProjectResponse)(project_handlers_1.browseProjects),
231
82
  },
232
83
  ],
233
84
  [
@@ -237,60 +88,7 @@ exports.coreToolRegistry = new Map([
237
88
  description: 'Explore GitLab groups and user namespaces. Actions: list (discover available namespaces), get (retrieve details with storage stats), verify (check if path exists). Related: manage_namespace to create/update/delete groups.',
238
89
  inputSchema: z.toJSONSchema(schema_readonly_1.BrowseNamespacesSchema),
239
90
  requirements: { default: { tier: 'free' } },
240
- handler: async (args) => {
241
- const input = schema_readonly_1.BrowseNamespacesSchema.parse(args);
242
- (0, utils_1.assertActionAllowed)('browse_namespaces', input.action);
243
- switch (input.action) {
244
- case 'list': {
245
- const { search, owned_only, top_level_only, with_statistics, min_access_level, per_page, page, } = input;
246
- const queryParams = new URLSearchParams();
247
- if (search)
248
- queryParams.set('search', search);
249
- if (owned_only !== undefined)
250
- queryParams.set('owned_only', String(owned_only));
251
- if (top_level_only !== undefined)
252
- queryParams.set('top_level_only', String(top_level_only));
253
- if (with_statistics !== undefined)
254
- queryParams.set('with_statistics', String(with_statistics));
255
- if (min_access_level !== undefined)
256
- queryParams.set('min_access_level', String(min_access_level));
257
- if (per_page)
258
- queryParams.set('per_page', String(per_page));
259
- if (page)
260
- queryParams.set('page', String(page));
261
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/namespaces?${queryParams}`;
262
- const response = await (0, fetch_1.enhancedFetch)(apiUrl);
263
- if (!response.ok) {
264
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
265
- }
266
- const namespaces = await response.json();
267
- return (0, idConversion_1.cleanGidsFromObject)(namespaces);
268
- }
269
- case 'get': {
270
- const { namespace_id } = input;
271
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/namespaces/${encodeURIComponent(namespace_id)}`;
272
- const response = await (0, fetch_1.enhancedFetch)(apiUrl);
273
- if (!response.ok) {
274
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
275
- }
276
- const namespace = await response.json();
277
- return (0, idConversion_1.cleanGidsFromObject)(namespace);
278
- }
279
- case 'verify': {
280
- const { namespace_id } = input;
281
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/namespaces/${encodeURIComponent(namespace_id)}`;
282
- const response = await (0, fetch_1.enhancedFetch)(apiUrl);
283
- return {
284
- exists: response.ok,
285
- status: response.status,
286
- namespace: namespace_id,
287
- data: response.ok ? await response.json() : null,
288
- };
289
- }
290
- default:
291
- throw new Error(`Unknown action: ${input.action}`);
292
- }
293
- },
91
+ handler: (0, project_response_1.withSafeProjectResponse)(project_handlers_1.browseNamespaces),
294
92
  },
295
93
  ],
296
94
  [
@@ -331,7 +129,7 @@ exports.coreToolRegistry = new Map([
331
129
  queryParams.set('per_page', String(per_page));
332
130
  if (page)
333
131
  queryParams.set('page', String(page));
334
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${encodeURIComponent(project_id)}/repository/commits?${queryParams}`;
132
+ const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/repository/commits?${queryParams}`;
335
133
  const response = await (0, fetch_1.enhancedFetch)(apiUrl);
336
134
  if (!response.ok) {
337
135
  throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
@@ -343,7 +141,7 @@ exports.coreToolRegistry = new Map([
343
141
  const queryParams = new URLSearchParams();
344
142
  if (stats)
345
143
  queryParams.set('stats', 'true');
346
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${encodeURIComponent(project_id)}/repository/commits/${encodeURIComponent(sha)}?${queryParams}`;
144
+ const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/repository/commits/${encodeURIComponent(sha)}?${queryParams}`;
347
145
  const response = await (0, fetch_1.enhancedFetch)(apiUrl);
348
146
  if (!response.ok) {
349
147
  throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
@@ -360,7 +158,7 @@ exports.coreToolRegistry = new Map([
360
158
  queryParams.set('per_page', String(per_page));
361
159
  if (page)
362
160
  queryParams.set('page', String(page));
363
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${encodeURIComponent(project_id)}/repository/commits/${encodeURIComponent(sha)}/diff?${queryParams}`;
161
+ const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/repository/commits/${encodeURIComponent(sha)}/diff?${queryParams}`;
364
162
  const response = await (0, fetch_1.enhancedFetch)(apiUrl);
365
163
  if (!response.ok) {
366
164
  throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
@@ -421,7 +219,7 @@ exports.coreToolRegistry = new Map([
421
219
  case 'project': {
422
220
  const { project_id } = input;
423
221
  const queryParams = buildQueryParams(input);
424
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${encodeURIComponent(project_id)}/events?${queryParams}`;
222
+ const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/events?${queryParams}`;
425
223
  const response = await (0, fetch_1.enhancedFetch)(apiUrl);
426
224
  if (!response.ok) {
427
225
  throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
@@ -542,181 +340,7 @@ exports.coreToolRegistry = new Map([
542
340
  duo_dependency_bump_breaking_changes_enabled: { tier: 'ultimate', minVersion: '19.2' },
543
341
  },
544
342
  },
545
- handler: async (args) => {
546
- const input = schema_1.ManageProjectSchema.parse(args);
547
- (0, utils_1.assertActionAllowed)('manage_project', input.action);
548
- switch (input.action) {
549
- case 'create': {
550
- const { name, namespace, description, visibility, initialize_with_readme, issues_enabled, merge_requests_enabled, jobs_enabled, wiki_enabled, snippets_enabled, lfs_enabled, request_access_enabled, only_allow_merge_if_pipeline_succeeds, only_allow_merge_if_all_discussions_are_resolved, } = input;
551
- let namespaceId;
552
- let resolvedNamespace = null;
553
- if (namespace) {
554
- const namespaceApiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/namespaces/${encodeURIComponent(namespace)}`;
555
- const namespaceResponse = await (0, fetch_1.enhancedFetch)(namespaceApiUrl);
556
- if (namespaceResponse.ok) {
557
- resolvedNamespace = (await namespaceResponse.json());
558
- namespaceId = String(resolvedNamespace.id);
559
- }
560
- else {
561
- throw new Error(`Namespace '${namespace}' not found or not accessible`);
562
- }
563
- }
564
- const targetNamespacePath = resolvedNamespace
565
- ? resolvedNamespace.full_path
566
- : 'current-user';
567
- const projectPath = `${targetNamespacePath}/${name}`;
568
- const checkProjectUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${encodeURIComponent(projectPath)}`;
569
- const checkResponse = await (0, fetch_1.enhancedFetch)(checkProjectUrl);
570
- if (checkResponse.ok) {
571
- const existingProject = (await checkResponse.json());
572
- throw new Error(`Project '${projectPath}' already exists (ID: ${existingProject.id}).`);
573
- }
574
- const body = new URLSearchParams();
575
- body.set('name', name);
576
- const generatedPath = name
577
- .toLowerCase()
578
- .replace(/[^a-z0-9-]/g, '-')
579
- .replace(/-+/g, '-')
580
- .replace(/^-|-$/g, '');
581
- body.set('path', generatedPath);
582
- if (namespaceId)
583
- body.set('namespace_id', namespaceId);
584
- if (description)
585
- body.set('description', description);
586
- if (visibility)
587
- body.set('visibility', visibility);
588
- if (initialize_with_readme)
589
- body.set('initialize_with_readme', 'true');
590
- if (issues_enabled !== undefined)
591
- body.set('issues_enabled', String(issues_enabled));
592
- if (merge_requests_enabled !== undefined)
593
- body.set('merge_requests_enabled', String(merge_requests_enabled));
594
- if (jobs_enabled !== undefined)
595
- body.set('jobs_enabled', String(jobs_enabled));
596
- if (wiki_enabled !== undefined)
597
- body.set('wiki_enabled', String(wiki_enabled));
598
- if (snippets_enabled !== undefined)
599
- body.set('snippets_enabled', String(snippets_enabled));
600
- if (lfs_enabled !== undefined)
601
- body.set('lfs_enabled', String(lfs_enabled));
602
- if (request_access_enabled !== undefined)
603
- body.set('request_access_enabled', String(request_access_enabled));
604
- if (only_allow_merge_if_pipeline_succeeds !== undefined)
605
- body.set('only_allow_merge_if_pipeline_succeeds', String(only_allow_merge_if_pipeline_succeeds));
606
- if (only_allow_merge_if_all_discussions_are_resolved !== undefined)
607
- body.set('only_allow_merge_if_all_discussions_are_resolved', String(only_allow_merge_if_all_discussions_are_resolved));
608
- const createApiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects`;
609
- const createResponse = await (0, fetch_1.enhancedFetch)(createApiUrl, {
610
- method: 'POST',
611
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
612
- body: body.toString(),
613
- });
614
- if (!createResponse.ok) {
615
- throw new Error(`GitLab API error: ${createResponse.status} ${createResponse.statusText}`);
616
- }
617
- const project = await createResponse.json();
618
- return {
619
- ...project,
620
- validation: {
621
- namespace_resolved: namespace ? `${namespace} -> ${namespaceId}` : 'current-user',
622
- generated_path: generatedPath,
623
- },
624
- };
625
- }
626
- case 'fork': {
627
- const { project_id, namespace, namespace_path, fork_name, fork_path } = input;
628
- const body = new URLSearchParams();
629
- if (namespace)
630
- body.set('namespace', namespace);
631
- if (namespace_path)
632
- body.set('namespace_path', namespace_path);
633
- if (fork_name)
634
- body.set('name', fork_name);
635
- if (fork_path)
636
- body.set('path', fork_path);
637
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${encodeURIComponent(project_id)}/fork`;
638
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, {
639
- method: 'POST',
640
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
641
- body: body.toString(),
642
- });
643
- if (!response.ok) {
644
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
645
- }
646
- return await response.json();
647
- }
648
- case 'update': {
649
- const { project_id, action: _action, ...updateParams } = input;
650
- const body = new URLSearchParams();
651
- Object.entries(updateParams).forEach(([key, value]) => {
652
- if (value !== undefined) {
653
- body.set(key, String(value));
654
- }
655
- });
656
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}`;
657
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, {
658
- method: 'PUT',
659
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
660
- body: body.toString(),
661
- });
662
- if (!response.ok) {
663
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
664
- }
665
- return (0, duo_settings_1.withUnappliedSettings)(updateParams, await response.json(), duo_settings_1.PROJECT_DUO_SETTINGS);
666
- }
667
- case 'delete': {
668
- const { project_id } = input;
669
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}`;
670
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, { method: 'DELETE' });
671
- if (!response.ok) {
672
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
673
- }
674
- return { success: true, message: `Project ${project_id} deleted` };
675
- }
676
- case 'archive': {
677
- const { project_id } = input;
678
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/archive`;
679
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, { method: 'POST' });
680
- if (!response.ok) {
681
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
682
- }
683
- return await response.json();
684
- }
685
- case 'unarchive': {
686
- const { project_id } = input;
687
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/unarchive`;
688
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, { method: 'POST' });
689
- if (!response.ok) {
690
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
691
- }
692
- return await response.json();
693
- }
694
- case 'transfer': {
695
- const { project_id, namespace } = input;
696
- const body = new URLSearchParams();
697
- body.set('namespace', namespace);
698
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/transfer`;
699
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, {
700
- method: 'PUT',
701
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
702
- body: body.toString(),
703
- });
704
- if (!response.ok) {
705
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
706
- }
707
- return await response.json();
708
- }
709
- case 'restore': {
710
- const { project_id } = input;
711
- if ((0, instance_version_1.currentInstance)()?.tier === 'free') {
712
- (0, instance_version_1.assertInstanceAtLeast)('18.0', 'Project restore on GitLab Free');
713
- }
714
- return restoreEntity(`${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/projects/${(0, projectIdentifier_1.normalizeProjectId)(project_id)}/restore`);
715
- }
716
- default:
717
- throw new Error(`Unknown action: ${input.action}`);
718
- }
719
- },
343
+ handler: (0, project_response_1.withSafeProjectResponse)(project_handlers_1.manageProject),
720
344
  },
721
345
  ],
722
346
  [
@@ -736,82 +360,7 @@ exports.coreToolRegistry = new Map([
736
360
  auto_duo_code_review_enabled: { tier: 'premium', minVersion: '18.7' },
737
361
  },
738
362
  },
739
- handler: async (args) => {
740
- const input = schema_1.ManageNamespaceSchema.parse(args);
741
- (0, utils_1.assertActionAllowed)('manage_namespace', input.action);
742
- switch (input.action) {
743
- case 'create': {
744
- const body = new URLSearchParams();
745
- body.set('name', input.name);
746
- body.set('path', input.path);
747
- if (input.description)
748
- body.set('description', input.description);
749
- if (input.visibility)
750
- body.set('visibility', input.visibility);
751
- if (input.parent_id !== undefined)
752
- body.set('parent_id', String(input.parent_id));
753
- if (input.lfs_enabled !== undefined)
754
- body.set('lfs_enabled', String(input.lfs_enabled));
755
- if (input.request_access_enabled !== undefined)
756
- body.set('request_access_enabled', String(input.request_access_enabled));
757
- if (input.default_branch_protection !== undefined)
758
- body.set('default_branch_protection', String(input.default_branch_protection));
759
- if (input.avatar)
760
- body.set('avatar', input.avatar);
761
- if (input.membership_lock !== undefined)
762
- body.set('membership_lock', String(input.membership_lock));
763
- if (input.wiki_access_level !== undefined)
764
- body.set('wiki_access_level', input.wiki_access_level);
765
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/groups`;
766
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, {
767
- method: 'POST',
768
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
769
- body: body.toString(),
770
- });
771
- if (!response.ok) {
772
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
773
- }
774
- return await response.json();
775
- }
776
- case 'update': {
777
- const { group_id, action: _action, ...updateParams } = input;
778
- const body = new URLSearchParams();
779
- Object.entries(updateParams).forEach(([key, value]) => {
780
- if (value !== undefined) {
781
- body.set(key, String(value));
782
- }
783
- });
784
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/groups/${(0, projectIdentifier_1.normalizeProjectId)(group_id)}`;
785
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, {
786
- method: 'PUT',
787
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
788
- body: body.toString(),
789
- });
790
- if (!response.ok) {
791
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
792
- }
793
- return (0, duo_settings_1.withUnappliedSettings)(updateParams, await response.json(), duo_settings_1.GROUP_DUO_SETTINGS);
794
- }
795
- case 'delete': {
796
- const { group_id } = input;
797
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/groups/${(0, projectIdentifier_1.normalizeProjectId)(group_id)}`;
798
- const response = await (0, fetch_1.enhancedFetch)(apiUrl, { method: 'DELETE' });
799
- if (!response.ok) {
800
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
801
- }
802
- return { success: true, message: `Group ${group_id} deleted` };
803
- }
804
- case 'restore': {
805
- const { group_id } = input;
806
- if ((0, instance_version_1.currentInstance)()?.tier === 'free') {
807
- (0, instance_version_1.assertInstanceAtLeast)('18.0', 'Group restore on GitLab Free');
808
- }
809
- return restoreEntity(`${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/groups/${(0, projectIdentifier_1.normalizeProjectId)(group_id)}/restore`);
810
- }
811
- default:
812
- throw new Error(`Unknown action: ${input.action}`);
813
- }
814
- },
363
+ handler: (0, project_response_1.withSafeProjectResponse)(project_handlers_1.manageNamespace),
815
364
  },
816
365
  ],
817
366
  [
@@ -826,7 +375,7 @@ exports.coreToolRegistry = new Map([
826
375
  (0, utils_1.assertActionAllowed)('manage_todos', input.action);
827
376
  switch (input.action) {
828
377
  case 'mark_done': {
829
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/todos/${input.id}/mark_as_done`;
378
+ const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/todos/${(0, api_path_1.encodeApiSegment)(input.id)}/mark_as_done`;
830
379
  const response = await (0, fetch_1.enhancedFetch)(apiUrl, { method: 'POST' });
831
380
  if (!response.ok) {
832
381
  throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
@@ -843,7 +392,7 @@ exports.coreToolRegistry = new Map([
843
392
  return { success: true, message: 'All todos marked as done' };
844
393
  }
845
394
  case 'restore': {
846
- const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/todos/${input.id}/mark_as_pending`;
395
+ const apiUrl = `${(0, gitlab_base_url_1.getGitLabBaseUrl)()}/api/v4/todos/${(0, api_path_1.encodeApiSegment)(input.id)}/mark_as_pending`;
847
396
  const response = await (0, fetch_1.enhancedFetch)(apiUrl, { method: 'POST' });
848
397
  if (!response.ok) {
849
398
  throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);