@zereight/mcp-gitlab 2.1.70 → 2.2.0

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 (157) hide show
  1. package/README.ko.md +3 -1
  2. package/README.md +6 -2
  3. package/README.pt-BR.md +1 -1
  4. package/README.zh-CN.md +3 -1
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +47 -0
  7. package/build/index.js +369 -184
  8. package/build/oauth-device-flow.js +80 -0
  9. package/build/oauth.js +135 -18
  10. package/build/schemas.js +1 -1
  11. package/build/server/remote-http-stack.js +39 -0
  12. package/build/tools/discover-activation.js +38 -0
  13. package/build/tools/exposed-tools.js +35 -0
  14. package/build/tools/listed-tools.js +76 -0
  15. package/build/tools/registry.js +226 -57
  16. package/build/tools/tool-profile.js +66 -0
  17. package/build/utils/compact-tool-allowlist.js +14 -0
  18. package/build/utils/logger.js +34 -12
  19. package/package.json +3 -3
  20. package/build/scripts/check-skill-sync.js +0 -143
  21. package/build/scripts/generate-server-card.js +0 -39
  22. package/build/scripts/generate-tool-coverage.js +0 -58
  23. package/build/scripts/generate-tool-docs.js +0 -430
  24. package/build/scripts/tool-coverage/coverage.js +0 -341
  25. package/build/scripts/tool-coverage/coverage.test.js +0 -142
  26. package/build/test/callback-proxy-tests.js +0 -321
  27. package/build/test/cli/args.test.js +0 -175
  28. package/build/test/cli/boolean-flags.test.js +0 -106
  29. package/build/test/cli/compact-mcp-result.test.js +0 -93
  30. package/build/test/cli/credentials.test.js +0 -153
  31. package/build/test/cli/exposure.test.js +0 -104
  32. package/build/test/cli/load-config-snapshot.js +0 -5
  33. package/build/test/cli/output.test.js +0 -74
  34. package/build/test/cli/replay-command.test.js +0 -37
  35. package/build/test/cli/router.test.js +0 -183
  36. package/build/test/client-pool-test.js +0 -109
  37. package/build/test/clients/client.js +0 -34
  38. package/build/test/clients/custom-header-client.js +0 -122
  39. package/build/test/clients/sse-client.js +0 -95
  40. package/build/test/clients/stdio-client.js +0 -113
  41. package/build/test/clients/streamable-http-client.js +0 -95
  42. package/build/test/config-allowed-groups.test.js +0 -97
  43. package/build/test/create-commit-actions.test.js +0 -102
  44. package/build/test/draft-note-schema.test.js +0 -44
  45. package/build/test/dynamic-api-url-allowlist.test.js +0 -121
  46. package/build/test/dynamic-api-url-test.js +0 -304
  47. package/build/test/dynamic-routing-tests.js +0 -495
  48. package/build/test/get-merge-request-discussion-schema.test.js +0 -30
  49. package/build/test/gitlab-api-tool-errors.test.js +0 -112
  50. package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
  51. package/build/test/gitlab-diff-schema.test.js +0 -36
  52. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  53. package/build/test/gitlab-tag-schema.test.js +0 -51
  54. package/build/test/group-milestone-schema.test.js +0 -45
  55. package/build/test/mcp-oauth-tests.js +0 -905
  56. package/build/test/mcp-server-name.test.js +0 -87
  57. package/build/test/merge-merge-request-schema.test.js +0 -75
  58. package/build/test/multi-server-test.js +0 -190
  59. package/build/test/no-proxy-integration-test.js +0 -183
  60. package/build/test/no-proxy-test.js +0 -149
  61. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  62. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  63. package/build/test/oauth-device-flow-tests.js +0 -450
  64. package/build/test/oauth-download-url.test.js +0 -157
  65. package/build/test/oauth-startup.test.js +0 -204
  66. package/build/test/oauth-tests.js +0 -428
  67. package/build/test/path-segment-encoding.test.js +0 -98
  68. package/build/test/remote-auth-simple-test.js +0 -277
  69. package/build/test/remote-auth-tests.js +0 -314
  70. package/build/test/response-masking.test.js +0 -445
  71. package/build/test/schema-tests.js +0 -1679
  72. package/build/test/server/metrics.test.js +0 -47
  73. package/build/test/server/request-helpers.test.js +0 -48
  74. package/build/test/server/version.test.js +0 -13
  75. package/build/test/sse-auth-guard.test.js +0 -96
  76. package/build/test/sse-session-limits.test.js +0 -273
  77. package/build/test/stateless/callback-proxy.test.js +0 -510
  78. package/build/test/stateless/client-id.test.js +0 -177
  79. package/build/test/stateless/codec.test.js +0 -328
  80. package/build/test/stateless/config-ttl.test.js +0 -149
  81. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  82. package/build/test/stateless/session-id-integration.test.js +0 -675
  83. package/build/test/stateless/session-id.test.js +0 -157
  84. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  85. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  86. package/build/test/streamable-http-sse-stream.test.js +0 -350
  87. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  88. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  89. package/build/test/test-all-transport-server.js +0 -255
  90. package/build/test/test-auth-retry.js +0 -195
  91. package/build/test/test-blank-filters.js +0 -156
  92. package/build/test/test-ci-catalog.js +0 -177
  93. package/build/test/test-ci-lint.js +0 -191
  94. package/build/test/test-ci-variables.js +0 -309
  95. package/build/test/test-create-repository.js +0 -120
  96. package/build/test/test-dependency-proxy.js +0 -195
  97. package/build/test/test-deployment-tools.js +0 -463
  98. package/build/test/test-download-attachment.js +0 -190
  99. package/build/test/test-dynamic-project-scope.js +0 -524
  100. package/build/test/test-empty-toolsets.js +0 -535
  101. package/build/test/test-get-file-blame.js +0 -145
  102. package/build/test/test-get-file-contents.js +0 -128
  103. package/build/test/test-geteffectiveprojectid.js +0 -804
  104. package/build/test/test-health-check.js +0 -115
  105. package/build/test/test-issue-description-patch.js +0 -256
  106. package/build/test/test-job-artifacts.js +0 -275
  107. package/build/test/test-json-schema.js +0 -166
  108. package/build/test/test-list-group-members.js +0 -150
  109. package/build/test/test-list-group-merge-requests.js +0 -165
  110. package/build/test/test-list-issues.js +0 -170
  111. package/build/test/test-list-merge-requests.js +0 -201
  112. package/build/test/test-list-milestones.js +0 -145
  113. package/build/test/test-list-project-members.js +0 -132
  114. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  115. package/build/test/test-merge-request-approvals.js +0 -187
  116. package/build/test/test-merge-request-pipelines.js +0 -106
  117. package/build/test/test-mr-diffs-filter.js +0 -132
  118. package/build/test/test-mr-file-diffs.js +0 -251
  119. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  120. package/build/test/test-orbit.js +0 -155
  121. package/build/test/test-permission-mode.js +0 -424
  122. package/build/test/test-pipeline-schedules.js +0 -484
  123. package/build/test/test-protected-branches.js +0 -174
  124. package/build/test/test-remote-downloads.js +0 -510
  125. package/build/test/test-search-code.js +0 -275
  126. package/build/test/test-snippets.js +0 -735
  127. package/build/test/test-tags.js +0 -220
  128. package/build/test/test-todos.js +0 -195
  129. package/build/test/test-token-optimizations.js +0 -691
  130. package/build/test/test-toolset-filtering.js +0 -499
  131. package/build/test/test-update-issue-slim.js +0 -141
  132. package/build/test/test-update-project.js +0 -112
  133. package/build/test/test-upload-markdown.js +0 -206
  134. package/build/test/test-vulnerabilities.js +0 -399
  135. package/build/test/test-webhooks.js +0 -218
  136. package/build/test/tool-description-quality.test.js +0 -50
  137. package/build/test/utils/bulk-publish-options.test.js +0 -32
  138. package/build/test/utils/download-token.test.js +0 -35
  139. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  140. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  141. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  142. package/build/test/utils/graphql-query.test.js +0 -168
  143. package/build/test/utils/helpers-path.test.js +0 -104
  144. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  145. package/build/test/utils/masking.test.js +0 -384
  146. package/build/test/utils/merge-request-position.test.js +0 -57
  147. package/build/test/utils/mock-gitlab-server.js +0 -614
  148. package/build/test/utils/proxy-client-ip.test.js +0 -28
  149. package/build/test/utils/redact-sensitive.test.js +0 -32
  150. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  151. package/build/test/utils/server-launcher.js +0 -231
  152. package/build/test/utils/tool-args.test.js +0 -210
  153. package/build/test/utils/url.test.js +0 -141
  154. package/build/test/utils/version-check.test.js +0 -239
  155. package/build/test/utils/wiki-title.test.js +0 -21
  156. package/build/test-note.js +0 -54
  157. package/build/test-resolve-issue-note.js +0 -127
@@ -1,499 +0,0 @@
1
- /**
2
- * Toolset Filtering Test Suite
3
- *
4
- * Tests GITLAB_TOOLSETS, GITLAB_TOOLS, and their interaction with
5
- * legacy flags (USE_GITLAB_WIKI, USE_PIPELINE, USE_MILESTONE),
6
- * GITLAB_READ_ONLY_MODE, and GITLAB_DENIED_TOOLS_REGEX.
7
- */
8
- import { describe, test, after, before } from "node:test";
9
- import assert from "node:assert";
10
- import { launchServer, findAvailablePort, cleanupServers, TransportMode, HOST, } from "./utils/server-launcher.js";
11
- import { MockGitLabServer, findMockServerPort, } from "./utils/mock-gitlab-server.js";
12
- import { CustomHeaderClient } from "./clients/custom-header-client.js";
13
- const MOCK_TOKEN = "glpat-toolset-test-token";
14
- // Port bases (offset from other test suites to avoid collisions)
15
- const MOCK_PORT_BASE = 9200;
16
- const MCP_PORT_BASE = 3200;
17
- // Known tool counts per toolset (from TOOLSET_DEFINITIONS)
18
- const TOOLSET_TOOL_COUNTS = {
19
- merge_requests: 43,
20
- issues: 24,
21
- repositories: 7,
22
- branches: 15,
23
- projects: 11,
24
- labels: 5,
25
- ci: 4,
26
- pipelines: 56,
27
- milestones: 17,
28
- wiki: 10,
29
- releases: 7,
30
- tags: 5,
31
- snippets: 5,
32
- users: 7,
33
- search: 3,
34
- workitems: 18,
35
- webhooks: 6,
36
- groups: 1,
37
- variables: 10,
38
- dependency_proxy: 4,
39
- vulnerabilities: 4,
40
- orbit: 4,
41
- };
42
- const LEGACY_PIPELINE_CI_TOOL_COUNT = 2;
43
- const LEGACY_PIPELINE_TOOL_COUNT = TOOLSET_TOOL_COUNTS.pipelines + LEGACY_PIPELINE_CI_TOOL_COUNT;
44
- const DEFAULT_TOOLSETS = [
45
- "merge_requests",
46
- "issues",
47
- "repositories",
48
- "branches",
49
- "projects",
50
- "labels",
51
- "ci",
52
- "users",
53
- "groups",
54
- ];
55
- const NON_DEFAULT_TOOLSETS = [
56
- "pipelines",
57
- "milestones",
58
- "wiki",
59
- "releases",
60
- "tags",
61
- "snippets",
62
- "workitems",
63
- "webhooks",
64
- "search",
65
- "variables",
66
- "dependency_proxy",
67
- "vulnerabilities",
68
- "orbit",
69
- ];
70
- // discover_tools meta-tool is always force-injected (Step 5.5)
71
- const DISCOVER_TOOLS_COUNT = 1;
72
- const DEFAULT_TOOL_COUNT = DEFAULT_TOOLSETS.reduce((sum, id) => sum + TOOLSET_TOOL_COUNTS[id], 0) + DISCOVER_TOOLS_COUNT;
73
- const ALL_TOOLSET_TOOL_COUNT = Object.values(TOOLSET_TOOL_COUNTS).reduce((sum, c) => sum + c, 0) + DISCOVER_TOOLS_COUNT;
74
- // Representative tools per toolset for spot-checking
75
- const TOOLSET_SAMPLE_TOOLS = {
76
- merge_requests: ["merge_merge_request", "create_merge_request_thread", "list_draft_notes"],
77
- issues: ["create_issue", "list_issues", "create_note", "list_todos"],
78
- repositories: ["search_repositories", "get_file_contents", "push_files"],
79
- branches: ["create_branch", "get_branch", "list_branches", "delete_branch", "list_commits", "list_commit_statuses", "create_commit_status"],
80
- projects: ["get_project", "update_project", "list_namespaces", "list_group_iterations"],
81
- labels: ["list_labels", "create_label"],
82
- ci: ["validate_ci_lint", "validate_project_ci_lint", "list_ci_catalog_resources", "get_ci_catalog_resource"],
83
- pipelines: ["list_pipelines", "create_pipeline", "cancel_pipeline_job", "list_deployments", "list_job_artifacts"],
84
- milestones: ["list_milestones", "create_milestone", "list_group_milestones", "get_group_milestone_burndown_events"],
85
- wiki: ["list_wiki_pages", "create_wiki_page", "list_group_wiki_pages", "create_group_wiki_page"],
86
- releases: ["list_releases", "create_release", "download_release_asset"],
87
- tags: ["list_tags", "create_tag", "get_tag_signature"],
88
- snippets: ["list_snippets", "create_snippet", "update_snippet"],
89
- users: ["get_users", "upload_markdown", "download_attachment"],
90
- search: ["search_code", "search_project_code", "search_group_code"],
91
- webhooks: ["list_webhooks", "create_webhook", "update_webhook", "delete_webhook", "list_webhook_events", "get_webhook_event"],
92
- groups: ["create_group"],
93
- variables: ["list_project_variables", "create_project_variable", "delete_project_variable", "list_group_variables", "create_group_variable", "delete_group_variable"],
94
- dependency_proxy: ["get_dependency_proxy_settings", "list_dependency_proxy_blobs", "purge_dependency_proxy_cache"],
95
- };
96
- // --- Helpers ---
97
- async function launchMcpServer(mockGitLabUrl, mcpPort, extraEnv = {}) {
98
- return launchServer({
99
- mode: TransportMode.STREAMABLE_HTTP,
100
- port: mcpPort,
101
- timeout: 10000,
102
- env: {
103
- STREAMABLE_HTTP: "true",
104
- REMOTE_AUTHORIZATION: "true",
105
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
106
- ...extraEnv,
107
- },
108
- });
109
- }
110
- async function getToolNames(mcpUrl) {
111
- const client = new CustomHeaderClient({
112
- authorization: `Bearer ${MOCK_TOKEN}`,
113
- });
114
- await client.connect(mcpUrl);
115
- const result = await client.listTools();
116
- await client.disconnect();
117
- return result.tools.map((t) => t.name);
118
- }
119
- function assertContainsAll(actual, expected, label) {
120
- for (const name of expected) {
121
- assert.ok(actual.includes(name), `${label}: expected tool "${name}" to be present`);
122
- }
123
- }
124
- function assertContainsNone(actual, excluded, label) {
125
- for (const name of excluded) {
126
- assert.ok(!actual.includes(name), `${label}: expected tool "${name}" to be absent`);
127
- }
128
- }
129
- // --- Tests ---
130
- let mockGitLab;
131
- let mockGitLabUrl;
132
- let portCounter = 0;
133
- async function nextMcpPort() {
134
- return findAvailablePort(MCP_PORT_BASE + portCounter++ * 10);
135
- }
136
- describe("Toolset Filtering", { concurrency: 1 }, () => {
137
- before(async () => {
138
- const mockPort = await findMockServerPort();
139
- mockGitLab = new MockGitLabServer({
140
- port: mockPort,
141
- validTokens: [MOCK_TOKEN],
142
- });
143
- await mockGitLab.start();
144
- mockGitLabUrl = mockGitLab.getUrl();
145
- console.log(`Mock GitLab: ${mockGitLabUrl}`);
146
- });
147
- after(async () => {
148
- if (mockGitLab)
149
- await mockGitLab.stop();
150
- });
151
- // ---- 1. Default behavior (no GITLAB_TOOLSETS / GITLAB_TOOLS) ----
152
- describe("defaults (no GITLAB_TOOLSETS)", () => {
153
- let server;
154
- let tools;
155
- before(async () => {
156
- const port = await nextMcpPort();
157
- server = await launchMcpServer(mockGitLabUrl, port);
158
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
159
- });
160
- after(() => cleanupServers([server]));
161
- test("returns expected default tool count", () => {
162
- assert.strictEqual(tools.length, DEFAULT_TOOL_COUNT);
163
- });
164
- test("includes tools from every default toolset", () => {
165
- for (const id of DEFAULT_TOOLSETS) {
166
- assertContainsAll(tools, TOOLSET_SAMPLE_TOOLS[id], id);
167
- }
168
- });
169
- test("excludes non-default toolsets (search, pipelines, wiki)", () => {
170
- assertContainsNone(tools, TOOLSET_SAMPLE_TOOLS.search, "non-default search");
171
- assertContainsNone(tools, TOOLSET_SAMPLE_TOOLS.pipelines, "non-default pipelines");
172
- assertContainsNone(tools, TOOLSET_SAMPLE_TOOLS.wiki, "non-default wiki");
173
- });
174
- test("excludes execute_graphql (not in any toolset)", () => {
175
- assertContainsNone(tools, ["execute_graphql"], "unassigned");
176
- });
177
- });
178
- // ---- 2. Single toolset ----
179
- describe("GITLAB_TOOLSETS=issues", () => {
180
- let server;
181
- let tools;
182
- before(async () => {
183
- const port = await nextMcpPort();
184
- server = await launchMcpServer(mockGitLabUrl, port, {
185
- GITLAB_TOOLSETS: "issues",
186
- });
187
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
188
- });
189
- after(() => cleanupServers([server]));
190
- test("returns only issue tools + discover_tools", () => {
191
- assert.strictEqual(tools.length, TOOLSET_TOOL_COUNTS.issues + DISCOVER_TOOLS_COUNT);
192
- });
193
- test("includes issue sample tools", () => {
194
- assertContainsAll(tools, TOOLSET_SAMPLE_TOOLS.issues, "issues");
195
- });
196
- test("excludes merge_requests tools", () => {
197
- assertContainsNone(tools, TOOLSET_SAMPLE_TOOLS.merge_requests, "merge_requests");
198
- });
199
- });
200
- // ---- 3. GITLAB_TOOLSETS=all ----
201
- describe("GITLAB_TOOLSETS=all", () => {
202
- let server;
203
- let tools;
204
- before(async () => {
205
- const port = await nextMcpPort();
206
- server = await launchMcpServer(mockGitLabUrl, port, {
207
- GITLAB_TOOLSETS: "all",
208
- });
209
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
210
- });
211
- after(() => cleanupServers([server]));
212
- test("returns all toolset tools", () => {
213
- assert.strictEqual(tools.length, ALL_TOOLSET_TOOL_COUNT);
214
- });
215
- test("includes pipelines, milestones, and wiki", () => {
216
- for (const id of ["pipelines", "milestones", "wiki"]) {
217
- assertContainsAll(tools, TOOLSET_SAMPLE_TOOLS[id], id);
218
- }
219
- });
220
- test("still excludes execute_graphql", () => {
221
- assertContainsNone(tools, ["execute_graphql"], "unassigned");
222
- });
223
- });
224
- // ---- 4. GITLAB_TOOLS (individual tools, additive) ----
225
- describe("GITLAB_TOOLS=list_pipelines,execute_graphql", () => {
226
- let server;
227
- let tools;
228
- before(async () => {
229
- const port = await nextMcpPort();
230
- server = await launchMcpServer(mockGitLabUrl, port, {
231
- GITLAB_TOOLS: "list_pipelines,execute_graphql",
232
- });
233
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
234
- });
235
- after(() => cleanupServers([server]));
236
- test("returns default tools plus list_pipelines and execute_graphql (both not in default toolsets)", () => {
237
- assert.strictEqual(tools.length, DEFAULT_TOOL_COUNT + 2);
238
- });
239
- test("includes the individually added tools", () => {
240
- assertContainsAll(tools, ["list_pipelines", "execute_graphql"], "individual");
241
- });
242
- test("excludes other pipeline tools (not individually enabled)", () => {
243
- assertContainsNone(tools, ["create_pipeline", "cancel_pipeline"], "non-enabled pipelines");
244
- });
245
- });
246
- // ---- 5. Toolset + individual tools combined ----
247
- describe("GITLAB_TOOLSETS=issues + GITLAB_TOOLS=list_pipelines,get_pipeline", () => {
248
- let server;
249
- let tools;
250
- before(async () => {
251
- const port = await nextMcpPort();
252
- server = await launchMcpServer(mockGitLabUrl, port, {
253
- GITLAB_TOOLSETS: "issues",
254
- GITLAB_TOOLS: "list_pipelines,get_pipeline",
255
- });
256
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
257
- });
258
- after(() => cleanupServers([server]));
259
- test("returns issue tools + 2 individual pipeline tools + discover_tools", () => {
260
- assert.strictEqual(tools.length, TOOLSET_TOOL_COUNTS.issues + 2 + DISCOVER_TOOLS_COUNT);
261
- });
262
- test("includes issue tools and the two pipeline tools", () => {
263
- assertContainsAll(tools, TOOLSET_SAMPLE_TOOLS.issues, "issues");
264
- assertContainsAll(tools, ["list_pipelines", "get_pipeline"], "individual");
265
- });
266
- test("excludes other pipeline tools", () => {
267
- assertContainsNone(tools, ["create_pipeline", "cancel_pipeline"], "other pipelines");
268
- });
269
- });
270
- // ---- 6. Legacy flag USE_PIPELINE as additive override ----
271
- describe("GITLAB_TOOLSETS=issues + USE_PIPELINE=true", () => {
272
- let server;
273
- let tools;
274
- before(async () => {
275
- const port = await nextMcpPort();
276
- server = await launchMcpServer(mockGitLabUrl, port, {
277
- GITLAB_TOOLSETS: "issues",
278
- USE_PIPELINE: "true",
279
- });
280
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
281
- });
282
- after(() => cleanupServers([server]));
283
- test("returns issue tools + all pipeline tools + discover_tools", () => {
284
- assert.strictEqual(tools.length, TOOLSET_TOOL_COUNTS.issues + LEGACY_PIPELINE_TOOL_COUNT + DISCOVER_TOOLS_COUNT);
285
- });
286
- test("includes all pipeline tools via legacy flag", () => {
287
- assertContainsAll(tools, TOOLSET_SAMPLE_TOOLS.pipelines, "pipelines");
288
- });
289
- });
290
- // ---- 7. Legacy flag USE_GITLAB_WIKI ----
291
- describe("USE_GITLAB_WIKI=true (no GITLAB_TOOLSETS)", () => {
292
- let server;
293
- let tools;
294
- before(async () => {
295
- const port = await nextMcpPort();
296
- server = await launchMcpServer(mockGitLabUrl, port, {
297
- USE_GITLAB_WIKI: "true",
298
- });
299
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
300
- });
301
- after(() => cleanupServers([server]));
302
- test("returns default tools + wiki tools (wiki is NOT default, USE_GITLAB_WIKI adds it)", () => {
303
- assert.strictEqual(tools.length, DEFAULT_TOOL_COUNT + TOOLSET_TOOL_COUNTS.wiki);
304
- });
305
- test("includes wiki tools", () => {
306
- assertContainsAll(tools, TOOLSET_SAMPLE_TOOLS.wiki, "wiki");
307
- });
308
- });
309
- // ---- 8. Read-only mode applied after toolset filter ----
310
- describe("GITLAB_TOOLSETS=issues + GITLAB_READ_ONLY_MODE=true", () => {
311
- let server;
312
- let tools;
313
- // Read-only issue tools (from readOnlyTools set in index.ts)
314
- const readOnlyIssueTools = [
315
- "list_issues",
316
- "my_issues",
317
- "get_issue",
318
- "list_issue_links",
319
- "list_issue_discussions",
320
- "get_issue_link",
321
- "list_todos",
322
- "list_issue_emoji_reactions",
323
- "list_issue_note_emoji_reactions",
324
- ];
325
- const writeIssueTools = [
326
- "create_issue",
327
- "update_issue",
328
- "update_issue_description_patch",
329
- "delete_issue",
330
- "mark_todo_done",
331
- "mark_all_todos_done",
332
- "create_issue_note",
333
- "update_issue_note",
334
- "create_issue_link",
335
- "delete_issue_link",
336
- "create_note",
337
- "create_issue_emoji_reaction",
338
- "delete_issue_emoji_reaction",
339
- "create_issue_note_emoji_reaction",
340
- "delete_issue_note_emoji_reaction",
341
- ];
342
- before(async () => {
343
- const port = await nextMcpPort();
344
- server = await launchMcpServer(mockGitLabUrl, port, {
345
- GITLAB_TOOLSETS: "issues",
346
- GITLAB_READ_ONLY_MODE: "true",
347
- });
348
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
349
- });
350
- after(() => cleanupServers([server]));
351
- test("includes only read-only issue tools", () => {
352
- assertContainsAll(tools, readOnlyIssueTools, "read-only issues");
353
- });
354
- test("excludes write issue tools", () => {
355
- assertContainsNone(tools, writeIssueTools, "write issues");
356
- });
357
- test("returns correct count (read-only issues + discover_tools)", () => {
358
- assert.strictEqual(tools.length, readOnlyIssueTools.length + DISCOVER_TOOLS_COUNT);
359
- });
360
- });
361
- // ---- 9. GITLAB_DENIED_TOOLS_REGEX applied after toolset filter ----
362
- describe("GITLAB_TOOLSETS=issues + GITLAB_DENIED_TOOLS_REGEX=^(create_|delete_)", () => {
363
- let server;
364
- let tools;
365
- before(async () => {
366
- const port = await nextMcpPort();
367
- server = await launchMcpServer(mockGitLabUrl, port, {
368
- GITLAB_TOOLSETS: "issues",
369
- GITLAB_DENIED_TOOLS_REGEX: "^(create_|delete_)",
370
- });
371
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
372
- });
373
- after(() => cleanupServers([server]));
374
- test("excludes tools matching the denial regex", () => {
375
- const denied = tools.filter((t) => t.startsWith("create_") || t.startsWith("delete_"));
376
- assert.strictEqual(denied.length, 0, `Should have no create_/delete_ tools, found: ${denied}`);
377
- });
378
- test("keeps non-matching issue tools", () => {
379
- assertContainsAll(tools, ["list_issues", "my_issues", "get_issue", "update_issue", "update_issue_note"], "non-denied issues");
380
- });
381
- });
382
- // ---- 10. Full combination: toolset + individual + legacy + read-only ----
383
- describe("GITLAB_TOOLSETS=issues + GITLAB_TOOLS=list_pipelines + USE_GITLAB_WIKI=true + GITLAB_READ_ONLY_MODE=true", () => {
384
- let server;
385
- let tools;
386
- before(async () => {
387
- const port = await nextMcpPort();
388
- server = await launchMcpServer(mockGitLabUrl, port, {
389
- GITLAB_TOOLSETS: "issues",
390
- GITLAB_TOOLS: "list_pipelines",
391
- USE_GITLAB_WIKI: "true",
392
- GITLAB_READ_ONLY_MODE: "true",
393
- });
394
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
395
- });
396
- after(() => cleanupServers([server]));
397
- test("includes read-only issue tools", () => {
398
- assertContainsAll(tools, ["list_issues", "get_issue"], "read-only issues");
399
- });
400
- test("includes list_pipelines (read-only individual tool)", () => {
401
- assertContainsAll(tools, ["list_pipelines"], "individual pipeline");
402
- });
403
- test("includes read-only wiki tools from legacy flag", () => {
404
- assertContainsAll(tools, ["list_wiki_pages", "get_wiki_page"], "read-only wiki");
405
- });
406
- test("excludes write tools across all sources", () => {
407
- assertContainsNone(tools, ["create_issue", "create_pipeline", "create_wiki_page"], "write tools");
408
- });
409
- });
410
- // ---- 11. Redundant legacy flag (toolset already includes it) ----
411
- describe("GITLAB_TOOLSETS=pipelines + USE_PIPELINE=true (redundant)", () => {
412
- let server;
413
- let tools;
414
- before(async () => {
415
- const port = await nextMcpPort();
416
- server = await launchMcpServer(mockGitLabUrl, port, {
417
- GITLAB_TOOLSETS: "pipelines",
418
- USE_PIPELINE: "true",
419
- });
420
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
421
- });
422
- after(() => cleanupServers([server]));
423
- test("returns exactly pipeline tool count + discover_tools (no duplicates)", () => {
424
- assert.strictEqual(tools.length, LEGACY_PIPELINE_TOOL_COUNT + DISCOVER_TOOLS_COUNT);
425
- });
426
- });
427
- // ---- 12. GITLAB_TOOLS with tool already in enabled toolset (no dupes) ----
428
- describe("GITLAB_TOOLSETS=issues + GITLAB_TOOLS=list_issues (already included)", () => {
429
- let server;
430
- let tools;
431
- before(async () => {
432
- const port = await nextMcpPort();
433
- server = await launchMcpServer(mockGitLabUrl, port, {
434
- GITLAB_TOOLSETS: "issues",
435
- GITLAB_TOOLS: "list_issues",
436
- });
437
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
438
- });
439
- after(() => cleanupServers([server]));
440
- test("returns exactly issue tool count + discover_tools (no duplicates)", () => {
441
- assert.strictEqual(tools.length, TOOLSET_TOOL_COUNTS.issues + DISCOVER_TOOLS_COUNT);
442
- });
443
- });
444
- // ---- 13. Invalid toolset ID is silently ignored ----
445
- describe("GITLAB_TOOLSETS=issues,nonexistent_toolset", () => {
446
- let server;
447
- let tools;
448
- before(async () => {
449
- const port = await nextMcpPort();
450
- server = await launchMcpServer(mockGitLabUrl, port, {
451
- GITLAB_TOOLSETS: "issues,nonexistent_toolset",
452
- });
453
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
454
- });
455
- after(() => cleanupServers([server]));
456
- test("returns only issue tools + discover_tools (invalid toolset ignored)", () => {
457
- assert.strictEqual(tools.length, TOOLSET_TOOL_COUNTS.issues + DISCOVER_TOOLS_COUNT);
458
- });
459
- });
460
- // ---- 14. GITLAB_TOOLS case-insensitive matching ----
461
- describe("GITLAB_TOOLS with mixed-case tool names", () => {
462
- let server;
463
- let tools;
464
- before(async () => {
465
- const port = await nextMcpPort();
466
- server = await launchMcpServer(mockGitLabUrl, port, {
467
- GITLAB_TOOLS: "List_Pipelines,Execute_GraphQL",
468
- });
469
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
470
- });
471
- after(() => cleanupServers([server]));
472
- test("resolves mixed-case tool names to lowercase equivalents", () => {
473
- assertContainsAll(tools, ["list_pipelines", "execute_graphql"], "case-insensitive tools");
474
- });
475
- test("returns default tools plus list_pipelines and execute_graphql", () => {
476
- assert.strictEqual(tools.length, DEFAULT_TOOL_COUNT + 2);
477
- });
478
- });
479
- // ---- 15. GITLAB_TOOLS with unknown tool names ----
480
- describe("GITLAB_TOOLS with unknown tool names", () => {
481
- let server;
482
- let tools;
483
- before(async () => {
484
- const port = await nextMcpPort();
485
- server = await launchMcpServer(mockGitLabUrl, port, {
486
- GITLAB_TOOLS: "list_pipelines,nonexistent_tool_xyz",
487
- });
488
- tools = await getToolNames(`http://${HOST}:${port}/mcp`);
489
- });
490
- after(() => cleanupServers([server]));
491
- test("server starts normally and returns tools without crashing", () => {
492
- assert.ok(tools.length > 0, "Should return at least some tools");
493
- });
494
- test("includes the valid individual tool but ignores the unknown one", () => {
495
- assertContainsAll(tools, ["list_pipelines"], "valid individual tool");
496
- assertContainsNone(tools, ["nonexistent_tool_xyz"], "unknown tool");
497
- });
498
- });
499
- });
@@ -1,141 +0,0 @@
1
- /**
2
- * Tests for the update_issue slim response (issue #563).
3
- * By default update_issue returns a slim confirmation; full_response=true
4
- * returns the complete updated issue object.
5
- */
6
- import { describe, test, before, after } from "node:test";
7
- import assert from "node:assert";
8
- import { launchServer, findAvailablePort, cleanupServers, TransportMode, HOST, } from "./utils/server-launcher.js";
9
- import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
10
- import { CustomHeaderClient } from "./clients/custom-header-client.js";
11
- const MOCK_TOKEN = "glpat-slim-update-test-token";
12
- describe("update_issue slim response", () => {
13
- let mockGitLab;
14
- let server;
15
- let client;
16
- const MOCK_PORT_BASE = 9650;
17
- const MCP_PORT_BASE = 3650;
18
- before(async () => {
19
- const mockPort = await findMockServerPort();
20
- mockGitLab = new MockGitLabServer({
21
- port: mockPort,
22
- validTokens: [MOCK_TOKEN],
23
- });
24
- await mockGitLab.start();
25
- server = await launchServer({
26
- mode: TransportMode.STREAMABLE_HTTP,
27
- port: await findAvailablePort(MCP_PORT_BASE),
28
- timeout: 10000,
29
- env: {
30
- STREAMABLE_HTTP: "true",
31
- REMOTE_AUTHORIZATION: "true",
32
- GITLAB_API_URL: `${mockGitLab.getUrl()}/api/v4`,
33
- GITLAB_ACCESS_TOKEN: MOCK_TOKEN,
34
- GITLAB_TOOLSETS: "issues",
35
- },
36
- });
37
- client = new CustomHeaderClient({
38
- headers: {
39
- authorization: `Bearer ${MOCK_TOKEN}`,
40
- },
41
- });
42
- await client.connect(`http://${HOST}:${server.port ?? 0}/mcp`);
43
- });
44
- after(async () => {
45
- await client?.disconnect();
46
- cleanupServers([server]);
47
- await mockGitLab?.stop();
48
- });
49
- test("default response is slim: no description echo", async () => {
50
- const result = await client.callTool("update_issue", {
51
- project_id: "test/project",
52
- issue_iid: "1",
53
- description: "A very long description that should not be echoed back",
54
- });
55
- const data = JSON.parse(result.content[0]?.text || "{}");
56
- assert.strictEqual(data.iid, "1");
57
- assert.strictEqual(data.state, "opened");
58
- assert.ok(data.title, "title should be present");
59
- assert.ok(data.web_url, "web_url should be present");
60
- assert.ok(data.updated_at, "updated_at should be present");
61
- assert.strictEqual(data.description, undefined, "description must not be echoed");
62
- assert.strictEqual(data.author, undefined, "author must not be included");
63
- assert.strictEqual(data.milestone, undefined, "milestone must not be included");
64
- });
65
- test("slim response reflects state changes", async () => {
66
- const result = await client.callTool("update_issue", {
67
- project_id: "test/project",
68
- issue_iid: "2",
69
- state_event: "close",
70
- });
71
- const data = JSON.parse(result.content[0]?.text || "{}");
72
- assert.strictEqual(data.state, "closed");
73
- assert.strictEqual(data.description, undefined);
74
- });
75
- test('full_response="false" string keeps the response slim', async () => {
76
- const result = await client.callTool("update_issue", {
77
- project_id: "test/project",
78
- issue_iid: "3",
79
- description: "A long description that should still not be echoed",
80
- full_response: "false",
81
- });
82
- const data = JSON.parse(result.content[0]?.text || "{}");
83
- assert.strictEqual(data.description, undefined);
84
- assert.strictEqual(data.author, undefined);
85
- assert.strictEqual(data.iid, "3");
86
- });
87
- test("full_response=true returns the complete issue object", async () => {
88
- const result = await client.callTool("update_issue", {
89
- project_id: "test/project",
90
- issue_iid: "4",
91
- description: "Full description expected in response",
92
- full_response: true,
93
- });
94
- const data = JSON.parse(result.content[0]?.text || "{}");
95
- assert.strictEqual(data.description, "Full description expected in response");
96
- assert.ok(data.author, "author should be present in full response");
97
- assert.strictEqual(data.iid, "4");
98
- });
99
- test("full_response is not forwarded to the GitLab API", async () => {
100
- const result = await client.callTool("update_issue", {
101
- project_id: "test/project",
102
- issue_iid: "5",
103
- title: "Updated title",
104
- full_response: true,
105
- });
106
- const data = JSON.parse(result.content[0]?.text || "{}");
107
- assert.strictEqual(data.title, "Updated title");
108
- assert.strictEqual(data.full_response, undefined, "full_response must not leak into the issue");
109
- });
110
- test("get_issue slims the milestone by default", async () => {
111
- const result = await client.callTool("get_issue", {
112
- project_id: "test/project",
113
- issue_iid: "100",
114
- });
115
- const data = JSON.parse(result.content[0]?.text || "{}");
116
- assert.ok(data.milestone, "milestone should be present");
117
- assert.strictEqual(data.milestone.title, "Sprint 42");
118
- assert.ok(data.milestone.web_url, "milestone web_url should be present");
119
- assert.strictEqual(data.milestone.description, undefined, "milestone description must not be echoed by default");
120
- assert.ok(data.description, "issue description should still be present");
121
- });
122
- test("get_issue full_response=true returns the full milestone", async () => {
123
- const result = await client.callTool("get_issue", {
124
- project_id: "test/project",
125
- issue_iid: "100",
126
- full_response: true,
127
- });
128
- const data = JSON.parse(result.content[0]?.text || "{}");
129
- assert.ok(data.milestone, "milestone should be present");
130
- assert.ok(typeof data.milestone.description === "string" && data.milestone.description.length > 0, "milestone description should be included with full_response");
131
- });
132
- test("get_issue without milestone is unaffected", async () => {
133
- const result = await client.callTool("get_issue", {
134
- project_id: "test/project",
135
- issue_iid: "6",
136
- });
137
- const data = JSON.parse(result.content[0]?.text || "{}");
138
- assert.strictEqual(data.milestone, null);
139
- assert.strictEqual(data.iid, "6");
140
- });
141
- });