@zereight/mcp-gitlab 2.1.69 → 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 (155) hide show
  1. package/README.ko.md +10 -4
  2. package/README.md +238 -233
  3. package/README.pt-BR.md +4 -4
  4. package/README.zh-CN.md +6 -4
  5. package/build/config.js +12 -4
  6. package/build/deprecated-env.js +47 -0
  7. package/build/index.js +456 -237
  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/build/utils/url.js +15 -0
  20. package/package.json +3 -3
  21. package/build/scripts/check-skill-sync.js +0 -143
  22. package/build/scripts/generate-server-card.js +0 -39
  23. package/build/scripts/generate-tool-coverage.js +0 -58
  24. package/build/scripts/generate-tool-docs.js +0 -430
  25. package/build/scripts/tool-coverage/coverage.js +0 -341
  26. package/build/scripts/tool-coverage/coverage.test.js +0 -142
  27. package/build/test/callback-proxy-tests.js +0 -321
  28. package/build/test/cli/args.test.js +0 -175
  29. package/build/test/cli/boolean-flags.test.js +0 -106
  30. package/build/test/cli/compact-mcp-result.test.js +0 -93
  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-artifact-entry-schema.test.js +0 -44
  50. package/build/test/gitlab-diff-schema.test.js +0 -36
  51. package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
  52. package/build/test/gitlab-tag-schema.test.js +0 -51
  53. package/build/test/group-milestone-schema.test.js +0 -45
  54. package/build/test/mcp-oauth-tests.js +0 -905
  55. package/build/test/mcp-server-name.test.js +0 -87
  56. package/build/test/merge-merge-request-schema.test.js +0 -75
  57. package/build/test/multi-server-test.js +0 -190
  58. package/build/test/no-proxy-integration-test.js +0 -183
  59. package/build/test/no-proxy-test.js +0 -149
  60. package/build/test/nullable-gitlab-response-fields.test.js +0 -37
  61. package/build/test/nullish-tool-arguments-schema.test.js +0 -118
  62. package/build/test/oauth-device-flow-tests.js +0 -450
  63. package/build/test/oauth-startup.test.js +0 -204
  64. package/build/test/oauth-tests.js +0 -428
  65. package/build/test/path-segment-encoding.test.js +0 -98
  66. package/build/test/remote-auth-simple-test.js +0 -277
  67. package/build/test/remote-auth-tests.js +0 -314
  68. package/build/test/response-masking.test.js +0 -445
  69. package/build/test/schema-tests.js +0 -1679
  70. package/build/test/server/metrics.test.js +0 -47
  71. package/build/test/server/request-helpers.test.js +0 -48
  72. package/build/test/server/version.test.js +0 -13
  73. package/build/test/sse-auth-guard.test.js +0 -96
  74. package/build/test/sse-session-limits.test.js +0 -273
  75. package/build/test/stateless/callback-proxy.test.js +0 -510
  76. package/build/test/stateless/client-id.test.js +0 -177
  77. package/build/test/stateless/codec.test.js +0 -328
  78. package/build/test/stateless/config-ttl.test.js +0 -149
  79. package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
  80. package/build/test/stateless/session-id-integration.test.js +0 -675
  81. package/build/test/stateless/session-id.test.js +0 -157
  82. package/build/test/streamable-http-concurrent-session.test.js +0 -171
  83. package/build/test/streamable-http-dns-rebinding.test.js +0 -185
  84. package/build/test/streamable-http-sse-stream.test.js +0 -350
  85. package/build/test/streamable-http-static-token-auth.test.js +0 -157
  86. package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
  87. package/build/test/test-all-transport-server.js +0 -255
  88. package/build/test/test-auth-retry.js +0 -195
  89. package/build/test/test-blank-filters.js +0 -156
  90. package/build/test/test-ci-catalog.js +0 -177
  91. package/build/test/test-ci-lint.js +0 -191
  92. package/build/test/test-ci-variables.js +0 -309
  93. package/build/test/test-create-repository.js +0 -120
  94. package/build/test/test-dependency-proxy.js +0 -195
  95. package/build/test/test-deployment-tools.js +0 -463
  96. package/build/test/test-download-attachment.js +0 -190
  97. package/build/test/test-dynamic-project-scope.js +0 -524
  98. package/build/test/test-empty-toolsets.js +0 -535
  99. package/build/test/test-get-file-blame.js +0 -145
  100. package/build/test/test-get-file-contents.js +0 -128
  101. package/build/test/test-geteffectiveprojectid.js +0 -812
  102. package/build/test/test-health-check.js +0 -115
  103. package/build/test/test-issue-description-patch.js +0 -256
  104. package/build/test/test-job-artifacts.js +0 -275
  105. package/build/test/test-json-schema.js +0 -166
  106. package/build/test/test-list-group-members.js +0 -150
  107. package/build/test/test-list-group-merge-requests.js +0 -165
  108. package/build/test/test-list-issues.js +0 -170
  109. package/build/test/test-list-merge-requests.js +0 -201
  110. package/build/test/test-list-milestones.js +0 -145
  111. package/build/test/test-list-project-members.js +0 -132
  112. package/build/test/test-merge-request-approval-state-tools.js +0 -213
  113. package/build/test/test-merge-request-approvals.js +0 -187
  114. package/build/test/test-merge-request-pipelines.js +0 -106
  115. package/build/test/test-mr-diffs-filter.js +0 -132
  116. package/build/test/test-mr-file-diffs.js +0 -251
  117. package/build/test/test-oauth-proxy-rate-limit.js +0 -133
  118. package/build/test/test-orbit.js +0 -155
  119. package/build/test/test-permission-mode.js +0 -424
  120. package/build/test/test-pipeline-schedules.js +0 -482
  121. package/build/test/test-protected-branches.js +0 -174
  122. package/build/test/test-remote-downloads.js +0 -510
  123. package/build/test/test-search-code.js +0 -275
  124. package/build/test/test-snippets.js +0 -735
  125. package/build/test/test-tags.js +0 -220
  126. package/build/test/test-todos.js +0 -195
  127. package/build/test/test-token-optimizations.js +0 -691
  128. package/build/test/test-toolset-filtering.js +0 -499
  129. package/build/test/test-update-issue-slim.js +0 -141
  130. package/build/test/test-update-project.js +0 -112
  131. package/build/test/test-upload-markdown.js +0 -206
  132. package/build/test/test-vulnerabilities.js +0 -399
  133. package/build/test/test-webhooks.js +0 -218
  134. package/build/test/tool-description-quality.test.js +0 -50
  135. package/build/test/utils/bulk-publish-options.test.js +0 -32
  136. package/build/test/utils/download-token.test.js +0 -35
  137. package/build/test/utils/forwarded-public-base-url.test.js +0 -46
  138. package/build/test/utils/gitlab-instance-version.test.js +0 -32
  139. package/build/test/utils/gitlab-version-gate.test.js +0 -74
  140. package/build/test/utils/graphql-query.test.js +0 -168
  141. package/build/test/utils/helpers-path.test.js +0 -104
  142. package/build/test/utils/jmespath-tool-result.test.js +0 -91
  143. package/build/test/utils/masking.test.js +0 -384
  144. package/build/test/utils/merge-request-position.test.js +0 -57
  145. package/build/test/utils/mock-gitlab-server.js +0 -614
  146. package/build/test/utils/proxy-client-ip.test.js +0 -28
  147. package/build/test/utils/redact-sensitive.test.js +0 -32
  148. package/build/test/utils/safe-redirect-fetch.test.js +0 -463
  149. package/build/test/utils/server-launcher.js +0 -231
  150. package/build/test/utils/tool-args.test.js +0 -210
  151. package/build/test/utils/url.test.js +0 -128
  152. package/build/test/utils/version-check.test.js +0 -239
  153. package/build/test/utils/wiki-title.test.js +0 -21
  154. package/build/test-note.js +0 -54
  155. package/build/test-resolve-issue-note.js +0 -127
@@ -1,166 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- import { z } from "zod";
3
- import { toJSONSchema } from "../utils/schema.js";
4
- function assert(condition, message) {
5
- if (!condition) {
6
- throw new Error(message);
7
- }
8
- }
9
- function runTests() {
10
- console.log("Testing toJSONSchema utility...");
11
- const results = [];
12
- // Test 1: Required field extraction
13
- try {
14
- const schema = z.object({
15
- requiredField: z.string(),
16
- optionalField: z.string().optional(),
17
- });
18
- const result = toJSONSchema(schema);
19
- assert(result.required?.includes("requiredField"), "requiredField should be in required array");
20
- assert(!result.required?.includes("optionalField"), "optionalField should NOT be in required array");
21
- results.push({ name: "required field extraction", status: "passed" });
22
- }
23
- catch (error) {
24
- results.push({
25
- name: "required field extraction",
26
- status: "failed",
27
- error: error.message,
28
- });
29
- }
30
- // Test 2: Nullable fields
31
- try {
32
- const schema = z.object({
33
- nullableField: z.string().nullable(),
34
- requiredField: z.string(),
35
- });
36
- const result = toJSONSchema(schema);
37
- assert(result.required?.includes("requiredField"), "requiredField should be in required array");
38
- assert(!result.required?.includes("nullableField"), "nullableField should NOT be in required array");
39
- results.push({ name: "nullable fields", status: "passed" });
40
- }
41
- catch (error) {
42
- results.push({
43
- name: "nullable fields",
44
- status: "failed",
45
- error: error.message,
46
- });
47
- }
48
- // Test 3: Optional nullable fields
49
- try {
50
- const schema = z.object({
51
- optionalNullable: z.string().optional().nullable(),
52
- requiredField: z.string(),
53
- });
54
- const result = toJSONSchema(schema);
55
- assert(result.required?.includes("requiredField"), "requiredField should be in required array");
56
- assert(!result.required?.includes("optionalNullable"), "optionalNullable should NOT be in required array");
57
- results.push({ name: "optional nullable fields", status: "passed" });
58
- }
59
- catch (error) {
60
- results.push({
61
- name: "optional nullable fields",
62
- status: "failed",
63
- error: error.message,
64
- });
65
- }
66
- // Test 4: Fields with defaults
67
- try {
68
- const schema = z.object({
69
- fieldWithDefault: z.string().default("default-value"),
70
- requiredField: z.string(),
71
- });
72
- const result = toJSONSchema(schema);
73
- assert(result.required?.includes("requiredField"), "requiredField should be in required array");
74
- assert(!result.required?.includes("fieldWithDefault"), "fieldWithDefault should NOT be in required array");
75
- assert(result.properties.fieldWithDefault.default === "default-value", "default value should be preserved");
76
- results.push({ name: "fields with defaults", status: "passed" });
77
- }
78
- catch (error) {
79
- results.push({
80
- name: "fields with defaults",
81
- status: "failed",
82
- error: error.message,
83
- });
84
- }
85
- // Test 5: Nested objects with shared property names
86
- try {
87
- const schema = z.object({
88
- foo: z.string(), // Required at root
89
- nested: z.object({
90
- foo: z.string().optional(), // Optional in nested, shares name with root
91
- }),
92
- });
93
- const result = toJSONSchema(schema);
94
- assert(result.required?.includes("foo"), "root foo should be in required array");
95
- assert(result.required?.includes("nested"), "nested object should be in required array");
96
- assert(result.properties.nested.required === undefined, "nested foo should NOT be in required array");
97
- results.push({
98
- name: "nested objects with shared property names",
99
- status: "passed",
100
- });
101
- }
102
- catch (error) {
103
- results.push({
104
- name: "nested objects with shared property names",
105
- status: "failed",
106
- error: error.message,
107
- });
108
- }
109
- // Test 6: Coerced fields
110
- try {
111
- const schema = z.object({
112
- coercedField: z.coerce.string(),
113
- optionalCoercedField: z.coerce.string().optional(),
114
- });
115
- const result = toJSONSchema(schema);
116
- assert(result.required?.includes("coercedField"), "coercedField should be in required array (z.coerce without optional)");
117
- assert(!result.required?.includes("optionalCoercedField"), "optionalCoercedField should NOT be in required array (z.coerce with optional)");
118
- results.push({ name: "coerced fields", status: "passed" });
119
- }
120
- catch (error) {
121
- results.push({
122
- name: "coerced fields",
123
- status: "failed",
124
- error: error.message,
125
- });
126
- }
127
- // Test 7: Effects fields
128
- try {
129
- const schema = z.object({
130
- effectRequired: z.preprocess(value => value, z.string()),
131
- effectOptional: z.preprocess(value => value, z.string().optional()),
132
- });
133
- const result = toJSONSchema(schema);
134
- assert(result.required?.includes("effectRequired"), "effectRequired should be in required array");
135
- assert(!result.required?.includes("effectOptional"), "effectOptional should NOT be in required array");
136
- results.push({ name: "effects fields", status: "passed" });
137
- }
138
- catch (error) {
139
- results.push({
140
- name: "effects fields",
141
- status: "failed",
142
- error: error.message,
143
- });
144
- }
145
- // Print results
146
- const passed = results.filter((r) => r.status === "passed").length;
147
- const failed = results.filter((r) => r.status === "failed").length;
148
- console.log("\nTest Results:");
149
- console.log("=".repeat(50));
150
- results.forEach((result) => {
151
- if (result.status === "passed") {
152
- console.log(` ${result.name}: ${result.status}`);
153
- }
154
- else {
155
- console.log(` ${result.name}: ${result.status}`);
156
- console.log(` Error: ${result.error}`);
157
- }
158
- });
159
- console.log("=".repeat(50));
160
- console.log(`Total: ${results.length} tests`);
161
- console.log(`Passed: ${passed}`);
162
- console.log(`Failed: ${failed}`);
163
- return { passed, failed };
164
- }
165
- // Run tests
166
- runTests();
@@ -1,150 +0,0 @@
1
- import { describe, test, before, after, beforeEach } from 'node:test';
2
- import assert from 'node:assert';
3
- import { spawn } from 'child_process';
4
- import { MockGitLabServer, findMockServerPort } from './utils/mock-gitlab-server.js';
5
- const MOCK_TOKEN = 'glpat-mock-token-12345';
6
- const TEST_GROUP_ID = '456';
7
- const directMembers = [
8
- {
9
- id: 1,
10
- username: 'direct-user',
11
- name: 'Direct User',
12
- state: 'active',
13
- avatar_url: null,
14
- web_url: 'https://gitlab.mock/users/1',
15
- access_level: 30,
16
- created_at: '2024-01-01T00:00:00Z'
17
- }
18
- ];
19
- const inheritedMembers = [
20
- {
21
- id: 2,
22
- username: 'inherited-user',
23
- name: 'Inherited User',
24
- state: 'active',
25
- avatar_url: null,
26
- web_url: 'https://gitlab.mock/users/2',
27
- access_level: 20,
28
- created_at: '2024-01-02T00:00:00Z'
29
- }
30
- ];
31
- async function callListGroupMembers(args, env) {
32
- return new Promise((resolve, reject) => {
33
- const proc = spawn('node', ['build/index.js'], {
34
- stdio: ['pipe', 'pipe', 'pipe'],
35
- env: {
36
- ...process.env,
37
- ...env,
38
- GITLAB_READ_ONLY_MODE: 'true'
39
- }
40
- });
41
- let output = '';
42
- let errorOutput = '';
43
- proc.stdout?.on('data', d => output += d);
44
- proc.stderr?.on('data', d => errorOutput += d);
45
- proc.on('close', (code) => {
46
- if (code !== 0)
47
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
48
- const line = output.split('\n').find(l => l.startsWith('{'));
49
- if (!line)
50
- return reject(new Error('No JSON output found'));
51
- try {
52
- const response = JSON.parse(line);
53
- if (response.error) {
54
- reject(response.error);
55
- }
56
- else {
57
- const content = response.result?.content?.[0]?.text;
58
- if (content) {
59
- try {
60
- resolve(JSON.parse(content));
61
- }
62
- catch (e) {
63
- reject(new Error(`Failed to parse tool output JSON: ${content}`));
64
- }
65
- }
66
- else {
67
- resolve(response.result);
68
- }
69
- }
70
- }
71
- catch (e) {
72
- reject(e);
73
- }
74
- });
75
- proc.stdin?.end(JSON.stringify({
76
- jsonrpc: "2.0", id: 1, method: "tools/call",
77
- params: { name: "list_group_members", arguments: args }
78
- }) + '\n');
79
- });
80
- }
81
- describe('list_group_members', () => {
82
- let mockGitLab;
83
- let mockGitLabUrl;
84
- let directEndpointHit = false;
85
- let inheritedEndpointHit = false;
86
- let queryParam = null;
87
- before(async () => {
88
- const mockPort = await findMockServerPort();
89
- mockGitLab = new MockGitLabServer({
90
- port: mockPort,
91
- validTokens: [MOCK_TOKEN]
92
- });
93
- await mockGitLab.start();
94
- mockGitLabUrl = mockGitLab.getUrl();
95
- mockGitLab.addMockHandler('get', `/groups/${TEST_GROUP_ID}/members`, (req, res) => {
96
- directEndpointHit = true;
97
- queryParam = req.query.query ?? null;
98
- res.json(directMembers);
99
- });
100
- mockGitLab.addMockHandler('get', `/groups/${TEST_GROUP_ID}/members/all`, (req, res) => {
101
- inheritedEndpointHit = true;
102
- res.json([...directMembers, ...inheritedMembers]);
103
- });
104
- });
105
- beforeEach(() => {
106
- directEndpointHit = false;
107
- inheritedEndpointHit = false;
108
- queryParam = null;
109
- });
110
- after(async () => {
111
- await mockGitLab.stop();
112
- });
113
- describe('When listing group members', () => {
114
- describe('with direct membership only', () => {
115
- test('should return direct members', async () => {
116
- const members = await callListGroupMembers({ group_id: TEST_GROUP_ID }, {
117
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
118
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
119
- });
120
- assert.ok(Array.isArray(members), 'Response should be an array');
121
- assert.strictEqual(members.length, 1, 'Should return direct members');
122
- assert.strictEqual(members[0].username, 'direct-user');
123
- assert.strictEqual(directEndpointHit, true, 'Direct members endpoint should be called');
124
- assert.strictEqual(inheritedEndpointHit, false, 'Inherited members endpoint should not be called');
125
- });
126
- });
127
- describe('with include_inheritance', () => {
128
- test('should return inherited members', async () => {
129
- const members = await callListGroupMembers({ group_id: TEST_GROUP_ID, include_inheritance: true }, {
130
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
131
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
132
- });
133
- assert.ok(Array.isArray(members), 'Response should be an array');
134
- assert.strictEqual(members.length, 2, 'Should return inherited members');
135
- assert.strictEqual(members[1].username, 'inherited-user');
136
- assert.strictEqual(inheritedEndpointHit, true, 'Inherited members endpoint should be called');
137
- assert.strictEqual(directEndpointHit, false, 'Direct members endpoint should not be called');
138
- });
139
- });
140
- describe('with query', () => {
141
- test('should pass query to the members endpoint', async () => {
142
- await callListGroupMembers({ group_id: TEST_GROUP_ID, query: 'alice' }, {
143
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
144
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
145
- });
146
- assert.strictEqual(queryParam, 'alice', 'Query parameter should be forwarded');
147
- });
148
- });
149
- });
150
- });
@@ -1,165 +0,0 @@
1
- import { describe, test, before, after, beforeEach } from "node:test";
2
- import assert from "node:assert";
3
- import { spawn } from "child_process";
4
- import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
5
- const MOCK_TOKEN = "glpat-mock-token-12345";
6
- const TEST_GROUP_ID = "my-group/sub-group";
7
- const groupMergeRequests = [
8
- {
9
- id: 1,
10
- iid: 10,
11
- project_id: 123,
12
- title: "Group MR 1",
13
- description: "First MR of the group",
14
- state: "opened",
15
- created_at: "2024-01-01T00:00:00Z",
16
- updated_at: "2024-01-02T00:00:00Z",
17
- merged_at: null,
18
- closed_at: null,
19
- target_branch: "main",
20
- source_branch: "feature/one",
21
- web_url: "https://gitlab.mock/my-group/project-a/-/merge_requests/10",
22
- merge_commit_sha: null,
23
- author: {
24
- id: 1,
25
- username: "test-user",
26
- name: "Test User",
27
- },
28
- },
29
- {
30
- id: 2,
31
- iid: 4,
32
- project_id: 456,
33
- title: "Group MR 2",
34
- description: "Second MR of the group",
35
- state: "opened",
36
- created_at: "2024-01-03T00:00:00Z",
37
- updated_at: "2024-01-04T00:00:00Z",
38
- merged_at: null,
39
- closed_at: null,
40
- target_branch: "main",
41
- source_branch: "feature/two",
42
- web_url: "https://gitlab.mock/my-group/project-b/-/merge_requests/4",
43
- merge_commit_sha: null,
44
- author: {
45
- id: 2,
46
- username: "other-user",
47
- name: "Other User",
48
- },
49
- },
50
- ];
51
- async function callListGroupMergeRequests(args, env) {
52
- return new Promise((resolve, reject) => {
53
- const proc = spawn("node", ["build/index.js"], {
54
- stdio: ["pipe", "pipe", "pipe"],
55
- env: {
56
- ...process.env,
57
- ...env,
58
- GITLAB_READ_ONLY_MODE: "true",
59
- },
60
- });
61
- let output = "";
62
- let errorOutput = "";
63
- proc.stdout?.on("data", d => (output += d));
64
- proc.stderr?.on("data", d => (errorOutput += d));
65
- proc.on("close", code => {
66
- if (code !== 0)
67
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
68
- const line = output.split("\n").find(l => l.startsWith("{"));
69
- if (!line)
70
- return reject(new Error("No JSON output found"));
71
- try {
72
- const response = JSON.parse(line);
73
- if (response.error) {
74
- reject(response.error);
75
- }
76
- else {
77
- const content = response.result?.content?.[0]?.text;
78
- if (content) {
79
- try {
80
- resolve(JSON.parse(content));
81
- }
82
- catch {
83
- reject(new Error(`Failed to parse tool output JSON: ${content}`));
84
- }
85
- }
86
- else {
87
- resolve(response.result);
88
- }
89
- }
90
- }
91
- catch (e) {
92
- reject(e);
93
- }
94
- });
95
- proc.stdin?.end(JSON.stringify({
96
- jsonrpc: "2.0",
97
- id: 1,
98
- method: "tools/call",
99
- params: { name: "list_group_merge_requests", arguments: args },
100
- }) + "\n");
101
- });
102
- }
103
- describe("list_group_merge_requests", () => {
104
- let mockGitLab;
105
- let mockGitLabUrl;
106
- let capturedUrl;
107
- before(async () => {
108
- const mockPort = await findMockServerPort();
109
- mockGitLab = new MockGitLabServer({
110
- port: mockPort,
111
- validTokens: [MOCK_TOKEN],
112
- });
113
- await mockGitLab.start();
114
- mockGitLabUrl = mockGitLab.getUrl();
115
- mockGitLab.addMockHandler("get", `/groups/${encodeURIComponent(TEST_GROUP_ID)}/merge_requests`, (req, res) => {
116
- capturedUrl = req.originalUrl;
117
- res.json(groupMergeRequests);
118
- });
119
- });
120
- beforeEach(() => {
121
- capturedUrl = undefined;
122
- });
123
- after(async () => {
124
- await mockGitLab.stop();
125
- });
126
- test("lists merge requests of every project in the group", async () => {
127
- const mrs = await callListGroupMergeRequests({ group_id: TEST_GROUP_ID }, {
128
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
129
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
130
- });
131
- assert.ok(Array.isArray(mrs), "Response should be an array");
132
- assert.strictEqual(mrs.length, 2, "Should return the 2 mock MRs");
133
- assert.strictEqual(mrs[0].title, "Group MR 1");
134
- assert.notStrictEqual(String(mrs[0].project_id), String(mrs[1].project_id), "MRs should come from different projects");
135
- });
136
- test("forwards group-specific and shared filters as query parameters", async () => {
137
- await callListGroupMergeRequests({
138
- group_id: TEST_GROUP_ID,
139
- state: "opened",
140
- non_archived: true,
141
- source_project_id: "123",
142
- labels: ["backend", "urgent"],
143
- approved_by_usernames: ["alice", "bob"],
144
- }, {
145
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
146
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
147
- });
148
- assert.ok(capturedUrl, "Mock handler should have received a request");
149
- assert.match(capturedUrl, /state=opened/, "Request URL should carry state");
150
- assert.match(capturedUrl, /non_archived=true/, "Request URL should carry non_archived");
151
- assert.match(capturedUrl, /source_project_id=123/, "Request URL should carry source_project_id");
152
- assert.match(capturedUrl, /labels=backend%2Curgent/, "Labels should be comma-joined");
153
- assert.match(capturedUrl, /approved_by_usernames%5B%5D=alice/, "approved_by_usernames should use bracket-array form (URL-encoded)");
154
- assert.match(capturedUrl, /approved_by_usernames%5B%5D=bob/);
155
- });
156
- test("drops the mutually exclusive *_id filter when a *_username is given", async () => {
157
- await callListGroupMergeRequests({ group_id: TEST_GROUP_ID, author_id: "7", author_username: "alice" }, {
158
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
159
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
160
- });
161
- assert.ok(capturedUrl, "Mock handler should have received a request");
162
- assert.match(capturedUrl, /author_username=alice/, "author_username should be forwarded");
163
- assert.doesNotMatch(capturedUrl, /author_id=/, "author_id should be dropped");
164
- });
165
- });
@@ -1,170 +0,0 @@
1
- import { describe, test, before, after } from "node:test";
2
- import assert from "node:assert";
3
- import { spawn } from "child_process";
4
- import { MockGitLabServer, findMockServerPort } from "./utils/mock-gitlab-server.js";
5
- const MOCK_TOKEN = "glpat-mock-token-12345";
6
- const TEST_PROJECT_ID = "123";
7
- async function callListIssuesResult(args = {}, env) {
8
- return new Promise((resolve, reject) => {
9
- const proc = spawn("node", ["build/index.js"], {
10
- stdio: ["pipe", "pipe", "pipe"],
11
- env: {
12
- ...process.env,
13
- ...env,
14
- GITLAB_READ_ONLY_MODE: "true",
15
- },
16
- });
17
- let output = "";
18
- let errorOutput = "";
19
- proc.stdout?.on("data", d => (output += d));
20
- proc.stderr?.on("data", d => (errorOutput += d));
21
- proc.on("close", code => {
22
- if (code !== 0) {
23
- return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
24
- }
25
- const line = output.split("\n").find(l => l.startsWith("{"));
26
- if (!line) {
27
- return reject(new Error("No JSON output found"));
28
- }
29
- try {
30
- const response = JSON.parse(line);
31
- if (response.error) {
32
- reject(response.error);
33
- }
34
- else {
35
- const content = response.result?.content?.[0]?.text;
36
- if (content) {
37
- try {
38
- resolve({ data: JSON.parse(content), text: content });
39
- }
40
- catch {
41
- reject(new Error(`Failed to parse tool output JSON: ${content}`));
42
- }
43
- }
44
- else {
45
- resolve({ data: response.result });
46
- }
47
- }
48
- }
49
- catch (e) {
50
- reject(e);
51
- }
52
- });
53
- proc.stdin?.end(JSON.stringify({
54
- jsonrpc: "2.0",
55
- id: 1,
56
- method: "tools/call",
57
- params: { name: "list_issues", arguments: args },
58
- }) + "\n");
59
- });
60
- }
61
- async function callListIssues(args = {}, env) {
62
- return (await callListIssuesResult(args, env)).data;
63
- }
64
- describe("list_issues", () => {
65
- let mockGitLab;
66
- let mockGitLabUrl;
67
- before(async () => {
68
- const mockPort = await findMockServerPort();
69
- mockGitLab = new MockGitLabServer({
70
- port: mockPort,
71
- validTokens: [MOCK_TOKEN],
72
- });
73
- await mockGitLab.start();
74
- mockGitLabUrl = mockGitLab.getUrl();
75
- });
76
- after(async () => {
77
- await mockGitLab.stop();
78
- });
79
- test("lists project-specific issues", async () => {
80
- const issues = await callListIssues({ project_id: TEST_PROJECT_ID }, {
81
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
82
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
83
- });
84
- assert.ok(Array.isArray(issues), "Response should be an array");
85
- assert.strictEqual(issues.length, 1, "Should return 1 mock issue");
86
- const firstIssue = issues[0];
87
- assert.ok(firstIssue && typeof firstIssue === "object" && "title" in firstIssue);
88
- const title = Reflect.get(firstIssue, "title");
89
- assert.strictEqual(title, "Test Issue 1");
90
- });
91
- test("returns compact JSON text", async () => {
92
- const result = await callListIssuesResult({ project_id: TEST_PROJECT_ID }, {
93
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
94
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
95
- });
96
- assert.ok(result.text, "Tool response should include text content");
97
- assert.doesNotMatch(result.text, /\n\s+"/, "Tool response JSON should not be pretty-printed");
98
- assert.ok(Array.isArray(result.data), "Response should remain valid JSON");
99
- });
100
- test("prefers author_username over author_id when both are provided", async () => {
101
- let capturedUrl;
102
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/issues`, (req, res) => {
103
- capturedUrl = req.originalUrl;
104
- res.json([]);
105
- });
106
- try {
107
- await callListIssues({
108
- project_id: TEST_PROJECT_ID,
109
- author_id: "42",
110
- author_username: "alice",
111
- }, {
112
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
113
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
114
- });
115
- assert.ok(capturedUrl, "Mock handler should have received a request");
116
- assert.match(capturedUrl, /author_username=alice/, "Request should include author_username");
117
- assert.doesNotMatch(capturedUrl, /author_id=/, "Request should not include author_id");
118
- }
119
- finally {
120
- mockGitLab.clearCustomHandlers();
121
- }
122
- });
123
- test("drops blank entries inside array filters", async () => {
124
- let capturedUrl;
125
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/issues`, (req, res) => {
126
- capturedUrl = req.originalUrl;
127
- res.json([]);
128
- });
129
- try {
130
- await callListIssues({
131
- project_id: TEST_PROJECT_ID,
132
- labels: ["", " ", "bug"],
133
- assignee_username: ["", "alice"],
134
- }, {
135
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
136
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
137
- });
138
- assert.ok(capturedUrl, "Mock handler should have received a request");
139
- const params = new URL(capturedUrl, "http://localhost").searchParams;
140
- assert.deepStrictEqual(params.getAll("labels[]"), ["bug"], "Blank label entries should be dropped while non-blank ones are kept");
141
- assert.deepStrictEqual(params.getAll("assignee_username[]"), ["alice"], "Blank assignee_username entries should be dropped while non-blank ones are kept");
142
- }
143
- finally {
144
- mockGitLab.clearCustomHandlers();
145
- }
146
- });
147
- test("omits array filters whose entries are all blank", async () => {
148
- let capturedUrl;
149
- mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/issues`, (req, res) => {
150
- capturedUrl = req.originalUrl;
151
- res.json([]);
152
- });
153
- try {
154
- const issues = await callListIssues({
155
- project_id: TEST_PROJECT_ID,
156
- labels: ["", " "],
157
- assignee_username: [""],
158
- }, {
159
- GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
160
- GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
161
- });
162
- assert.deepStrictEqual(issues, []);
163
- assert.ok(capturedUrl, "Mock handler should have received a request");
164
- assert.strictEqual(new URL(capturedUrl, "http://localhost").search, "", "Array filters with only blank entries should not be serialized");
165
- }
166
- finally {
167
- mockGitLab.clearCustomHandlers();
168
- }
169
- });
170
- });