@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.
- package/README.ko.md +3 -1
- package/README.md +6 -2
- package/README.pt-BR.md +1 -1
- package/README.zh-CN.md +3 -1
- package/build/config.js +12 -4
- package/build/deprecated-env.js +47 -0
- package/build/index.js +369 -184
- package/build/oauth-device-flow.js +80 -0
- package/build/oauth.js +135 -18
- package/build/schemas.js +1 -1
- package/build/server/remote-http-stack.js +39 -0
- package/build/tools/discover-activation.js +38 -0
- package/build/tools/exposed-tools.js +35 -0
- package/build/tools/listed-tools.js +76 -0
- package/build/tools/registry.js +226 -57
- package/build/tools/tool-profile.js +66 -0
- package/build/utils/compact-tool-allowlist.js +14 -0
- package/build/utils/logger.js +34 -12
- package/package.json +3 -3
- package/build/scripts/check-skill-sync.js +0 -143
- package/build/scripts/generate-server-card.js +0 -39
- package/build/scripts/generate-tool-coverage.js +0 -58
- package/build/scripts/generate-tool-docs.js +0 -430
- package/build/scripts/tool-coverage/coverage.js +0 -341
- package/build/scripts/tool-coverage/coverage.test.js +0 -142
- package/build/test/callback-proxy-tests.js +0 -321
- package/build/test/cli/args.test.js +0 -175
- package/build/test/cli/boolean-flags.test.js +0 -106
- package/build/test/cli/compact-mcp-result.test.js +0 -93
- package/build/test/cli/credentials.test.js +0 -153
- package/build/test/cli/exposure.test.js +0 -104
- package/build/test/cli/load-config-snapshot.js +0 -5
- package/build/test/cli/output.test.js +0 -74
- package/build/test/cli/replay-command.test.js +0 -37
- package/build/test/cli/router.test.js +0 -183
- package/build/test/client-pool-test.js +0 -109
- package/build/test/clients/client.js +0 -34
- package/build/test/clients/custom-header-client.js +0 -122
- package/build/test/clients/sse-client.js +0 -95
- package/build/test/clients/stdio-client.js +0 -113
- package/build/test/clients/streamable-http-client.js +0 -95
- package/build/test/config-allowed-groups.test.js +0 -97
- package/build/test/create-commit-actions.test.js +0 -102
- package/build/test/draft-note-schema.test.js +0 -44
- package/build/test/dynamic-api-url-allowlist.test.js +0 -121
- package/build/test/dynamic-api-url-test.js +0 -304
- package/build/test/dynamic-routing-tests.js +0 -495
- package/build/test/get-merge-request-discussion-schema.test.js +0 -30
- package/build/test/gitlab-api-tool-errors.test.js +0 -112
- package/build/test/gitlab-artifact-entry-schema.test.js +0 -44
- package/build/test/gitlab-diff-schema.test.js +0 -36
- package/build/test/gitlab-pipeline-schedule-schema.test.js +0 -32
- package/build/test/gitlab-tag-schema.test.js +0 -51
- package/build/test/group-milestone-schema.test.js +0 -45
- package/build/test/mcp-oauth-tests.js +0 -905
- package/build/test/mcp-server-name.test.js +0 -87
- package/build/test/merge-merge-request-schema.test.js +0 -75
- package/build/test/multi-server-test.js +0 -190
- package/build/test/no-proxy-integration-test.js +0 -183
- package/build/test/no-proxy-test.js +0 -149
- package/build/test/nullable-gitlab-response-fields.test.js +0 -37
- package/build/test/nullish-tool-arguments-schema.test.js +0 -118
- package/build/test/oauth-device-flow-tests.js +0 -450
- package/build/test/oauth-download-url.test.js +0 -157
- package/build/test/oauth-startup.test.js +0 -204
- package/build/test/oauth-tests.js +0 -428
- package/build/test/path-segment-encoding.test.js +0 -98
- package/build/test/remote-auth-simple-test.js +0 -277
- package/build/test/remote-auth-tests.js +0 -314
- package/build/test/response-masking.test.js +0 -445
- package/build/test/schema-tests.js +0 -1679
- package/build/test/server/metrics.test.js +0 -47
- package/build/test/server/request-helpers.test.js +0 -48
- package/build/test/server/version.test.js +0 -13
- package/build/test/sse-auth-guard.test.js +0 -96
- package/build/test/sse-session-limits.test.js +0 -273
- package/build/test/stateless/callback-proxy.test.js +0 -510
- package/build/test/stateless/client-id.test.js +0 -177
- package/build/test/stateless/codec.test.js +0 -328
- package/build/test/stateless/config-ttl.test.js +0 -149
- package/build/test/stateless/consumed-proxy-code-cache.test.js +0 -150
- package/build/test/stateless/session-id-integration.test.js +0 -675
- package/build/test/stateless/session-id.test.js +0 -157
- package/build/test/streamable-http-concurrent-session.test.js +0 -171
- package/build/test/streamable-http-dns-rebinding.test.js +0 -185
- package/build/test/streamable-http-sse-stream.test.js +0 -350
- package/build/test/streamable-http-static-token-auth.test.js +0 -157
- package/build/test/streamable-http-unauthenticated-discovery.test.js +0 -207
- package/build/test/test-all-transport-server.js +0 -255
- package/build/test/test-auth-retry.js +0 -195
- package/build/test/test-blank-filters.js +0 -156
- package/build/test/test-ci-catalog.js +0 -177
- package/build/test/test-ci-lint.js +0 -191
- package/build/test/test-ci-variables.js +0 -309
- package/build/test/test-create-repository.js +0 -120
- package/build/test/test-dependency-proxy.js +0 -195
- package/build/test/test-deployment-tools.js +0 -463
- package/build/test/test-download-attachment.js +0 -190
- package/build/test/test-dynamic-project-scope.js +0 -524
- package/build/test/test-empty-toolsets.js +0 -535
- package/build/test/test-get-file-blame.js +0 -145
- package/build/test/test-get-file-contents.js +0 -128
- package/build/test/test-geteffectiveprojectid.js +0 -804
- package/build/test/test-health-check.js +0 -115
- package/build/test/test-issue-description-patch.js +0 -256
- package/build/test/test-job-artifacts.js +0 -275
- package/build/test/test-json-schema.js +0 -166
- package/build/test/test-list-group-members.js +0 -150
- package/build/test/test-list-group-merge-requests.js +0 -165
- package/build/test/test-list-issues.js +0 -170
- package/build/test/test-list-merge-requests.js +0 -201
- package/build/test/test-list-milestones.js +0 -145
- package/build/test/test-list-project-members.js +0 -132
- package/build/test/test-merge-request-approval-state-tools.js +0 -213
- package/build/test/test-merge-request-approvals.js +0 -187
- package/build/test/test-merge-request-pipelines.js +0 -106
- package/build/test/test-mr-diffs-filter.js +0 -132
- package/build/test/test-mr-file-diffs.js +0 -251
- package/build/test/test-oauth-proxy-rate-limit.js +0 -133
- package/build/test/test-orbit.js +0 -155
- package/build/test/test-permission-mode.js +0 -424
- package/build/test/test-pipeline-schedules.js +0 -484
- package/build/test/test-protected-branches.js +0 -174
- package/build/test/test-remote-downloads.js +0 -510
- package/build/test/test-search-code.js +0 -275
- package/build/test/test-snippets.js +0 -735
- package/build/test/test-tags.js +0 -220
- package/build/test/test-todos.js +0 -195
- package/build/test/test-token-optimizations.js +0 -691
- package/build/test/test-toolset-filtering.js +0 -499
- package/build/test/test-update-issue-slim.js +0 -141
- package/build/test/test-update-project.js +0 -112
- package/build/test/test-upload-markdown.js +0 -206
- package/build/test/test-vulnerabilities.js +0 -399
- package/build/test/test-webhooks.js +0 -218
- package/build/test/tool-description-quality.test.js +0 -50
- package/build/test/utils/bulk-publish-options.test.js +0 -32
- package/build/test/utils/download-token.test.js +0 -35
- package/build/test/utils/forwarded-public-base-url.test.js +0 -46
- package/build/test/utils/gitlab-instance-version.test.js +0 -32
- package/build/test/utils/gitlab-version-gate.test.js +0 -74
- package/build/test/utils/graphql-query.test.js +0 -168
- package/build/test/utils/helpers-path.test.js +0 -104
- package/build/test/utils/jmespath-tool-result.test.js +0 -91
- package/build/test/utils/masking.test.js +0 -384
- package/build/test/utils/merge-request-position.test.js +0 -57
- package/build/test/utils/mock-gitlab-server.js +0 -614
- package/build/test/utils/proxy-client-ip.test.js +0 -28
- package/build/test/utils/redact-sensitive.test.js +0 -32
- package/build/test/utils/safe-redirect-fetch.test.js +0 -463
- package/build/test/utils/server-launcher.js +0 -231
- package/build/test/utils/tool-args.test.js +0 -210
- package/build/test/utils/url.test.js +0 -141
- package/build/test/utils/version-check.test.js +0 -239
- package/build/test/utils/wiki-title.test.js +0 -21
- package/build/test-note.js +0 -54
- package/build/test-resolve-issue-note.js +0 -127
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { after, before, describe, test } 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-approval";
|
|
6
|
-
const TEST_PROJECT_ID = "123";
|
|
7
|
-
const TEST_MR_IID_WITH_FALLBACK = "88";
|
|
8
|
-
const TEST_MR_IID_WITH_APPROVAL_STATE = "89";
|
|
9
|
-
const TEST_MR_IID_WITHOUT_RULES = "90";
|
|
10
|
-
async function callTool(toolName, args, env) {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const proc = spawn("node", ["build/index.js"], {
|
|
13
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
14
|
-
env: {
|
|
15
|
-
...process.env,
|
|
16
|
-
...env,
|
|
17
|
-
GITLAB_READ_ONLY_MODE: "true",
|
|
18
|
-
USE_PIPELINE: "true",
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
let output = "";
|
|
22
|
-
let errorOutput = "";
|
|
23
|
-
proc.stdout?.on("data", (d) => (output += d));
|
|
24
|
-
proc.stderr?.on("data", (d) => (errorOutput += d));
|
|
25
|
-
proc.on("close", (code) => {
|
|
26
|
-
if (code !== 0) {
|
|
27
|
-
return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
28
|
-
}
|
|
29
|
-
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
30
|
-
if (!line) {
|
|
31
|
-
return reject(new Error("No JSON output found"));
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const response = JSON.parse(line);
|
|
35
|
-
if (response.error) {
|
|
36
|
-
reject(response.error);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const content = response.result?.content?.[0]?.text;
|
|
40
|
-
if (content) {
|
|
41
|
-
try {
|
|
42
|
-
resolve(JSON.parse(content));
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
resolve(content);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
resolve(response.result);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
reject(error);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
proc.stdin?.end(JSON.stringify({
|
|
58
|
-
jsonrpc: "2.0",
|
|
59
|
-
id: 1,
|
|
60
|
-
method: "tools/call",
|
|
61
|
-
params: { name: toolName, arguments: args },
|
|
62
|
-
}) + "\n");
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
describe("merge request approval state tools", () => {
|
|
66
|
-
let mockGitLab;
|
|
67
|
-
let mockGitLabUrl;
|
|
68
|
-
before(async () => {
|
|
69
|
-
const mockPort = await findMockServerPort();
|
|
70
|
-
mockGitLab = new MockGitLabServer({
|
|
71
|
-
port: mockPort,
|
|
72
|
-
validTokens: [MOCK_TOKEN],
|
|
73
|
-
});
|
|
74
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MR_IID_WITH_FALLBACK}/approval_state`, (_req, res) => {
|
|
75
|
-
res.status(404).json({ error: "404 Not Found" });
|
|
76
|
-
});
|
|
77
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MR_IID_WITH_FALLBACK}/approvals`, (_req, res) => {
|
|
78
|
-
res.json({
|
|
79
|
-
approved: true,
|
|
80
|
-
user_has_approved: false,
|
|
81
|
-
user_can_approve: true,
|
|
82
|
-
approved_by: [
|
|
83
|
-
{
|
|
84
|
-
user: {
|
|
85
|
-
id: "35",
|
|
86
|
-
username: "sergey.kravchenya",
|
|
87
|
-
name: "Sergey Kravchenya",
|
|
88
|
-
state: "active",
|
|
89
|
-
avatar_url: "https://gitlab.mock/uploads/avatar.png",
|
|
90
|
-
web_url: "https://gitlab.mock/sergey.kravchenya",
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MR_IID_WITH_APPROVAL_STATE}/approval_state`, (_req, res) => {
|
|
97
|
-
res.json({
|
|
98
|
-
approval_rules_overwritten: false,
|
|
99
|
-
rules: [
|
|
100
|
-
{
|
|
101
|
-
id: "101",
|
|
102
|
-
name: "Default rule",
|
|
103
|
-
rule_type: "regular",
|
|
104
|
-
approvals_required: 1,
|
|
105
|
-
approved: true,
|
|
106
|
-
approved_by: [
|
|
107
|
-
{
|
|
108
|
-
id: "35",
|
|
109
|
-
username: "sergey.kravchenya",
|
|
110
|
-
name: "Sergey Kravchenya",
|
|
111
|
-
state: "active",
|
|
112
|
-
avatar_url: "https://gitlab.mock/uploads/avatar.png",
|
|
113
|
-
web_url: "https://gitlab.mock/sergey.kravchenya",
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
id: "102",
|
|
119
|
-
name: "Code owners",
|
|
120
|
-
rule_type: "code_owner",
|
|
121
|
-
approvals_required: 1,
|
|
122
|
-
approved: true,
|
|
123
|
-
approved_by: [
|
|
124
|
-
{
|
|
125
|
-
id: "35",
|
|
126
|
-
username: "sergey.kravchenya",
|
|
127
|
-
name: "Sergey Kravchenya",
|
|
128
|
-
state: "active",
|
|
129
|
-
avatar_url: "https://gitlab.mock/uploads/avatar.png",
|
|
130
|
-
web_url: "https://gitlab.mock/sergey.kravchenya",
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
// A project without approval rules answers 200 with an empty rules array, while
|
|
138
|
-
// the approval itself is only visible on /approvals.
|
|
139
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MR_IID_WITHOUT_RULES}/approval_state`, (_req, res) => {
|
|
140
|
-
res.json({
|
|
141
|
-
approval_rules_overwritten: false,
|
|
142
|
-
rules: [],
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MR_IID_WITHOUT_RULES}/approvals`, (_req, res) => {
|
|
146
|
-
res.json({
|
|
147
|
-
approved: true,
|
|
148
|
-
user_has_approved: false,
|
|
149
|
-
user_can_approve: true,
|
|
150
|
-
approved_by: [
|
|
151
|
-
{
|
|
152
|
-
user: {
|
|
153
|
-
id: "35",
|
|
154
|
-
username: "sergey.kravchenya",
|
|
155
|
-
name: "Sergey Kravchenya",
|
|
156
|
-
state: "active",
|
|
157
|
-
avatar_url: "https://gitlab.mock/uploads/avatar.png",
|
|
158
|
-
web_url: "https://gitlab.mock/sergey.kravchenya",
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
await mockGitLab.start();
|
|
165
|
-
mockGitLabUrl = mockGitLab.getUrl();
|
|
166
|
-
});
|
|
167
|
-
after(async () => {
|
|
168
|
-
await mockGitLab.stop();
|
|
169
|
-
});
|
|
170
|
-
test("falls back to approvals endpoint when approval_state is unavailable", async () => {
|
|
171
|
-
const result = await callTool("get_merge_request_approval_state", {
|
|
172
|
-
project_id: TEST_PROJECT_ID,
|
|
173
|
-
merge_request_iid: TEST_MR_IID_WITH_FALLBACK,
|
|
174
|
-
}, {
|
|
175
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
176
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
177
|
-
});
|
|
178
|
-
assert.strictEqual(result.source_endpoint, "approvals");
|
|
179
|
-
assert.strictEqual(result.approved, true);
|
|
180
|
-
assert.deepStrictEqual(result.approved_by_usernames, ["sergey.kravchenya"]);
|
|
181
|
-
assert.ok(Array.isArray(result.approved_by));
|
|
182
|
-
assert.strictEqual(result.approved_by[0].username, "sergey.kravchenya");
|
|
183
|
-
});
|
|
184
|
-
test("finds approvers via approvals when approval_state reports no rules", async () => {
|
|
185
|
-
const result = await callTool("get_merge_request_approval_state", {
|
|
186
|
-
project_id: TEST_PROJECT_ID,
|
|
187
|
-
merge_request_iid: TEST_MR_IID_WITHOUT_RULES,
|
|
188
|
-
}, {
|
|
189
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
190
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
191
|
-
});
|
|
192
|
-
assert.strictEqual(result.source_endpoint, "approvals");
|
|
193
|
-
assert.strictEqual(result.approved, true);
|
|
194
|
-
assert.deepStrictEqual(result.approved_by_usernames, ["sergey.kravchenya"]);
|
|
195
|
-
assert.ok(Array.isArray(result.approved_by));
|
|
196
|
-
assert.strictEqual(result.approved_by[0].username, "sergey.kravchenya");
|
|
197
|
-
});
|
|
198
|
-
test("returns deduplicated approvers from approval_state rules", async () => {
|
|
199
|
-
const result = await callTool("get_merge_request_approval_state", {
|
|
200
|
-
project_id: TEST_PROJECT_ID,
|
|
201
|
-
merge_request_iid: TEST_MR_IID_WITH_APPROVAL_STATE,
|
|
202
|
-
}, {
|
|
203
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
204
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
205
|
-
});
|
|
206
|
-
assert.strictEqual(result.source_endpoint, "approval_state");
|
|
207
|
-
assert.strictEqual(result.rules.length, 2);
|
|
208
|
-
assert.deepStrictEqual(result.approved_by_usernames, ["sergey.kravchenya"]);
|
|
209
|
-
assert.ok(Array.isArray(result.approved_by));
|
|
210
|
-
assert.strictEqual(result.approved_by.length, 1);
|
|
211
|
-
assert.strictEqual(result.approved_by[0].username, "sergey.kravchenya");
|
|
212
|
-
});
|
|
213
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env npx ts-node
|
|
2
|
-
/**
|
|
3
|
-
* Test script for merge request approval tools
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* GITLAB_PERSONAL_ACCESS_TOKEN=<token> GITLAB_PROJECT_ID=<project> npx ts-node test/test-merge-request-approvals.ts
|
|
7
|
-
*
|
|
8
|
-
* Optional: Set MERGE_REQUEST_IID to test a specific merge request
|
|
9
|
-
*/
|
|
10
|
-
import { spawn } from "child_process";
|
|
11
|
-
import path from "path";
|
|
12
|
-
import { fileURLToPath } from "url";
|
|
13
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
-
const __dirname = path.dirname(__filename);
|
|
15
|
-
const GITLAB_TOKEN = process.env.GITLAB_PERSONAL_ACCESS_TOKEN || process.env.GITLAB_TOKEN;
|
|
16
|
-
const GITLAB_PROJECT_ID = process.env.GITLAB_PROJECT_ID;
|
|
17
|
-
const GITLAB_API_URL = process.env.GITLAB_API_URL || "https://gitlab.com/api/v4";
|
|
18
|
-
const MERGE_REQUEST_IID = process.env.MERGE_REQUEST_IID;
|
|
19
|
-
async function sendMcpRequest(serverProcess, method, params) {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
const request = {
|
|
22
|
-
jsonrpc: "2.0",
|
|
23
|
-
id: Date.now(),
|
|
24
|
-
method,
|
|
25
|
-
params,
|
|
26
|
-
};
|
|
27
|
-
let responseData = "";
|
|
28
|
-
const onData = (data) => {
|
|
29
|
-
responseData += data.toString();
|
|
30
|
-
const lines = responseData.split("\n");
|
|
31
|
-
for (const line of lines) {
|
|
32
|
-
if (line.trim()) {
|
|
33
|
-
try {
|
|
34
|
-
const parsed = JSON.parse(line);
|
|
35
|
-
serverProcess.stdout?.off("data", onData);
|
|
36
|
-
resolve(parsed);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
// Continue accumulating data
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
serverProcess.stdout?.on("data", onData);
|
|
46
|
-
serverProcess.stdin?.write(JSON.stringify(request) + "\n");
|
|
47
|
-
setTimeout(() => {
|
|
48
|
-
serverProcess.stdout?.off("data", onData);
|
|
49
|
-
reject(new Error("Request timeout"));
|
|
50
|
-
}, 30000);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async function runTests() {
|
|
54
|
-
console.log("=== Merge Request Approval Tools Test ===\n");
|
|
55
|
-
if (!GITLAB_TOKEN) {
|
|
56
|
-
console.error("Error: GITLAB_PERSONAL_ACCESS_TOKEN or GITLAB_TOKEN environment variable is required");
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
if (!GITLAB_PROJECT_ID) {
|
|
60
|
-
console.error("Error: GITLAB_PROJECT_ID environment variable is required");
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
console.log(`GitLab API URL: ${GITLAB_API_URL}`);
|
|
64
|
-
console.log(`Project ID: ${GITLAB_PROJECT_ID}`);
|
|
65
|
-
console.log(`Merge Request IID: ${MERGE_REQUEST_IID || "(will find one)"}\n`);
|
|
66
|
-
// Start the MCP server
|
|
67
|
-
const serverPath = path.join(__dirname, "..", "build", "index.js");
|
|
68
|
-
const serverProcess = spawn("node", [serverPath], {
|
|
69
|
-
env: {
|
|
70
|
-
...process.env,
|
|
71
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: GITLAB_TOKEN,
|
|
72
|
-
GITLAB_API_URL,
|
|
73
|
-
},
|
|
74
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
75
|
-
});
|
|
76
|
-
serverProcess.stderr?.on("data", data => {
|
|
77
|
-
const msg = data.toString();
|
|
78
|
-
if (!msg.includes("GitLab MCP Server running")) {
|
|
79
|
-
console.error("Server stderr:", msg);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
// Wait for server to start
|
|
83
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
84
|
-
try {
|
|
85
|
-
// Initialize the MCP connection
|
|
86
|
-
console.log("1. Initializing MCP connection...");
|
|
87
|
-
await sendMcpRequest(serverProcess, "initialize", {
|
|
88
|
-
protocolVersion: "2024-11-05",
|
|
89
|
-
capabilities: {},
|
|
90
|
-
clientInfo: { name: "test-client", version: "1.0.0" },
|
|
91
|
-
});
|
|
92
|
-
console.log(" ✓ Connected\n");
|
|
93
|
-
// Find a merge request to test with
|
|
94
|
-
let mrIid = MERGE_REQUEST_IID;
|
|
95
|
-
if (!mrIid) {
|
|
96
|
-
console.log("2. Finding an open merge request...");
|
|
97
|
-
const listResponse = await sendMcpRequest(serverProcess, "tools/call", {
|
|
98
|
-
name: "list_merge_requests",
|
|
99
|
-
arguments: {
|
|
100
|
-
project_id: GITLAB_PROJECT_ID,
|
|
101
|
-
state: "opened",
|
|
102
|
-
per_page: 1,
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
if (listResponse.error) {
|
|
106
|
-
console.error(" ✗ Error:", listResponse.error.message);
|
|
107
|
-
process.exit(1);
|
|
108
|
-
}
|
|
109
|
-
const mrs = JSON.parse(listResponse.result?.content?.[0]?.text || "[]");
|
|
110
|
-
if (mrs.length === 0) {
|
|
111
|
-
console.log(" ⚠ No open merge requests found. Create one to test approval tools.");
|
|
112
|
-
process.exit(0);
|
|
113
|
-
}
|
|
114
|
-
mrIid = mrs[0].iid;
|
|
115
|
-
console.log(` ✓ Found MR !${mrIid}: ${mrs[0].title}\n`);
|
|
116
|
-
}
|
|
117
|
-
// Test get_merge_request_approval_state
|
|
118
|
-
console.log("3. Testing get_merge_request_approval_state...");
|
|
119
|
-
const approvalStateResponse = await sendMcpRequest(serverProcess, "tools/call", {
|
|
120
|
-
name: "get_merge_request_approval_state",
|
|
121
|
-
arguments: {
|
|
122
|
-
project_id: GITLAB_PROJECT_ID,
|
|
123
|
-
merge_request_iid: mrIid,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
if (approvalStateResponse.error) {
|
|
127
|
-
console.error(" ✗ Error:", approvalStateResponse.error.message);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
const state = JSON.parse(approvalStateResponse.result?.content?.[0]?.text || "{}");
|
|
131
|
-
console.log(" ✓ Got approval state");
|
|
132
|
-
console.log(` Rules: ${state.rules?.length || 0}`);
|
|
133
|
-
// Show details for each rule
|
|
134
|
-
for (const rule of state.rules || []) {
|
|
135
|
-
const approvedBy = rule.approved_by || [];
|
|
136
|
-
const approvedNames = approvedBy.map((u) => u.name).join(", ") || "none";
|
|
137
|
-
const status = rule.approved ? "✓ APPROVED" : "○ pending";
|
|
138
|
-
console.log(`\n Rule: "${rule.name}"`);
|
|
139
|
-
console.log(` Status: ${status}`);
|
|
140
|
-
console.log(` Required: ${rule.approvals_required} approval(s)`);
|
|
141
|
-
console.log(` Approved by: ${approvedNames} (${approvedBy.length}/${rule.approvals_required})`);
|
|
142
|
-
}
|
|
143
|
-
console.log();
|
|
144
|
-
}
|
|
145
|
-
// Test approve_merge_request
|
|
146
|
-
console.log("4. Testing approve_merge_request...");
|
|
147
|
-
const approveResponse = await sendMcpRequest(serverProcess, "tools/call", {
|
|
148
|
-
name: "approve_merge_request",
|
|
149
|
-
arguments: {
|
|
150
|
-
project_id: GITLAB_PROJECT_ID,
|
|
151
|
-
merge_request_iid: mrIid,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
if (approveResponse.error) {
|
|
155
|
-
console.log(" ✗ Approve error:", approveResponse.error);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
console.log(" ✓ Approved successfully");
|
|
159
|
-
}
|
|
160
|
-
// Wait 3 seconds before unapproving
|
|
161
|
-
console.log("\n Waiting 3 seconds...");
|
|
162
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
163
|
-
// Test unapprove_merge_request
|
|
164
|
-
console.log("\n5. Testing unapprove_merge_request...");
|
|
165
|
-
const unapproveResponse = await sendMcpRequest(serverProcess, "tools/call", {
|
|
166
|
-
name: "unapprove_merge_request",
|
|
167
|
-
arguments: {
|
|
168
|
-
project_id: GITLAB_PROJECT_ID,
|
|
169
|
-
merge_request_iid: mrIid,
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
if (unapproveResponse.error) {
|
|
173
|
-
console.log(" ✗ Unapprove error:", unapproveResponse.error);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
console.log(" ✓ Unapproved successfully");
|
|
177
|
-
}
|
|
178
|
-
console.log("\n=== Tests Complete ===");
|
|
179
|
-
}
|
|
180
|
-
finally {
|
|
181
|
-
serverProcess.kill();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
runTests().catch(error => {
|
|
185
|
-
console.error("Test failed:", error);
|
|
186
|
-
process.exit(1);
|
|
187
|
-
});
|
|
@@ -1,106 +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-mr-pipelines-test-token";
|
|
6
|
-
const TEST_PROJECT_ID = "123";
|
|
7
|
-
const TEST_MR_IID = "1";
|
|
8
|
-
async function callTool(toolName, args, env) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
const proc = spawn("node", ["build/index.js"], {
|
|
11
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
12
|
-
env: {
|
|
13
|
-
...process.env,
|
|
14
|
-
...env,
|
|
15
|
-
GITLAB_READ_ONLY_MODE: "true",
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
let output = "";
|
|
19
|
-
let errorOutput = "";
|
|
20
|
-
proc.stdout?.on("data", d => output += d);
|
|
21
|
-
proc.stderr?.on("data", d => errorOutput += d);
|
|
22
|
-
proc.on("close", code => {
|
|
23
|
-
if (code !== 0) {
|
|
24
|
-
reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
28
|
-
if (!line) {
|
|
29
|
-
reject(new Error("No JSON output found"));
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
const response = JSON.parse(line);
|
|
34
|
-
if (response.error) {
|
|
35
|
-
reject(response.error);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const content = response.result?.content?.[0]?.text;
|
|
39
|
-
resolve(content ? JSON.parse(content) : response.result);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
reject(error);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
proc.stdin?.end(JSON.stringify({
|
|
46
|
-
jsonrpc: "2.0",
|
|
47
|
-
id: 1,
|
|
48
|
-
method: "tools/call",
|
|
49
|
-
params: { name: toolName, arguments: args },
|
|
50
|
-
}) + "\n");
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
describe("list_merge_request_pipelines", () => {
|
|
54
|
-
let mockGitLab;
|
|
55
|
-
let mockGitLabUrl;
|
|
56
|
-
let lastQuery = {};
|
|
57
|
-
before(async () => {
|
|
58
|
-
const mockPort = await findMockServerPort();
|
|
59
|
-
mockGitLab = new MockGitLabServer({
|
|
60
|
-
port: mockPort,
|
|
61
|
-
validTokens: [MOCK_TOKEN],
|
|
62
|
-
});
|
|
63
|
-
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/merge_requests/${TEST_MR_IID}/pipelines`, (req, res) => {
|
|
64
|
-
lastQuery = { ...req.query };
|
|
65
|
-
res.json([
|
|
66
|
-
{
|
|
67
|
-
id: 77,
|
|
68
|
-
sha: "959e04d7c7a30600c894bd3c0cd0e1ce7f42c11d",
|
|
69
|
-
ref: "main",
|
|
70
|
-
status: "success",
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
id: 78,
|
|
74
|
-
sha: "a59e04d7c7a30600c894bd3c0cd0e1ce7f42c22e",
|
|
75
|
-
ref: "refs/merge-requests/1/head",
|
|
76
|
-
status: "running",
|
|
77
|
-
source: "merge_request_event",
|
|
78
|
-
web_url: "https://gitlab.mock/test/project/-/pipelines/78",
|
|
79
|
-
},
|
|
80
|
-
]);
|
|
81
|
-
});
|
|
82
|
-
await mockGitLab.start();
|
|
83
|
-
mockGitLabUrl = mockGitLab.getUrl();
|
|
84
|
-
});
|
|
85
|
-
after(async () => {
|
|
86
|
-
await mockGitLab.stop();
|
|
87
|
-
});
|
|
88
|
-
test("lists pipelines for a merge request", async () => {
|
|
89
|
-
const pipelines = await callTool("list_merge_request_pipelines", {
|
|
90
|
-
project_id: TEST_PROJECT_ID,
|
|
91
|
-
merge_request_iid: TEST_MR_IID,
|
|
92
|
-
page: 2,
|
|
93
|
-
per_page: 10,
|
|
94
|
-
}, {
|
|
95
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
96
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
97
|
-
});
|
|
98
|
-
assert.ok(Array.isArray(pipelines), "Response should be an array");
|
|
99
|
-
assert.strictEqual(pipelines.length, 2);
|
|
100
|
-
assert.strictEqual(pipelines[0].id, "77");
|
|
101
|
-
assert.strictEqual(pipelines[0].status, "success");
|
|
102
|
-
assert.strictEqual(pipelines[1].source, "merge_request_event");
|
|
103
|
-
assert.strictEqual(lastQuery.page, "2");
|
|
104
|
-
assert.strictEqual(lastQuery.per_page, "10");
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,132 +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
|
-
const TEST_MR_IID = '1';
|
|
8
|
-
// Helper to call get_merge_request_diffs
|
|
9
|
-
async function callGetMergeRequestDiffs(args = {}, env) {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
const proc = spawn('node', ['build/index.js'], {
|
|
12
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
13
|
-
env: {
|
|
14
|
-
...process.env,
|
|
15
|
-
...env,
|
|
16
|
-
GITLAB_READ_ONLY_MODE: 'true'
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
let output = '';
|
|
20
|
-
let errorOutput = '';
|
|
21
|
-
proc.stdout?.on('data', d => output += d);
|
|
22
|
-
proc.stderr?.on('data', d => errorOutput += d);
|
|
23
|
-
proc.on('close', (code) => {
|
|
24
|
-
if (code !== 0)
|
|
25
|
-
return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
26
|
-
// Find the JSON line in stdout
|
|
27
|
-
const line = output.split('\n').find(l => l.startsWith('{'));
|
|
28
|
-
if (!line)
|
|
29
|
-
return reject(new Error('No JSON output found'));
|
|
30
|
-
try {
|
|
31
|
-
const response = JSON.parse(line);
|
|
32
|
-
if (response.error) {
|
|
33
|
-
reject(response.error);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
// Parse the tool result content
|
|
37
|
-
const content = response.result?.content?.[0]?.text;
|
|
38
|
-
if (content) {
|
|
39
|
-
try {
|
|
40
|
-
resolve(JSON.parse(content));
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
reject(new Error(`Failed to parse tool output JSON: ${content}`));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
resolve(response.result);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
reject(e);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
proc.stdin?.end(JSON.stringify({
|
|
56
|
-
jsonrpc: "2.0", id: 1, method: "tools/call",
|
|
57
|
-
params: { name: "get_merge_request_diffs", arguments: args }
|
|
58
|
-
}) + '\n');
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
describe('get_merge_request_diffs with excluded_file_patterns', () => {
|
|
62
|
-
let mockGitLab;
|
|
63
|
-
let mockGitLabUrl;
|
|
64
|
-
before(async () => {
|
|
65
|
-
const mockPort = await findMockServerPort();
|
|
66
|
-
mockGitLab = new MockGitLabServer({
|
|
67
|
-
port: mockPort,
|
|
68
|
-
validTokens: [MOCK_TOKEN]
|
|
69
|
-
});
|
|
70
|
-
await mockGitLab.start();
|
|
71
|
-
mockGitLabUrl = mockGitLab.getUrl();
|
|
72
|
-
});
|
|
73
|
-
after(async () => {
|
|
74
|
-
await mockGitLab.stop();
|
|
75
|
-
});
|
|
76
|
-
test('returns all diffs without filtering', async () => {
|
|
77
|
-
const diffs = await callGetMergeRequestDiffs({ project_id: TEST_PROJECT_ID, merge_request_iid: TEST_MR_IID }, {
|
|
78
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
79
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
|
|
80
|
-
});
|
|
81
|
-
assert.ok(Array.isArray(diffs), 'Response should be an array');
|
|
82
|
-
assert.strictEqual(diffs.length, 4, 'Should return 4 diffs');
|
|
83
|
-
assert.strictEqual(diffs[0].new_path, 'src/index.ts');
|
|
84
|
-
assert.strictEqual(diffs[1].new_path, 'vendor/package/file.js');
|
|
85
|
-
assert.strictEqual(diffs[2].new_path, 'README.md');
|
|
86
|
-
assert.strictEqual(diffs[3].new_path, 'package-lock.json');
|
|
87
|
-
});
|
|
88
|
-
test('filters out vendor folder with ^vendor/ pattern', async () => {
|
|
89
|
-
const diffs = await callGetMergeRequestDiffs({
|
|
90
|
-
project_id: TEST_PROJECT_ID,
|
|
91
|
-
merge_request_iid: TEST_MR_IID,
|
|
92
|
-
excluded_file_patterns: ['^vendor/']
|
|
93
|
-
}, {
|
|
94
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
95
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
|
|
96
|
-
});
|
|
97
|
-
assert.ok(Array.isArray(diffs), 'Response should be an array');
|
|
98
|
-
assert.strictEqual(diffs.length, 3, 'Should return 3 diffs (vendor filtered out)');
|
|
99
|
-
assert.strictEqual(diffs[0].new_path, 'src/index.ts');
|
|
100
|
-
assert.strictEqual(diffs[1].new_path, 'README.md');
|
|
101
|
-
assert.strictEqual(diffs[2].new_path, 'package-lock.json');
|
|
102
|
-
});
|
|
103
|
-
test('filters out package-lock.json with package-lock pattern', async () => {
|
|
104
|
-
const diffs = await callGetMergeRequestDiffs({
|
|
105
|
-
project_id: TEST_PROJECT_ID,
|
|
106
|
-
merge_request_iid: TEST_MR_IID,
|
|
107
|
-
excluded_file_patterns: ['package-lock\\.json']
|
|
108
|
-
}, {
|
|
109
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
110
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
|
|
111
|
-
});
|
|
112
|
-
assert.ok(Array.isArray(diffs), 'Response should be an array');
|
|
113
|
-
assert.strictEqual(diffs.length, 3, 'Should return 3 diffs (package-lock.json filtered out)');
|
|
114
|
-
assert.strictEqual(diffs[0].new_path, 'src/index.ts');
|
|
115
|
-
assert.strictEqual(diffs[1].new_path, 'vendor/package/file.js');
|
|
116
|
-
assert.strictEqual(diffs[2].new_path, 'README.md');
|
|
117
|
-
});
|
|
118
|
-
test('filters multiple patterns at once', async () => {
|
|
119
|
-
const diffs = await callGetMergeRequestDiffs({
|
|
120
|
-
project_id: TEST_PROJECT_ID,
|
|
121
|
-
merge_request_iid: TEST_MR_IID,
|
|
122
|
-
excluded_file_patterns: ['^vendor/', 'package-lock\\.json']
|
|
123
|
-
}, {
|
|
124
|
-
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
125
|
-
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN
|
|
126
|
-
});
|
|
127
|
-
assert.ok(Array.isArray(diffs), 'Response should be an array');
|
|
128
|
-
assert.strictEqual(diffs.length, 2, 'Should return 2 diffs (vendor and package-lock filtered out)');
|
|
129
|
-
assert.strictEqual(diffs[0].new_path, 'src/index.ts');
|
|
130
|
-
assert.strictEqual(diffs[1].new_path, 'README.md');
|
|
131
|
-
});
|
|
132
|
-
});
|