@zereight/mcp-gitlab 2.3.28-next.244 → 2.3.28-next.245

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
@@ -123,7 +123,7 @@ import { fetchStatusBeforeDeadline } from "./utils/poll-deadline.js";
123
123
  import { getUniqueApprovalUsers, inferMergeRequestApproved, MERGE_REQUEST_DEPLOYMENT_SUMMARY_LIMIT, parseApprovalsResponse, sortDeploymentsByCreatedAtDesc, toMergeRequestDeploymentSummaryRecord, } from "./utils/merge-request-summary.js";
124
124
  import { parseGitLabVersionApiResponse, } from "./utils/gitlab-instance-version.js";
125
125
  import { buildBulkPublishDraftNotesBody, needsGitLab19_2BulkPublish, } from "./utils/bulk-publish-options.js";
126
- import { appendFilterParam, appendFilterParams, cleanMutuallyExclusiveIdUsernameOptions, dropBlankArrayEntries, isBlankFilterValue, LIST_MERGE_REQUESTS_ID_USERNAME_PAIRS, sanitizeToolArguments, } from "./utils/tool-args.js";
126
+ import { appendFilterParams, cleanMutuallyExclusiveIdUsernameOptions, dropBlankArrayEntries, isBlankFilterValue, LIST_MERGE_REQUESTS_ID_USERNAME_PAIRS, sanitizeToolArguments, } from "./utils/tool-args.js";
127
127
  import { applyJmespathToToolResult, getJmespathSyntaxError, JMESPATH_TOOL_ARGUMENT, JMESPATH_TOOL_ARGUMENT_DESCRIPTION, omitJmespathArgument, readJmespathExpression, } from "./utils/jmespath-tool-result.js";
128
128
  import { appendRecoveryHint, withRecoveryHint } from "./utils/error-hints.js";
129
129
  import { applyListSummaryToToolResult, omitListSummaryArgument, readListSummaryRequested, toolAcceptsDecoratedSummary, toolUsesListSummaryDefault, } from "./utils/list-summary.js";
@@ -136,6 +136,7 @@ import { configureWikiTools, handleWikiToolCall } from "./tools/wiki.js";
136
136
  import { configureMilestoneTools, handleMilestoneToolCall } from "./tools/milestones.js";
137
137
  import { configureLabelTools, handleLabelToolCall } from "./tools/labels.js";
138
138
  import { configureTagTools, handleTagToolCall } from "./tools/tags.js";
139
+ import { configureVariableTools, handleVariableToolCall } from "./tools/variables.js";
139
140
  import { buildUnavailableToolMessage, isSkippedByDiscoverActivation, } from "./tools/discover-activation.js";
140
141
  import { selectCallableHiddenToolNames, selectExposedTools } from "./tools/exposed-tools.js";
141
142
  import { createListedToolsCache, decorateToolsForList, } from "./tools/listed-tools.js";
@@ -146,7 +147,7 @@ import { BulkPublishDraftNotesSchema, CancelPipelineJobSchema, ErasePipelineJobS
146
147
  GitLabDiscussionNoteSchema, // Added
147
148
  GitLabDiscussionSchema,
148
149
  // Draft Notes Schemas
149
- GitLabDraftNoteSchema, GitLabForkSchema, GitLabBranchSchema, GitLabProtectedBranchSchema, GitLabGroupSchema, GitLabIssueLinkSchema, GitLabIssueSchema, GitLabIssueWithLinkDetailsSchema, 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, GitLabCiVariableSchema, ListProjectVariablesSchema, GetProjectVariableSchema, CreateProjectVariableSchema, UpdateProjectVariableSchema, DeleteProjectVariableSchema, ListGroupVariablesSchema, GetGroupVariableSchema, CreateGroupVariableSchema, UpdateGroupVariableSchema, DeleteGroupVariableSchema, GitLabDependencyProxySchema, GitLabDependencyProxyBlobSchema, GetDependencyProxySettingsSchema, UpdateDependencyProxySettingsSchema, ListDependencyProxyBlobsSchema, PurgeDependencyProxyCacheSchema, ListProjectVulnerabilitiesSchema, GetVulnerabilitySchema, DismissVulnerabilitySchema, ConfirmVulnerabilitySchema, ListIssueDiscussionsSchema, ListIssueLinksSchema, ListIssuesSchema, ListTodosSchema, ListMergeRequestDiffsSchema, // Added
150
+ GitLabDraftNoteSchema, GitLabForkSchema, GitLabBranchSchema, GitLabProtectedBranchSchema, GitLabGroupSchema, GitLabIssueLinkSchema, GitLabIssueSchema, GitLabIssueWithLinkDetailsSchema, 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, ListIssuesSchema, ListTodosSchema, ListMergeRequestDiffsSchema, // Added
150
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";
151
152
  import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
152
153
  import { createGraphQLAuditFailure, createToolCallAuditor, graphqlPayloadHasErrors, markToolResultAsAuditFailure, readKnownGitLabUserId, readKnownGitLabUsername, } from "./utils/audit-log.js";
@@ -1004,8 +1005,9 @@ configureGitLabRequestContext({
1004
1005
  getDispatcherForUrl: apiUrl => clientPool.getDispatcherForUrl(apiUrl),
1005
1006
  getOAuthAccessToken: () => OAUTH_ACCESS_TOKEN,
1006
1007
  });
1007
- // The wiki, milestone, label, and tag handlers call back into the fetch, error handling, and
1008
- // project scope helpers below; fetch is read at call time because the cookie reload replaces it.
1008
+ // The wiki, milestone, label, tag, and variable handlers call back into the fetch, error
1009
+ // handling, and project scope helpers below; fetch is read at call time because the cookie
1010
+ // reload replaces it.
1009
1011
  configureWikiTools({
1010
1012
  getFetch: () => fetch,
1011
1013
  handleGitLabError,
@@ -1028,6 +1030,12 @@ configureTagTools({
1028
1030
  handleGitLabError,
1029
1031
  getEffectiveProjectId,
1030
1032
  });
1033
+ configureVariableTools({
1034
+ getFetch: () => fetch,
1035
+ handleGitLabError,
1036
+ getEffectiveProjectId,
1037
+ rejectIfProjectScopedDeployment,
1038
+ });
1031
1039
  // Create cookie jar with clean Netscape file parsing
1032
1040
  // Resolve cookie path once using os.homedir() for cross-platform support
1033
1041
  const resolvedCookiePath = GITLAB_AUTH_COOKIE_PATH
@@ -6960,131 +6968,6 @@ async function deleteGroupIterationCadence(cadenceId) {
6960
6968
  throw new Error(`Failed to delete iteration cadence: ${data.iterationCadenceDestroy.errors.join(", ")}`);
6961
6969
  }
6962
6970
  }
6963
- // --- CI/CD Variables ---
6964
- async function listProjectVariables(projectId, options = {}) {
6965
- projectId = decodeURIComponent(projectId);
6966
- const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables`);
6967
- Object.entries(options).forEach(([key, value]) => {
6968
- if (key === "filter" && typeof value === "object" && value !== null) {
6969
- Object.entries(value).forEach(([filterKey, filterValue]) => {
6970
- appendFilterParam(url.searchParams, `filter[${filterKey}]`, filterValue);
6971
- });
6972
- return;
6973
- }
6974
- appendFilterParam(url.searchParams, key, value);
6975
- });
6976
- const response = await fetch(url.toString(), getFetchConfig());
6977
- await handleGitLabError(response);
6978
- const data = await response.json();
6979
- return z.array(GitLabCiVariableSchema).parse(data);
6980
- }
6981
- async function getProjectVariable(projectId, key, filter) {
6982
- projectId = decodeURIComponent(projectId);
6983
- const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables/${encodeGitLabPathSegment(key)}`);
6984
- if (filter?.environment_scope) {
6985
- url.searchParams.append("filter[environment_scope]", filter.environment_scope);
6986
- }
6987
- const response = await fetch(url.toString(), getFetchConfig());
6988
- await handleGitLabError(response);
6989
- const data = await response.json();
6990
- return GitLabCiVariableSchema.parse(data);
6991
- }
6992
- async function createProjectVariable(projectId, options) {
6993
- projectId = decodeURIComponent(projectId);
6994
- const response = await fetch(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables`, { ...getFetchConfig(), method: "POST", body: JSON.stringify(options) });
6995
- await handleGitLabError(response);
6996
- const data = await response.json();
6997
- return GitLabCiVariableSchema.parse(data);
6998
- }
6999
- async function updateProjectVariable(projectId, key, options) {
7000
- projectId = decodeURIComponent(projectId);
7001
- const { filter, ...body } = options;
7002
- const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables/${encodeGitLabPathSegment(key)}`);
7003
- if (filter?.environment_scope) {
7004
- url.searchParams.append("filter[environment_scope]", filter.environment_scope);
7005
- }
7006
- const response = await fetch(url.toString(), {
7007
- ...getFetchConfig(),
7008
- method: "PUT",
7009
- body: JSON.stringify(body),
7010
- });
7011
- await handleGitLabError(response);
7012
- const data = await response.json();
7013
- return GitLabCiVariableSchema.parse(data);
7014
- }
7015
- async function deleteProjectVariable(projectId, key, filter) {
7016
- projectId = decodeURIComponent(projectId);
7017
- const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables/${encodeGitLabPathSegment(key)}`);
7018
- if (filter?.environment_scope) {
7019
- url.searchParams.append("filter[environment_scope]", filter.environment_scope);
7020
- }
7021
- const response = await fetch(url.toString(), { ...getFetchConfig(), method: "DELETE" });
7022
- await handleGitLabError(response);
7023
- }
7024
- async function listGroupVariables(groupId, options = {}) {
7025
- const encoded = encodeGitLabPathSegment(groupId);
7026
- const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables`);
7027
- Object.entries(options).forEach(([key, value]) => {
7028
- if (key === "filter" && typeof value === "object" && value !== null) {
7029
- Object.entries(value).forEach(([filterKey, filterValue]) => {
7030
- appendFilterParam(url.searchParams, `filter[${filterKey}]`, filterValue);
7031
- });
7032
- return;
7033
- }
7034
- appendFilterParam(url.searchParams, key, value);
7035
- });
7036
- const response = await fetch(url.toString(), getFetchConfig());
7037
- await handleGitLabError(response);
7038
- const data = await response.json();
7039
- return z.array(GitLabCiVariableSchema).parse(data);
7040
- }
7041
- async function getGroupVariable(groupId, key, filter) {
7042
- const encoded = encodeGitLabPathSegment(groupId);
7043
- const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables/${encodeGitLabPathSegment(key)}`);
7044
- if (filter?.environment_scope) {
7045
- url.searchParams.append("filter[environment_scope]", filter.environment_scope);
7046
- }
7047
- const response = await fetch(url.toString(), getFetchConfig());
7048
- await handleGitLabError(response);
7049
- const data = await response.json();
7050
- return GitLabCiVariableSchema.parse(data);
7051
- }
7052
- async function createGroupVariable(groupId, options) {
7053
- const encoded = encodeGitLabPathSegment(groupId);
7054
- const response = await fetch(`${getEffectiveApiUrl()}/groups/${encoded}/variables`, {
7055
- ...getFetchConfig(),
7056
- method: "POST",
7057
- body: JSON.stringify(options),
7058
- });
7059
- await handleGitLabError(response);
7060
- const data = await response.json();
7061
- return GitLabCiVariableSchema.parse(data);
7062
- }
7063
- async function updateGroupVariable(groupId, key, options) {
7064
- const encoded = encodeGitLabPathSegment(groupId);
7065
- const { filter, ...body } = options;
7066
- const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables/${encodeGitLabPathSegment(key)}`);
7067
- if (filter?.environment_scope) {
7068
- url.searchParams.append("filter[environment_scope]", filter.environment_scope);
7069
- }
7070
- const response = await fetch(url.toString(), {
7071
- ...getFetchConfig(),
7072
- method: "PUT",
7073
- body: JSON.stringify(body),
7074
- });
7075
- await handleGitLabError(response);
7076
- const data = await response.json();
7077
- return GitLabCiVariableSchema.parse(data);
7078
- }
7079
- async function deleteGroupVariable(groupId, key, filter) {
7080
- const encoded = encodeGitLabPathSegment(groupId);
7081
- const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables/${encodeGitLabPathSegment(key)}`);
7082
- if (filter?.environment_scope) {
7083
- url.searchParams.append("filter[environment_scope]", filter.environment_scope);
7084
- }
7085
- const response = await fetch(url.toString(), { ...getFetchConfig(), method: "DELETE" });
7086
- await handleGitLabError(response);
7087
- }
7088
6971
  // --- Dependency Proxy ---
7089
6972
  async function resolveGroupFullPath(groupId) {
7090
6973
  const decoded = decodeURIComponent(groupId);
@@ -10161,88 +10044,17 @@ async function handleToolCall(params) {
10161
10044
  ],
10162
10045
  };
10163
10046
  }
10164
- // --- CI/CD Variables ---
10165
- case "list_project_variables": {
10166
- const args = ListProjectVariablesSchema.parse(params.arguments);
10167
- const { project_id, ...options } = args;
10168
- const variables = await listProjectVariables(project_id, options);
10169
- return { content: [{ type: "text", text: JSON.stringify(variables) }] };
10170
- }
10171
- case "get_project_variable": {
10172
- const args = GetProjectVariableSchema.parse(params.arguments);
10173
- const variable = await getProjectVariable(args.project_id, args.key, args.filter);
10174
- return { content: [{ type: "text", text: JSON.stringify(variable) }] };
10175
- }
10176
- case "create_project_variable": {
10177
- const args = CreateProjectVariableSchema.parse(params.arguments);
10178
- const { project_id, ...options } = args;
10179
- const variable = await createProjectVariable(project_id, options);
10180
- return { content: [{ type: "text", text: JSON.stringify(variable) }] };
10181
- }
10182
- case "update_project_variable": {
10183
- const args = UpdateProjectVariableSchema.parse(params.arguments);
10184
- const { project_id, key, ...options } = args;
10185
- const variable = await updateProjectVariable(project_id, key, options);
10186
- return { content: [{ type: "text", text: JSON.stringify(variable) }] };
10187
- }
10188
- case "delete_project_variable": {
10189
- const args = DeleteProjectVariableSchema.parse(params.arguments);
10190
- await deleteProjectVariable(args.project_id, args.key, args.filter);
10191
- return {
10192
- content: [
10193
- {
10194
- type: "text",
10195
- text: JSON.stringify({
10196
- status: "success",
10197
- message: `Variable '${args.key}' deleted from project`,
10198
- }),
10199
- },
10200
- ],
10201
- };
10202
- }
10203
- case "list_group_variables": {
10204
- rejectIfProjectScopedDeployment("list_group_variables");
10205
- const args = ListGroupVariablesSchema.parse(params.arguments);
10206
- const { group_id, ...options } = args;
10207
- const variables = await listGroupVariables(group_id, options);
10208
- return { content: [{ type: "text", text: JSON.stringify(variables) }] };
10209
- }
10210
- case "get_group_variable": {
10211
- rejectIfProjectScopedDeployment("get_group_variable");
10212
- const args = GetGroupVariableSchema.parse(params.arguments);
10213
- const variable = await getGroupVariable(args.group_id, args.key, args.filter);
10214
- return { content: [{ type: "text", text: JSON.stringify(variable) }] };
10215
- }
10216
- case "create_group_variable": {
10217
- rejectIfProjectScopedDeployment("create_group_variable");
10218
- const args = CreateGroupVariableSchema.parse(params.arguments);
10219
- const { group_id, ...options } = args;
10220
- const variable = await createGroupVariable(group_id, options);
10221
- return { content: [{ type: "text", text: JSON.stringify(variable) }] };
10222
- }
10223
- case "update_group_variable": {
10224
- rejectIfProjectScopedDeployment("update_group_variable");
10225
- const args = UpdateGroupVariableSchema.parse(params.arguments);
10226
- const { group_id, key, ...options } = args;
10227
- const variable = await updateGroupVariable(group_id, key, options);
10228
- return { content: [{ type: "text", text: JSON.stringify(variable) }] };
10229
- }
10230
- case "delete_group_variable": {
10231
- rejectIfProjectScopedDeployment("delete_group_variable");
10232
- const args = DeleteGroupVariableSchema.parse(params.arguments);
10233
- await deleteGroupVariable(args.group_id, args.key, args.filter);
10234
- return {
10235
- content: [
10236
- {
10237
- type: "text",
10238
- text: JSON.stringify({
10239
- status: "success",
10240
- message: `Variable '${args.key}' deleted from group`,
10241
- }),
10242
- },
10243
- ],
10244
- };
10245
- }
10047
+ case "list_project_variables":
10048
+ case "get_project_variable":
10049
+ case "create_project_variable":
10050
+ case "update_project_variable":
10051
+ case "delete_project_variable":
10052
+ case "list_group_variables":
10053
+ case "get_group_variable":
10054
+ case "create_group_variable":
10055
+ case "update_group_variable":
10056
+ case "delete_group_variable":
10057
+ return await handleVariableToolCall(params);
10246
10058
  case "get_dependency_proxy_settings": {
10247
10059
  rejectIfProjectScopedDeployment("get_dependency_proxy_settings");
10248
10060
  const args = GetDependencyProxySettingsSchema.parse(params.arguments);
@@ -0,0 +1,237 @@
1
+ import { z } from "zod";
2
+ import { CreateGroupVariableSchema, CreateProjectVariableSchema, DeleteGroupVariableSchema, DeleteProjectVariableSchema, GetGroupVariableSchema, GetProjectVariableSchema, GitLabCiVariableSchema, ListGroupVariablesSchema, ListProjectVariablesSchema, UpdateGroupVariableSchema, UpdateProjectVariableSchema, } from "../schemas.js";
3
+ import { getEffectiveApiUrl, getFetchConfig } from "../server/gitlab-request-context.js";
4
+ import { appendFilterParam } from "../utils/tool-args.js";
5
+ import { encodeGitLabPathSegment } from "../utils/url.js";
6
+ let deps;
7
+ export function configureVariableTools(next) {
8
+ deps = next;
9
+ }
10
+ function requireDeps() {
11
+ if (!deps) {
12
+ throw new Error("Variable tools used before configureVariableTools()");
13
+ }
14
+ return deps;
15
+ }
16
+ const fetch = (input, init) => requireDeps().getFetch()(input, init);
17
+ function handleGitLabError(response) {
18
+ return requireDeps().handleGitLabError(response);
19
+ }
20
+ function getEffectiveProjectId(projectId) {
21
+ return requireDeps().getEffectiveProjectId(projectId);
22
+ }
23
+ function rejectIfProjectScopedDeployment(toolName) {
24
+ requireDeps().rejectIfProjectScopedDeployment(toolName);
25
+ }
26
+ // --- CI/CD Variables ---
27
+ async function listProjectVariables(projectId, options = {}) {
28
+ projectId = decodeURIComponent(projectId);
29
+ const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables`);
30
+ Object.entries(options).forEach(([key, value]) => {
31
+ if (key === "filter" && typeof value === "object" && value !== null) {
32
+ Object.entries(value).forEach(([filterKey, filterValue]) => {
33
+ appendFilterParam(url.searchParams, `filter[${filterKey}]`, filterValue);
34
+ });
35
+ return;
36
+ }
37
+ appendFilterParam(url.searchParams, key, value);
38
+ });
39
+ const response = await fetch(url.toString(), getFetchConfig());
40
+ await handleGitLabError(response);
41
+ const data = await response.json();
42
+ return z.array(GitLabCiVariableSchema).parse(data);
43
+ }
44
+ async function getProjectVariable(projectId, key, filter) {
45
+ projectId = decodeURIComponent(projectId);
46
+ const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables/${encodeGitLabPathSegment(key)}`);
47
+ if (filter?.environment_scope) {
48
+ url.searchParams.append("filter[environment_scope]", filter.environment_scope);
49
+ }
50
+ const response = await fetch(url.toString(), getFetchConfig());
51
+ await handleGitLabError(response);
52
+ const data = await response.json();
53
+ return GitLabCiVariableSchema.parse(data);
54
+ }
55
+ async function createProjectVariable(projectId, options) {
56
+ projectId = decodeURIComponent(projectId);
57
+ const response = await fetch(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables`, { ...getFetchConfig(), method: "POST", body: JSON.stringify(options) });
58
+ await handleGitLabError(response);
59
+ const data = await response.json();
60
+ return GitLabCiVariableSchema.parse(data);
61
+ }
62
+ async function updateProjectVariable(projectId, key, options) {
63
+ projectId = decodeURIComponent(projectId);
64
+ const { filter, ...body } = options;
65
+ const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables/${encodeGitLabPathSegment(key)}`);
66
+ if (filter?.environment_scope) {
67
+ url.searchParams.append("filter[environment_scope]", filter.environment_scope);
68
+ }
69
+ const response = await fetch(url.toString(), {
70
+ ...getFetchConfig(),
71
+ method: "PUT",
72
+ body: JSON.stringify(body),
73
+ });
74
+ await handleGitLabError(response);
75
+ const data = await response.json();
76
+ return GitLabCiVariableSchema.parse(data);
77
+ }
78
+ async function deleteProjectVariable(projectId, key, filter) {
79
+ projectId = decodeURIComponent(projectId);
80
+ const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/variables/${encodeGitLabPathSegment(key)}`);
81
+ if (filter?.environment_scope) {
82
+ url.searchParams.append("filter[environment_scope]", filter.environment_scope);
83
+ }
84
+ const response = await fetch(url.toString(), { ...getFetchConfig(), method: "DELETE" });
85
+ await handleGitLabError(response);
86
+ }
87
+ async function listGroupVariables(groupId, options = {}) {
88
+ const encoded = encodeGitLabPathSegment(groupId);
89
+ const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables`);
90
+ Object.entries(options).forEach(([key, value]) => {
91
+ if (key === "filter" && typeof value === "object" && value !== null) {
92
+ Object.entries(value).forEach(([filterKey, filterValue]) => {
93
+ appendFilterParam(url.searchParams, `filter[${filterKey}]`, filterValue);
94
+ });
95
+ return;
96
+ }
97
+ appendFilterParam(url.searchParams, key, value);
98
+ });
99
+ const response = await fetch(url.toString(), getFetchConfig());
100
+ await handleGitLabError(response);
101
+ const data = await response.json();
102
+ return z.array(GitLabCiVariableSchema).parse(data);
103
+ }
104
+ async function getGroupVariable(groupId, key, filter) {
105
+ const encoded = encodeGitLabPathSegment(groupId);
106
+ const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables/${encodeGitLabPathSegment(key)}`);
107
+ if (filter?.environment_scope) {
108
+ url.searchParams.append("filter[environment_scope]", filter.environment_scope);
109
+ }
110
+ const response = await fetch(url.toString(), getFetchConfig());
111
+ await handleGitLabError(response);
112
+ const data = await response.json();
113
+ return GitLabCiVariableSchema.parse(data);
114
+ }
115
+ async function createGroupVariable(groupId, options) {
116
+ const encoded = encodeGitLabPathSegment(groupId);
117
+ const response = await fetch(`${getEffectiveApiUrl()}/groups/${encoded}/variables`, {
118
+ ...getFetchConfig(),
119
+ method: "POST",
120
+ body: JSON.stringify(options),
121
+ });
122
+ await handleGitLabError(response);
123
+ const data = await response.json();
124
+ return GitLabCiVariableSchema.parse(data);
125
+ }
126
+ async function updateGroupVariable(groupId, key, options) {
127
+ const encoded = encodeGitLabPathSegment(groupId);
128
+ const { filter, ...body } = options;
129
+ const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables/${encodeGitLabPathSegment(key)}`);
130
+ if (filter?.environment_scope) {
131
+ url.searchParams.append("filter[environment_scope]", filter.environment_scope);
132
+ }
133
+ const response = await fetch(url.toString(), {
134
+ ...getFetchConfig(),
135
+ method: "PUT",
136
+ body: JSON.stringify(body),
137
+ });
138
+ await handleGitLabError(response);
139
+ const data = await response.json();
140
+ return GitLabCiVariableSchema.parse(data);
141
+ }
142
+ async function deleteGroupVariable(groupId, key, filter) {
143
+ const encoded = encodeGitLabPathSegment(groupId);
144
+ const url = new URL(`${getEffectiveApiUrl()}/groups/${encoded}/variables/${encodeGitLabPathSegment(key)}`);
145
+ if (filter?.environment_scope) {
146
+ url.searchParams.append("filter[environment_scope]", filter.environment_scope);
147
+ }
148
+ const response = await fetch(url.toString(), { ...getFetchConfig(), method: "DELETE" });
149
+ await handleGitLabError(response);
150
+ }
151
+ export async function handleVariableToolCall(params) {
152
+ switch (params.name) {
153
+ case "list_project_variables": {
154
+ const args = ListProjectVariablesSchema.parse(params.arguments);
155
+ const { project_id, ...options } = args;
156
+ const variables = await listProjectVariables(project_id, options);
157
+ return { content: [{ type: "text", text: JSON.stringify(variables) }] };
158
+ }
159
+ case "get_project_variable": {
160
+ const args = GetProjectVariableSchema.parse(params.arguments);
161
+ const variable = await getProjectVariable(args.project_id, args.key, args.filter);
162
+ return { content: [{ type: "text", text: JSON.stringify(variable) }] };
163
+ }
164
+ case "create_project_variable": {
165
+ const args = CreateProjectVariableSchema.parse(params.arguments);
166
+ const { project_id, ...options } = args;
167
+ const variable = await createProjectVariable(project_id, options);
168
+ return { content: [{ type: "text", text: JSON.stringify(variable) }] };
169
+ }
170
+ case "update_project_variable": {
171
+ const args = UpdateProjectVariableSchema.parse(params.arguments);
172
+ const { project_id, key, ...options } = args;
173
+ const variable = await updateProjectVariable(project_id, key, options);
174
+ return { content: [{ type: "text", text: JSON.stringify(variable) }] };
175
+ }
176
+ case "delete_project_variable": {
177
+ const args = DeleteProjectVariableSchema.parse(params.arguments);
178
+ await deleteProjectVariable(args.project_id, args.key, args.filter);
179
+ return {
180
+ content: [
181
+ {
182
+ type: "text",
183
+ text: JSON.stringify({
184
+ status: "success",
185
+ message: `Variable '${args.key}' deleted from project`,
186
+ }),
187
+ },
188
+ ],
189
+ };
190
+ }
191
+ case "list_group_variables": {
192
+ rejectIfProjectScopedDeployment("list_group_variables");
193
+ const args = ListGroupVariablesSchema.parse(params.arguments);
194
+ const { group_id, ...options } = args;
195
+ const variables = await listGroupVariables(group_id, options);
196
+ return { content: [{ type: "text", text: JSON.stringify(variables) }] };
197
+ }
198
+ case "get_group_variable": {
199
+ rejectIfProjectScopedDeployment("get_group_variable");
200
+ const args = GetGroupVariableSchema.parse(params.arguments);
201
+ const variable = await getGroupVariable(args.group_id, args.key, args.filter);
202
+ return { content: [{ type: "text", text: JSON.stringify(variable) }] };
203
+ }
204
+ case "create_group_variable": {
205
+ rejectIfProjectScopedDeployment("create_group_variable");
206
+ const args = CreateGroupVariableSchema.parse(params.arguments);
207
+ const { group_id, ...options } = args;
208
+ const variable = await createGroupVariable(group_id, options);
209
+ return { content: [{ type: "text", text: JSON.stringify(variable) }] };
210
+ }
211
+ case "update_group_variable": {
212
+ rejectIfProjectScopedDeployment("update_group_variable");
213
+ const args = UpdateGroupVariableSchema.parse(params.arguments);
214
+ const { group_id, key, ...options } = args;
215
+ const variable = await updateGroupVariable(group_id, key, options);
216
+ return { content: [{ type: "text", text: JSON.stringify(variable) }] };
217
+ }
218
+ case "delete_group_variable": {
219
+ rejectIfProjectScopedDeployment("delete_group_variable");
220
+ const args = DeleteGroupVariableSchema.parse(params.arguments);
221
+ await deleteGroupVariable(args.group_id, args.key, args.filter);
222
+ return {
223
+ content: [
224
+ {
225
+ type: "text",
226
+ text: JSON.stringify({
227
+ status: "success",
228
+ message: `Variable '${args.key}' deleted from group`,
229
+ }),
230
+ },
231
+ ],
232
+ };
233
+ }
234
+ default:
235
+ throw new Error(`Unknown tool: ${params.name}`);
236
+ }
237
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zereight/mcp-gitlab",
3
- "version": "2.3.28-next.244",
3
+ "version": "2.3.28-next.245",
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": [