@zereight/mcp-gitlab 2.3.22 → 2.3.23-next.209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,175 @@
1
+ import { CreateLabelSchema, DeleteLabelSchema, GetLabelSchema, ListLabelsSchema, UpdateLabelSchema, } from "../schemas.js";
2
+ import { getEffectiveApiUrl, getFetchConfig } from "../server/gitlab-request-context.js";
3
+ import { appendFilterParams } from "../utils/tool-args.js";
4
+ import { encodeGitLabPathSegment } from "../utils/url.js";
5
+ let deps;
6
+ export function configureLabelTools(next) {
7
+ deps = next;
8
+ }
9
+ function requireDeps() {
10
+ if (!deps) {
11
+ throw new Error("Label tools used before configureLabelTools()");
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
+ /**
23
+ * List labels for a project
24
+ *
25
+ * @param projectId The ID or URL-encoded path of the project
26
+ * @param options Optional parameters for listing labels
27
+ * @returns Array of GitLab labels
28
+ */
29
+ async function listLabels(projectId, options = {}) {
30
+ projectId = decodeURIComponent(projectId); // Decode project ID
31
+ // Construct the URL with project path
32
+ const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/labels`);
33
+ // Add query parameters
34
+ appendFilterParams(url.searchParams, options);
35
+ // Make the API request
36
+ const response = await fetch(url.toString(), {
37
+ ...getFetchConfig(),
38
+ });
39
+ // Handle errors
40
+ await handleGitLabError(response);
41
+ // Parse and return the data
42
+ const data = await response.json();
43
+ return data;
44
+ }
45
+ /**
46
+ * Get a single label from a project
47
+ *
48
+ * @param projectId The ID or URL-encoded path of the project
49
+ * @param labelId The ID or name of the label
50
+ * @param includeAncestorGroups Whether to include ancestor groups
51
+ * @returns GitLab label
52
+ */
53
+ async function getLabel(projectId, labelId, includeAncestorGroups) {
54
+ projectId = decodeURIComponent(projectId); // Decode project ID
55
+ const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/labels/${encodeGitLabPathSegment(String(labelId))}`);
56
+ // Add query parameters
57
+ if (includeAncestorGroups !== undefined) {
58
+ url.searchParams.append("include_ancestor_groups", includeAncestorGroups ? "true" : "false");
59
+ }
60
+ // Make the API request
61
+ const response = await fetch(url.toString(), {
62
+ ...getFetchConfig(),
63
+ });
64
+ // Handle errors
65
+ await handleGitLabError(response);
66
+ // Parse and return the data
67
+ const data = await response.json();
68
+ return data;
69
+ }
70
+ /**
71
+ * Create a new label in a project
72
+ *
73
+ * @param projectId The ID or URL-encoded path of the project
74
+ * @param options Options for creating the label
75
+ * @returns Created GitLab label
76
+ */
77
+ async function createLabel(projectId, options) {
78
+ projectId = decodeURIComponent(projectId); // Decode project ID
79
+ // Make the API request
80
+ const response = await fetch(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/labels`, {
81
+ ...getFetchConfig(),
82
+ method: "POST",
83
+ body: JSON.stringify(options),
84
+ });
85
+ // Handle errors
86
+ await handleGitLabError(response);
87
+ // Parse and return the data
88
+ const data = await response.json();
89
+ return data;
90
+ }
91
+ /**
92
+ * Update an existing label in a project
93
+ *
94
+ * @param projectId The ID or URL-encoded path of the project
95
+ * @param labelId The ID or name of the label to update
96
+ * @param options Options for updating the label
97
+ * @returns Updated GitLab label
98
+ */
99
+ async function updateLabel(projectId, labelId, options) {
100
+ projectId = decodeURIComponent(projectId); // Decode project ID
101
+ // Make the API request
102
+ const response = await fetch(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/labels/${encodeGitLabPathSegment(String(labelId))}`, {
103
+ ...getFetchConfig(),
104
+ method: "PUT",
105
+ body: JSON.stringify(options),
106
+ });
107
+ // Handle errors
108
+ await handleGitLabError(response);
109
+ // Parse and return the data
110
+ const data = await response.json();
111
+ return data;
112
+ }
113
+ /**
114
+ * Delete a label from a project
115
+ *
116
+ * @param projectId The ID or URL-encoded path of the project
117
+ * @param labelId The ID or name of the label to delete
118
+ */
119
+ async function deleteLabel(projectId, labelId) {
120
+ projectId = decodeURIComponent(projectId); // Decode project ID
121
+ // Make the API request
122
+ const response = await fetch(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(getEffectiveProjectId(projectId))}/labels/${encodeGitLabPathSegment(String(labelId))}`, {
123
+ ...getFetchConfig(),
124
+ method: "DELETE",
125
+ });
126
+ // Handle errors
127
+ await handleGitLabError(response);
128
+ }
129
+ export async function handleLabelToolCall(params) {
130
+ switch (params.name) {
131
+ case "list_labels": {
132
+ const { project_id, ...options } = ListLabelsSchema.parse(params.arguments);
133
+ const labels = await listLabels(project_id, options);
134
+ return {
135
+ content: [{ type: "text", text: JSON.stringify(labels) }],
136
+ };
137
+ }
138
+ case "get_label": {
139
+ const args = GetLabelSchema.parse(params.arguments);
140
+ const label = await getLabel(args.project_id, args.label_id, args.include_ancestor_groups);
141
+ return {
142
+ content: [{ type: "text", text: JSON.stringify(label) }],
143
+ };
144
+ }
145
+ case "create_label": {
146
+ const args = CreateLabelSchema.parse(params.arguments);
147
+ const label = await createLabel(args.project_id, args);
148
+ return {
149
+ content: [{ type: "text", text: JSON.stringify(label) }],
150
+ };
151
+ }
152
+ case "update_label": {
153
+ const args = UpdateLabelSchema.parse(params.arguments);
154
+ const { project_id, label_id, ...options } = args;
155
+ const label = await updateLabel(project_id, label_id, options);
156
+ return {
157
+ content: [{ type: "text", text: JSON.stringify(label) }],
158
+ };
159
+ }
160
+ case "delete_label": {
161
+ const args = DeleteLabelSchema.parse(params.arguments);
162
+ await deleteLabel(args.project_id, args.label_id);
163
+ return {
164
+ content: [
165
+ {
166
+ type: "text",
167
+ text: JSON.stringify({ status: "success", message: "Label deleted successfully" }),
168
+ },
169
+ ],
170
+ };
171
+ }
172
+ default:
173
+ throw new Error(`Unknown tool: ${params.name}`);
174
+ }
175
+ }