@zereight/mcp-gitlab 2.3.29-next.249 → 2.3.29-next.250

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/index.js CHANGED
@@ -107,7 +107,7 @@ import { isInitializationRequestBody, isUnauthenticatedDiscoveryRequestBody, par
107
107
  export { readMcpSessionIdHeader } from "./server/request-helpers.js";
108
108
  import { authBySession, BASE_HEADERS, bindSessionProjectScope, buildAuthHeaders, configureGitLabRequestContext, getEffectiveAllowedProjectIds, getEffectiveApiUrl, getFetchConfig, SESSION_PROJECT_SCOPE_MISMATCH, sessionAuthStore, updateSessionPublicBaseUrl, usesJobTokenHeader, withPublicBaseUrl, } from "./server/gitlab-request-context.js";
109
109
  import { apiUrlUserinfoWarning, commaSplitHint, configuredApiUrlErrors, encodeGitLabPath, encodeGitLabPathSegment, invalidListEntryError, isCleartextRemoteUrl, normalizeGitLabApiUrl, parseConfiguredGitLabApiUrls, uploadFilenameForms, } from "./utils/url.js";
110
- import { estimateMergeCommitCount, filterDiffsByPatterns, openSafeOutputWriteStream, resolveDownloadRoot, readSafeExistingFile, summarizeWebhookEvents, } from "./utils/helpers.js";
110
+ import { estimateMergeCommitCount, filterDiffsByPatterns, openSafeOutputWriteStream, resolveDownloadRoot, readSafeExistingFile, } from "./utils/helpers.js";
111
111
  import { graphqlQueryContainsWriteOperation, graphqlQueryContainsDeleteOperation, } from "./utils/graphql-query.js";
112
112
  import { encodeRepoFilePayloadContent, fileOperationsIncludeDeleteOrMove, toGitLabCommitActions, } from "./utils/gitlab-commit-actions.js";
113
113
  import { redactSensitiveGitLabFields } from "./utils/redact-sensitive.js";
@@ -137,6 +137,7 @@ import { configureMilestoneTools, handleMilestoneToolCall } from "./tools/milest
137
137
  import { configureLabelTools, handleLabelToolCall } from "./tools/labels.js";
138
138
  import { configureTagTools, handleTagToolCall } from "./tools/tags.js";
139
139
  import { configureVariableTools, handleVariableToolCall } from "./tools/variables.js";
140
+ import { configureWebhookTools, handleWebhookToolCall } from "./tools/webhooks.js";
140
141
  import { buildUnavailableToolMessage, isSkippedByDiscoverActivation, } from "./tools/discover-activation.js";
141
142
  import { selectCallableHiddenToolNames, selectExposedTools } from "./tools/exposed-tools.js";
142
143
  import { createListedToolsCache, decorateToolsForList, } from "./tools/listed-tools.js";
@@ -148,7 +149,7 @@ GitLabDiscussionNoteSchema, // Added
148
149
  GitLabDiscussionSchema,
149
150
  // Draft Notes Schemas
150
151
  GitLabDraftNoteSchema, GitLabForkSchema, GitLabBranchSchema, GitLabProtectedBranchSchema, GitLabGroupSchema, GitLabIssueLinkSchema, GitLabIssueSchema, GitLabIssueWithLinkDetailsSchema, GitLabResourceLabelEventSchema, GitLabResourceStateEventSchema, GitLabMarkdownUploadSchema, GitLabMergeRequestPipelineSchema, GitLabMergeRequestSchema, GitLabNamespaceExistsResponseSchema, GitLabNamespaceSchema, GitLabPipelineJobSchema, GitLabDeploymentSchema, GitLabEnvironmentSchema, GitLabPipelineSchema, GitLabPipelineScheduleSchema, GitLabPipelineScheduleVariableSchema, GitLabPipelineSchedulePlayResultSchema, ListPipelineSchedulesSchema, GetPipelineScheduleSchema, ListPipelineSchedulePipelinesSchema, CreatePipelineScheduleSchema, UpdatePipelineScheduleSchema, DeletePipelineScheduleSchema, PlayPipelineScheduleSchema, TakeOwnershipPipelineScheduleSchema, GetPipelineScheduleVariableSchema, CreatePipelineScheduleVariableSchema, UpdatePipelineScheduleVariableSchema, DeletePipelineScheduleVariableSchema, GitLabPipelineTriggerJobSchema, GitLabProjectMemberSchema, GitLabProjectSchema, GitLabTodoSchema, GitLabReferenceSchema, GitLabRepositorySchema, GitLabSearchBlobResultSchema, GitLabSearchResponseSchema, GitLabTreeItemSchema, GitLabUserSchema, GitLabUsersResponseSchema, GroupIteration, ListCommitStatusesSchema, ListBranchesSchema, ListCommitsSchema, ListDraftNotesSchema, ListGroupIterationsSchema, GetGroupIterationSchema, UpdateGroupIterationSchema, CreateGroupIterationSchema, GroupIterationCadence, ListGroupIterationCadencesSchema, DeleteGroupIterationSchema, ListProjectIterationsSchema, CreateGroupIterationCadenceSchema, UpdateGroupIterationCadenceSchema, DeleteGroupIterationCadenceSchema, ListGroupProjectsSchema, GitLabDependencyProxySchema, GitLabDependencyProxyBlobSchema, GetDependencyProxySettingsSchema, UpdateDependencyProxySettingsSchema, ListDependencyProxyBlobsSchema, PurgeDependencyProxyCacheSchema, ListProjectVulnerabilitiesSchema, GetVulnerabilitySchema, DismissVulnerabilitySchema, ConfirmVulnerabilitySchema, ListIssueDiscussionsSchema, ListIssueLinksSchema, ListIssueLabelEventsSchema, ListIssueStateEventsSchema, ListIssuesSchema, ListTodosSchema, ListMergeRequestDiffsSchema, // Added
151
- GetMergeRequestFileDiffSchema, ListMergeRequestChangedFilesSchema, ListMergeRequestDiscussionsSchema, ListMergeRequestPipelinesSchema, ListMergeRequestsSchema, ListGroupMergeRequestsSchema, ListMergeRequestVersionsSchema, GetMergeRequestVersionSchema, GitLabMergeRequestVersionSchema, GitLabMergeRequestVersionDetailSchema, ListNamespacesSchema, ListPipelineJobsSchema, ListPipelinesSchema, ListDeploymentsSchema, ListEnvironmentsSchema, ListProjectRunnersSchema, GetRunnerSchema, ListPipelineTriggerJobsSchema, ValidateCiLintSchema, ValidateProjectCiLintSchema, ListCiCatalogResourcesSchema, GetCiCatalogResourceSchema, ListProjectMembersSchema, ListGroupMembersSchema, ListProjectsSchema, MarkdownUploadSchema, MarkdownUploadRemoteSchema, DownloadAttachmentSchema, DownloadJobArtifactsSchema, GetJobArtifactFileSchema, GitLabArtifactEntrySchema, ListJobArtifactsSchema, MergeMergeRequestSchema, ApproveMergeRequestSchema, UnapproveMergeRequestSchema, RebaseMergeRequestSchema, GetMergeRequestApprovalStateSchema, GetMergeRequestConflictsSchema, GitLabMergeRequestApprovalStateSchema, MyIssuesSchema, OrbitQuerySchema, OrbitSchemaSchema, OrbitStatusSchema, OrbitToolsSchema, MarkAllTodosDoneSchema, MarkTodoDoneSchema, PaginatedDiscussionsResponseSchema, PublishDraftNoteSchema, PlayPipelineJobSchema, PushFilesSchema, RetryPipelineJobSchema, RetryPipelineSchema, SearchCodeSchema, SearchGroupCodeSchema, SearchProjectCodeSchema, SearchRepositoriesSchema, UpdateDraftNoteSchema, UpdateIssueNoteSchema, UpdateIssueSchema, UpdateIssueDescriptionPatchSchema, ReorderIssueSchema, UpdateProjectSchema, UpdateMergeRequestNoteSchema, UpdateMergeRequestDiscussionNoteSchema, UpdateMergeRequestSchema, VerifyNamespaceSchema, GitLabEventSchema, ListEventsSchema, GetProjectEventsSchema, ExecuteGraphQLSchema, GitLabReleaseSchema, ListReleasesSchema, GetReleaseSchema, CreateReleaseSchema, UpdateReleaseSchema, DeleteReleaseSchema, CreateReleaseEvidenceSchema, DownloadReleaseAssetSchema, ListSnippetsSchema, GetSnippetSchema, CreateSnippetSchema, UpdateSnippetSchema, DeleteSnippetSchema, GitLabSnippetSchema, GetMergeRequestNotesSchema, GetMergeRequestNoteSchema, GetMergeRequestDiscussionSchema, DeleteMergeRequestDiscussionNoteSchema, ResolveMergeRequestThreadSchema, GetWorkItemSchema, ListWorkItemsSchema, CreateWorkItemSchema, UpdateWorkItemSchema, ConvertWorkItemTypeSchema, ListWorkItemStatusesSchema, ListWorkItemNotesSchema, CreateWorkItemNoteSchema, CreateWorkItemEmojiReactionSchema, CreateWorkItemNoteEmojiReactionSchema, ListWorkItemEmojiReactionsSchema, ListWorkItemNoteEmojiReactionsSchema, DeleteWorkItemEmojiReactionSchema, DeleteWorkItemNoteEmojiReactionSchema, MoveWorkItemSchema, ListCustomFieldDefinitionsSchema, GetTimelineEventsSchema, CreateTimelineEventSchema, ListWebhooksSchema, CreateWebhookSchema, UpdateWebhookSchema, DeleteWebhookSchema, ListWebhookEventsSchema, GetWebhookEventSchema, HealthCheckSchema, } from "./schemas.js";
152
+ GetMergeRequestFileDiffSchema, ListMergeRequestChangedFilesSchema, ListMergeRequestDiscussionsSchema, ListMergeRequestPipelinesSchema, ListMergeRequestsSchema, ListGroupMergeRequestsSchema, ListMergeRequestVersionsSchema, GetMergeRequestVersionSchema, GitLabMergeRequestVersionSchema, GitLabMergeRequestVersionDetailSchema, ListNamespacesSchema, ListPipelineJobsSchema, ListPipelinesSchema, ListDeploymentsSchema, ListEnvironmentsSchema, ListProjectRunnersSchema, GetRunnerSchema, ListPipelineTriggerJobsSchema, ValidateCiLintSchema, ValidateProjectCiLintSchema, ListCiCatalogResourcesSchema, GetCiCatalogResourceSchema, ListProjectMembersSchema, ListGroupMembersSchema, ListProjectsSchema, MarkdownUploadSchema, MarkdownUploadRemoteSchema, DownloadAttachmentSchema, DownloadJobArtifactsSchema, GetJobArtifactFileSchema, GitLabArtifactEntrySchema, ListJobArtifactsSchema, MergeMergeRequestSchema, ApproveMergeRequestSchema, UnapproveMergeRequestSchema, RebaseMergeRequestSchema, GetMergeRequestApprovalStateSchema, GetMergeRequestConflictsSchema, GitLabMergeRequestApprovalStateSchema, MyIssuesSchema, OrbitQuerySchema, OrbitSchemaSchema, OrbitStatusSchema, OrbitToolsSchema, MarkAllTodosDoneSchema, MarkTodoDoneSchema, PaginatedDiscussionsResponseSchema, PublishDraftNoteSchema, PlayPipelineJobSchema, PushFilesSchema, RetryPipelineJobSchema, RetryPipelineSchema, SearchCodeSchema, SearchGroupCodeSchema, SearchProjectCodeSchema, SearchRepositoriesSchema, UpdateDraftNoteSchema, UpdateIssueNoteSchema, UpdateIssueSchema, UpdateIssueDescriptionPatchSchema, ReorderIssueSchema, UpdateProjectSchema, UpdateMergeRequestNoteSchema, UpdateMergeRequestDiscussionNoteSchema, UpdateMergeRequestSchema, VerifyNamespaceSchema, GitLabEventSchema, ListEventsSchema, GetProjectEventsSchema, ExecuteGraphQLSchema, GitLabReleaseSchema, ListReleasesSchema, GetReleaseSchema, CreateReleaseSchema, UpdateReleaseSchema, DeleteReleaseSchema, CreateReleaseEvidenceSchema, DownloadReleaseAssetSchema, ListSnippetsSchema, GetSnippetSchema, CreateSnippetSchema, UpdateSnippetSchema, DeleteSnippetSchema, GitLabSnippetSchema, GetMergeRequestNotesSchema, GetMergeRequestNoteSchema, GetMergeRequestDiscussionSchema, DeleteMergeRequestDiscussionNoteSchema, ResolveMergeRequestThreadSchema, GetWorkItemSchema, ListWorkItemsSchema, CreateWorkItemSchema, UpdateWorkItemSchema, ConvertWorkItemTypeSchema, ListWorkItemStatusesSchema, ListWorkItemNotesSchema, CreateWorkItemNoteSchema, CreateWorkItemEmojiReactionSchema, CreateWorkItemNoteEmojiReactionSchema, ListWorkItemEmojiReactionsSchema, ListWorkItemNoteEmojiReactionsSchema, DeleteWorkItemEmojiReactionSchema, DeleteWorkItemNoteEmojiReactionSchema, MoveWorkItemSchema, ListCustomFieldDefinitionsSchema, GetTimelineEventsSchema, CreateTimelineEventSchema, HealthCheckSchema, } from "./schemas.js";
152
153
  import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
153
154
  import { createGraphQLAuditFailure, createToolCallAuditor, graphqlPayloadHasErrors, markToolResultAsAuditFailure, readKnownGitLabUserId, readKnownGitLabUsername, } from "./utils/audit-log.js";
154
155
  import { createLogger, flushBufferedLogs, flushStartupLogs } from "./utils/logger.js";
@@ -1005,7 +1006,7 @@ configureGitLabRequestContext({
1005
1006
  getDispatcherForUrl: apiUrl => clientPool.getDispatcherForUrl(apiUrl),
1006
1007
  getOAuthAccessToken: () => OAUTH_ACCESS_TOKEN,
1007
1008
  });
1008
- // The wiki, milestone, label, tag, and variable handlers call back into the fetch, error
1009
+ // The wiki, milestone, label, tag, variable, and webhook handlers call back into the fetch, error
1009
1010
  // handling, and project scope helpers below; fetch is read at call time because the cookie
1010
1011
  // reload replaces it.
1011
1012
  configureWikiTools({
@@ -1036,6 +1037,12 @@ configureVariableTools({
1036
1037
  getEffectiveProjectId,
1037
1038
  rejectIfProjectScopedDeployment,
1038
1039
  });
1040
+ configureWebhookTools({
1041
+ getFetch: () => fetch,
1042
+ handleGitLabError,
1043
+ getEffectiveProjectId,
1044
+ rejectIfStrictProjectScope,
1045
+ });
1039
1046
  // Create cookie jar with clean Netscape file parsing
1040
1047
  // Resolve cookie path once using os.homedir() for cross-platform support
1041
1048
  const resolvedCookiePath = GITLAB_AUTH_COOKIE_PATH
@@ -5155,126 +5162,6 @@ async function listGroupProjects(options) {
5155
5162
  const projects = await response.json();
5156
5163
  return filterProjectsByAllowlist(GitLabProjectSchema.array().parse(projects));
5157
5164
  }
5158
- // Webhook API helper functions
5159
- /**
5160
- * Build the base URL for webhooks (project or group)
5161
- */
5162
- function buildWebhookBaseUrl(projectId, groupId) {
5163
- if (projectId) {
5164
- projectId = decodeURIComponent(projectId);
5165
- return `${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/hooks`;
5166
- }
5167
- rejectIfStrictProjectScope("group webhooks");
5168
- const decodedGroupId = decodeURIComponent(groupId);
5169
- return `${getEffectiveApiUrl()}/groups/${encodeGitLabPathSegment(decodedGroupId)}/hooks`;
5170
- }
5171
- /**
5172
- * List webhooks for a project or group
5173
- */
5174
- async function listWebhooks(options) {
5175
- const url = new URL(buildWebhookBaseUrl(options.project_id, options.group_id));
5176
- if (options.page)
5177
- url.searchParams.append("page", options.page.toString());
5178
- if (options.per_page)
5179
- url.searchParams.append("per_page", options.per_page.toString());
5180
- const response = await fetch(url.toString(), { ...getFetchConfig() });
5181
- await handleGitLabError(response);
5182
- return (await response.json());
5183
- }
5184
- function buildWebhookMutationBody(options) {
5185
- const body = {};
5186
- for (const [key, value] of Object.entries(options)) {
5187
- if (key === "project_id" || key === "group_id" || key === "hook_id")
5188
- continue;
5189
- if (value !== undefined)
5190
- body[key] = value;
5191
- }
5192
- return body;
5193
- }
5194
- /**
5195
- * Create a webhook on a project or group
5196
- */
5197
- async function createWebhook(options) {
5198
- const url = buildWebhookBaseUrl(options.project_id, options.group_id);
5199
- const response = await fetch(url, {
5200
- ...getFetchConfig(),
5201
- method: "POST",
5202
- body: JSON.stringify(buildWebhookMutationBody(options)),
5203
- });
5204
- await handleGitLabError(response);
5205
- return await response.json();
5206
- }
5207
- /**
5208
- * Update a webhook on a project or group
5209
- */
5210
- async function updateWebhook(options) {
5211
- const url = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}`;
5212
- const response = await fetch(url, {
5213
- ...getFetchConfig(),
5214
- method: "PUT",
5215
- body: JSON.stringify(buildWebhookMutationBody(options)),
5216
- });
5217
- await handleGitLabError(response);
5218
- return await response.json();
5219
- }
5220
- /**
5221
- * Delete a webhook from a project or group
5222
- */
5223
- async function deleteWebhook(options) {
5224
- const url = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}`;
5225
- const response = await fetch(url, {
5226
- ...getFetchConfig(),
5227
- method: "DELETE",
5228
- });
5229
- await handleGitLabError(response);
5230
- return { status: "deleted", hook_id: options.hook_id };
5231
- }
5232
- /**
5233
- * Fetch a single page of webhook events
5234
- */
5235
- async function fetchWebhookEventsPage(baseUrl, page, perPage, status) {
5236
- const url = new URL(baseUrl);
5237
- url.searchParams.set("page", page.toString());
5238
- url.searchParams.set("per_page", perPage.toString());
5239
- if (status !== undefined)
5240
- url.searchParams.append("status", String(status));
5241
- const response = await fetch(url.toString(), { ...getFetchConfig() });
5242
- await handleGitLabError(response);
5243
- return (await response.json());
5244
- }
5245
- /**
5246
- * List webhook events for a project or group webhook
5247
- */
5248
- async function listWebhookEvents(options) {
5249
- const eventsUrl = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}/events`;
5250
- const events = await fetchWebhookEventsPage(eventsUrl, options.page ?? 1, options.per_page ?? 20, options.status);
5251
- return options.summary ? summarizeWebhookEvents(events) : events;
5252
- }
5253
- /**
5254
- * Get a specific webhook event by ID (searches up to 500 recent events)
5255
- */
5256
- async function getWebhookEvent(options) {
5257
- const eventsUrl = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}/events`;
5258
- // GitLab enforces max per_page=20 for webhook events
5259
- const perPage = 20;
5260
- if (options.page) {
5261
- // Direct page lookup — single API call
5262
- const events = await fetchWebhookEventsPage(eventsUrl, options.page, perPage);
5263
- const match = events.find(e => e.id === options.event_id);
5264
- return match ?? null;
5265
- }
5266
- // Auto-paginate up to 500 events
5267
- const maxPages = 25;
5268
- for (let page = 1; page <= maxPages; page++) {
5269
- const events = await fetchWebhookEventsPage(eventsUrl, page, perPage);
5270
- const match = events.find(e => e.id === options.event_id);
5271
- if (match)
5272
- return match;
5273
- if (events.length < perPage)
5274
- break;
5275
- }
5276
- return null;
5277
- }
5278
5165
  /**
5279
5166
  * List pipelines in a GitLab project
5280
5167
  *
@@ -10482,61 +10369,13 @@ async function handleToolCall(params) {
10482
10369
  ],
10483
10370
  };
10484
10371
  }
10485
- case "list_webhooks": {
10486
- const args = ListWebhooksSchema.parse(params.arguments);
10487
- const webhooks = await listWebhooks(args);
10488
- return {
10489
- content: [{ type: "text", text: JSON.stringify(webhooks) }],
10490
- };
10491
- }
10492
- case "create_webhook": {
10493
- const args = CreateWebhookSchema.parse(params.arguments);
10494
- const webhook = await createWebhook(args);
10495
- return {
10496
- content: [{ type: "text", text: JSON.stringify(webhook) }],
10497
- };
10498
- }
10499
- case "update_webhook": {
10500
- const args = UpdateWebhookSchema.parse(params.arguments);
10501
- const webhook = await updateWebhook(args);
10502
- return {
10503
- content: [{ type: "text", text: JSON.stringify(webhook) }],
10504
- };
10505
- }
10506
- case "delete_webhook": {
10507
- const args = DeleteWebhookSchema.parse(params.arguments);
10508
- const result = await deleteWebhook(args);
10509
- return {
10510
- content: [{ type: "text", text: JSON.stringify(result) }],
10511
- };
10512
- }
10513
- case "list_webhook_events": {
10514
- const args = ListWebhookEventsSchema.parse(params.arguments);
10515
- const events = await listWebhookEvents(args);
10516
- return {
10517
- content: [{ type: "text", text: JSON.stringify(events) }],
10518
- };
10519
- }
10520
- case "get_webhook_event": {
10521
- const args = GetWebhookEventSchema.parse(params.arguments);
10522
- const event = await getWebhookEvent(args);
10523
- if (!event) {
10524
- const searchScope = args.page ? `on page ${args.page}` : "in the 500 most recent events";
10525
- return {
10526
- content: [
10527
- {
10528
- type: "text",
10529
- text: JSON.stringify({
10530
- error: `Webhook event ${args.event_id} not found ${searchScope}`,
10531
- }),
10532
- },
10533
- ],
10534
- };
10535
- }
10536
- return {
10537
- content: [{ type: "text", text: JSON.stringify(event) }],
10538
- };
10539
- }
10372
+ case "list_webhooks":
10373
+ case "create_webhook":
10374
+ case "update_webhook":
10375
+ case "delete_webhook":
10376
+ case "list_webhook_events":
10377
+ case "get_webhook_event":
10378
+ return await handleWebhookToolCall(params);
10540
10379
  case "health_check": {
10541
10380
  HealthCheckSchema.parse(params.arguments ?? {});
10542
10381
  const url = new URL(`${getEffectiveApiUrl()}/user`);
@@ -0,0 +1,205 @@
1
+ import { CreateWebhookSchema, DeleteWebhookSchema, GetWebhookEventSchema, ListWebhookEventsSchema, ListWebhooksSchema, UpdateWebhookSchema, } from "../schemas.js";
2
+ import { getEffectiveApiUrl, getFetchConfig } from "../server/gitlab-request-context.js";
3
+ import { encodeGitLabPathSegment } from "../utils/url.js";
4
+ import { summarizeWebhookEvents } from "../utils/helpers.js";
5
+ let deps;
6
+ export function configureWebhookTools(next) {
7
+ deps = next;
8
+ }
9
+ function requireDeps() {
10
+ if (!deps) {
11
+ throw new Error("Webhook tools used before configureWebhookTools()");
12
+ }
13
+ return deps;
14
+ }
15
+ const fetch = (input, init) => requireDeps().getFetch()(input, init);
16
+ function handleGitLabError(response) {
17
+ return requireDeps().handleGitLabError(response);
18
+ }
19
+ function getEffectiveProjectId(projectId) {
20
+ return requireDeps().getEffectiveProjectId(projectId);
21
+ }
22
+ function rejectIfStrictProjectScope(toolName) {
23
+ requireDeps().rejectIfStrictProjectScope(toolName);
24
+ }
25
+ // Webhook API helper functions
26
+ /**
27
+ * Build the base URL for webhooks (project or group)
28
+ */
29
+ function buildWebhookBaseUrl(projectId, groupId) {
30
+ if (projectId) {
31
+ projectId = decodeURIComponent(projectId);
32
+ return `${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/hooks`;
33
+ }
34
+ rejectIfStrictProjectScope("group webhooks");
35
+ const decodedGroupId = decodeURIComponent(groupId);
36
+ return `${getEffectiveApiUrl()}/groups/${encodeGitLabPathSegment(decodedGroupId)}/hooks`;
37
+ }
38
+ /**
39
+ * List webhooks for a project or group
40
+ */
41
+ async function listWebhooks(options) {
42
+ const url = new URL(buildWebhookBaseUrl(options.project_id, options.group_id));
43
+ if (options.page)
44
+ url.searchParams.append("page", options.page.toString());
45
+ if (options.per_page)
46
+ url.searchParams.append("per_page", options.per_page.toString());
47
+ const response = await fetch(url.toString(), { ...getFetchConfig() });
48
+ await handleGitLabError(response);
49
+ return (await response.json());
50
+ }
51
+ function buildWebhookMutationBody(options) {
52
+ const body = {};
53
+ for (const [key, value] of Object.entries(options)) {
54
+ if (key === "project_id" || key === "group_id" || key === "hook_id")
55
+ continue;
56
+ if (value !== undefined)
57
+ body[key] = value;
58
+ }
59
+ return body;
60
+ }
61
+ /**
62
+ * Create a webhook on a project or group
63
+ */
64
+ async function createWebhook(options) {
65
+ const url = buildWebhookBaseUrl(options.project_id, options.group_id);
66
+ const response = await fetch(url, {
67
+ ...getFetchConfig(),
68
+ method: "POST",
69
+ body: JSON.stringify(buildWebhookMutationBody(options)),
70
+ });
71
+ await handleGitLabError(response);
72
+ return await response.json();
73
+ }
74
+ /**
75
+ * Update a webhook on a project or group
76
+ */
77
+ async function updateWebhook(options) {
78
+ const url = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}`;
79
+ const response = await fetch(url, {
80
+ ...getFetchConfig(),
81
+ method: "PUT",
82
+ body: JSON.stringify(buildWebhookMutationBody(options)),
83
+ });
84
+ await handleGitLabError(response);
85
+ return await response.json();
86
+ }
87
+ /**
88
+ * Delete a webhook from a project or group
89
+ */
90
+ async function deleteWebhook(options) {
91
+ const url = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}`;
92
+ const response = await fetch(url, {
93
+ ...getFetchConfig(),
94
+ method: "DELETE",
95
+ });
96
+ await handleGitLabError(response);
97
+ return { status: "deleted", hook_id: options.hook_id };
98
+ }
99
+ /**
100
+ * Fetch a single page of webhook events
101
+ */
102
+ async function fetchWebhookEventsPage(baseUrl, page, perPage, status) {
103
+ const url = new URL(baseUrl);
104
+ url.searchParams.set("page", page.toString());
105
+ url.searchParams.set("per_page", perPage.toString());
106
+ if (status !== undefined)
107
+ url.searchParams.append("status", String(status));
108
+ const response = await fetch(url.toString(), { ...getFetchConfig() });
109
+ await handleGitLabError(response);
110
+ return (await response.json());
111
+ }
112
+ /**
113
+ * List webhook events for a project or group webhook
114
+ */
115
+ async function listWebhookEvents(options) {
116
+ const eventsUrl = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}/events`;
117
+ const events = await fetchWebhookEventsPage(eventsUrl, options.page ?? 1, options.per_page ?? 20, options.status);
118
+ return options.summary ? summarizeWebhookEvents(events) : events;
119
+ }
120
+ /**
121
+ * Get a specific webhook event by ID (searches up to 500 recent events)
122
+ */
123
+ async function getWebhookEvent(options) {
124
+ const eventsUrl = `${buildWebhookBaseUrl(options.project_id, options.group_id)}/${options.hook_id}/events`;
125
+ // GitLab enforces max per_page=20 for webhook events
126
+ const perPage = 20;
127
+ if (options.page) {
128
+ // Direct page lookup — single API call
129
+ const events = await fetchWebhookEventsPage(eventsUrl, options.page, perPage);
130
+ const match = events.find(e => e.id === options.event_id);
131
+ return match ?? null;
132
+ }
133
+ // Auto-paginate up to 500 events
134
+ const maxPages = 25;
135
+ for (let page = 1; page <= maxPages; page++) {
136
+ const events = await fetchWebhookEventsPage(eventsUrl, page, perPage);
137
+ const match = events.find(e => e.id === options.event_id);
138
+ if (match)
139
+ return match;
140
+ if (events.length < perPage)
141
+ break;
142
+ }
143
+ return null;
144
+ }
145
+ export async function handleWebhookToolCall(params) {
146
+ switch (params.name) {
147
+ case "list_webhooks": {
148
+ const args = ListWebhooksSchema.parse(params.arguments);
149
+ const webhooks = await listWebhooks(args);
150
+ return {
151
+ content: [{ type: "text", text: JSON.stringify(webhooks) }],
152
+ };
153
+ }
154
+ case "create_webhook": {
155
+ const args = CreateWebhookSchema.parse(params.arguments);
156
+ const webhook = await createWebhook(args);
157
+ return {
158
+ content: [{ type: "text", text: JSON.stringify(webhook) }],
159
+ };
160
+ }
161
+ case "update_webhook": {
162
+ const args = UpdateWebhookSchema.parse(params.arguments);
163
+ const webhook = await updateWebhook(args);
164
+ return {
165
+ content: [{ type: "text", text: JSON.stringify(webhook) }],
166
+ };
167
+ }
168
+ case "delete_webhook": {
169
+ const args = DeleteWebhookSchema.parse(params.arguments);
170
+ const result = await deleteWebhook(args);
171
+ return {
172
+ content: [{ type: "text", text: JSON.stringify(result) }],
173
+ };
174
+ }
175
+ case "list_webhook_events": {
176
+ const args = ListWebhookEventsSchema.parse(params.arguments);
177
+ const events = await listWebhookEvents(args);
178
+ return {
179
+ content: [{ type: "text", text: JSON.stringify(events) }],
180
+ };
181
+ }
182
+ case "get_webhook_event": {
183
+ const args = GetWebhookEventSchema.parse(params.arguments);
184
+ const event = await getWebhookEvent(args);
185
+ if (!event) {
186
+ const searchScope = args.page ? `on page ${args.page}` : "in the 500 most recent events";
187
+ return {
188
+ content: [
189
+ {
190
+ type: "text",
191
+ text: JSON.stringify({
192
+ error: `Webhook event ${args.event_id} not found ${searchScope}`,
193
+ }),
194
+ },
195
+ ],
196
+ };
197
+ }
198
+ return {
199
+ content: [{ type: "text", text: JSON.stringify(event) }],
200
+ };
201
+ }
202
+ default:
203
+ throw new Error(`Unknown tool: ${params.name}`);
204
+ }
205
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zereight/mcp-gitlab",
3
- "version": "2.3.29-next.249",
3
+ "version": "2.3.29-next.250",
4
4
  "mcpName": "io.github.zereight/gitlab-mcp",
5
5
  "description": "GitLab MCP server for projects, merge requests, issues, pipelines, wiki, releases, and more",
6
6
  "keywords": [