@zereight/mcp-gitlab 2.1.15 → 2.1.17
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.md +10 -0
- package/build/index.js +241 -21
- package/build/schemas.js +151 -20
- package/build/test/nullish-tool-arguments-schema.test.js +99 -0
- package/build/test/schema-tests.js +116 -2
- package/build/test/test-ci-variables.js +306 -0
- package/build/test/test-geteffectiveprojectid.js +42 -0
- package/build/test/test-list-merge-requests.js +19 -0
- package/build/test/test-toolset-filtering.js +3 -0
- package/build/test/utils/merge-request-position.test.js +57 -0
- package/build/test/utils/tool-args.test.js +75 -0
- package/build/tools/registry.js +74 -2
- package/build/utils/merge-request-position.js +29 -0
- package/build/utils/tool-args.js +22 -0
- package/package.json +2 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, test } from "node:test";
|
|
3
|
+
import { CreateDraftNoteSchema, CreateLabelSchema, ExecuteGraphQLSchema, GetBranchDiffsSchema, UpdateMergeRequestDiscussionNoteSchema, } from "../schemas.js";
|
|
4
|
+
import { sanitizeToolArguments } from "../utils/tool-args.js";
|
|
5
|
+
const PROJECT_ID = "group/project";
|
|
6
|
+
const MERGE_REQUEST_IID = "1";
|
|
7
|
+
function parseAfterSanitize(toolName, raw, parse) {
|
|
8
|
+
return parse(sanitizeToolArguments(toolName, raw));
|
|
9
|
+
}
|
|
10
|
+
describe("When validating tool arguments after sanitization", () => {
|
|
11
|
+
describe("with create_draft_note", () => {
|
|
12
|
+
test("should accept position with null SHAs after sanitize and schema preprocess", () => {
|
|
13
|
+
const parsed = parseAfterSanitize("create_draft_note", {
|
|
14
|
+
project_id: PROJECT_ID,
|
|
15
|
+
merge_request_iid: MERGE_REQUEST_IID,
|
|
16
|
+
body: "Test note",
|
|
17
|
+
position: {
|
|
18
|
+
base_sha: null,
|
|
19
|
+
head_sha: null,
|
|
20
|
+
start_sha: null,
|
|
21
|
+
position_type: "text",
|
|
22
|
+
},
|
|
23
|
+
}, value => CreateDraftNoteSchema.parse(value));
|
|
24
|
+
assert.equal(parsed.position, undefined);
|
|
25
|
+
});
|
|
26
|
+
test("should accept position with nullable old_line after sanitize", () => {
|
|
27
|
+
const parsed = parseAfterSanitize("create_draft_note", {
|
|
28
|
+
project_id: PROJECT_ID,
|
|
29
|
+
merge_request_iid: MERGE_REQUEST_IID,
|
|
30
|
+
body: "Test note",
|
|
31
|
+
position: {
|
|
32
|
+
base_sha: "base",
|
|
33
|
+
head_sha: "head",
|
|
34
|
+
start_sha: "start",
|
|
35
|
+
position_type: "text",
|
|
36
|
+
new_path: "file.ts",
|
|
37
|
+
old_line: null,
|
|
38
|
+
new_line: 10,
|
|
39
|
+
},
|
|
40
|
+
}, value => CreateDraftNoteSchema.parse(value));
|
|
41
|
+
assert.equal(parsed.position?.old_line, null);
|
|
42
|
+
assert.equal(parsed.position?.new_line, 10);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe("with update_merge_request_discussion_note", () => {
|
|
46
|
+
test("should accept body plus resolved null after sanitize", () => {
|
|
47
|
+
const parsed = parseAfterSanitize("update_merge_request_discussion_note", {
|
|
48
|
+
project_id: PROJECT_ID,
|
|
49
|
+
merge_request_iid: MERGE_REQUEST_IID,
|
|
50
|
+
discussion_id: "d1",
|
|
51
|
+
note_id: "n1",
|
|
52
|
+
body: "updated",
|
|
53
|
+
resolved: null,
|
|
54
|
+
}, value => UpdateMergeRequestDiscussionNoteSchema.parse(value));
|
|
55
|
+
assert.equal(parsed.body, "updated");
|
|
56
|
+
assert.equal(parsed.resolved, undefined);
|
|
57
|
+
});
|
|
58
|
+
test("should reject when only resolved null remains after sanitize", () => {
|
|
59
|
+
assert.throws(() => parseAfterSanitize("update_merge_request_discussion_note", {
|
|
60
|
+
project_id: PROJECT_ID,
|
|
61
|
+
merge_request_iid: MERGE_REQUEST_IID,
|
|
62
|
+
discussion_id: "d1",
|
|
63
|
+
note_id: "n1",
|
|
64
|
+
resolved: null,
|
|
65
|
+
}, value => UpdateMergeRequestDiscussionNoteSchema.parse(value)), /At least one of 'body' or 'resolved'/);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("with get_branch_diffs", () => {
|
|
69
|
+
test("should ignore unknown commit null field from older clients", () => {
|
|
70
|
+
const parsed = parseAfterSanitize("get_branch_diffs", {
|
|
71
|
+
project_id: PROJECT_ID,
|
|
72
|
+
from: "main",
|
|
73
|
+
to: "dev",
|
|
74
|
+
commit: null,
|
|
75
|
+
}, value => GetBranchDiffsSchema.parse(value));
|
|
76
|
+
assert.equal(Object.hasOwn(parsed, "commit"), false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("with execute_graphql", () => {
|
|
80
|
+
test("should preserve explicit null variable values after sanitize", () => {
|
|
81
|
+
const parsed = parseAfterSanitize("execute_graphql", {
|
|
82
|
+
query: "mutation($id: ID) { updateProject(input: { id: $id }) { project { id } } }",
|
|
83
|
+
variables: { id: null },
|
|
84
|
+
}, value => ExecuteGraphQLSchema.parse(value));
|
|
85
|
+
assert.equal(parsed.variables?.id, null);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe("with create_label", () => {
|
|
89
|
+
test("should preserve explicit null priority after sanitize", () => {
|
|
90
|
+
const parsed = parseAfterSanitize("create_label", {
|
|
91
|
+
project_id: PROJECT_ID,
|
|
92
|
+
name: "priority-null",
|
|
93
|
+
color: "#112233",
|
|
94
|
+
priority: null,
|
|
95
|
+
}, value => CreateLabelSchema.parse(value));
|
|
96
|
+
assert.equal(parsed.priority, null);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -723,6 +723,54 @@ function runGitLabMergeRequestSchemaTests() {
|
|
|
723
723
|
},
|
|
724
724
|
validate: (data) => data.milestone === undefined,
|
|
725
725
|
},
|
|
726
|
+
{
|
|
727
|
+
name: 'schema:gitlab_merge_request:labels-string-array',
|
|
728
|
+
input: {
|
|
729
|
+
...baseMergeRequest,
|
|
730
|
+
labels: ['bug', 'enhancement'],
|
|
731
|
+
},
|
|
732
|
+
validate: (data) => Array.isArray(data.labels) &&
|
|
733
|
+
data.labels.length === 2 &&
|
|
734
|
+
data.labels[0] === 'bug' &&
|
|
735
|
+
data.labels[1] === 'enhancement',
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
name: 'schema:gitlab_merge_request:labels-object-array',
|
|
739
|
+
input: {
|
|
740
|
+
...baseMergeRequest,
|
|
741
|
+
labels: [
|
|
742
|
+
{
|
|
743
|
+
id: 1,
|
|
744
|
+
name: 'bug',
|
|
745
|
+
color: '#ff0000',
|
|
746
|
+
text_color: '#ffffff',
|
|
747
|
+
description: null,
|
|
748
|
+
description_html: null,
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
id: 2,
|
|
752
|
+
name: 'enhancement',
|
|
753
|
+
color: '#00ff00',
|
|
754
|
+
text_color: '#000000',
|
|
755
|
+
description: 'Improvements',
|
|
756
|
+
description_html: '<p>Improvements</p>',
|
|
757
|
+
},
|
|
758
|
+
],
|
|
759
|
+
},
|
|
760
|
+
validate: (data) => Array.isArray(data.labels) &&
|
|
761
|
+
data.labels.length === 2 &&
|
|
762
|
+
data.labels[0].name === 'bug' &&
|
|
763
|
+
data.labels[0].id === '1' &&
|
|
764
|
+
data.labels[1].name === 'enhancement' &&
|
|
765
|
+
data.labels[1].id === '2',
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
name: 'schema:gitlab_merge_request:labels-omitted',
|
|
769
|
+
input: {
|
|
770
|
+
...baseMergeRequest,
|
|
771
|
+
},
|
|
772
|
+
validate: (data) => data.labels === undefined,
|
|
773
|
+
},
|
|
726
774
|
];
|
|
727
775
|
let passed = 0;
|
|
728
776
|
let failed = 0;
|
|
@@ -955,6 +1003,71 @@ function runLabelsCoercionSchemaTests() {
|
|
|
955
1003
|
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
956
1004
|
return { passed, failed };
|
|
957
1005
|
}
|
|
1006
|
+
function runApprovedByUsernamesSchemaTests() {
|
|
1007
|
+
console.log('\n=== ListMergeRequestsSchema approved_by_usernames Tests ===');
|
|
1008
|
+
const cases = [
|
|
1009
|
+
{
|
|
1010
|
+
name: 'schema:list_merge_requests:approved_by_usernames-native-array',
|
|
1011
|
+
input: { approved_by_usernames: ['alice', 'bob'] },
|
|
1012
|
+
expected: ['alice', 'bob'],
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
name: 'schema:list_merge_requests:approved_by_usernames-stringified-array',
|
|
1016
|
+
input: { approved_by_usernames: '["alice","bob"]' },
|
|
1017
|
+
expected: ['alice', 'bob'],
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
name: 'schema:list_merge_requests:approved_by_usernames-omitted',
|
|
1021
|
+
input: {},
|
|
1022
|
+
expected: undefined,
|
|
1023
|
+
},
|
|
1024
|
+
];
|
|
1025
|
+
let passed = 0;
|
|
1026
|
+
let failed = 0;
|
|
1027
|
+
cases.forEach(testCase => {
|
|
1028
|
+
const result = { name: testCase.name, status: 'failed' };
|
|
1029
|
+
const parsed = ListMergeRequestsSchema.safeParse(testCase.input);
|
|
1030
|
+
if (testCase.shouldFail) {
|
|
1031
|
+
if (parsed.success) {
|
|
1032
|
+
result.error = 'Expected schema validation to fail';
|
|
1033
|
+
}
|
|
1034
|
+
else {
|
|
1035
|
+
result.status = 'passed';
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
else if (!parsed.success) {
|
|
1039
|
+
result.error = parsed.error?.message || 'Schema validation failed';
|
|
1040
|
+
}
|
|
1041
|
+
else {
|
|
1042
|
+
const actual = parsed.data['approved_by_usernames'];
|
|
1043
|
+
if (testCase.expected === undefined) {
|
|
1044
|
+
result.status = actual === undefined ? 'passed' : 'failed';
|
|
1045
|
+
if (actual !== undefined) {
|
|
1046
|
+
result.error = `Expected approved_by_usernames to be undefined, got ${JSON.stringify(actual)}`;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
const match = Array.isArray(actual) &&
|
|
1051
|
+
actual.length === testCase.expected.length &&
|
|
1052
|
+
testCase.expected.every((v, i) => actual[i] === v);
|
|
1053
|
+
result.status = match ? 'passed' : 'failed';
|
|
1054
|
+
if (!match) {
|
|
1055
|
+
result.error = `Expected ${JSON.stringify(testCase.expected)}, got ${JSON.stringify(actual)}`;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
if (result.status === 'passed') {
|
|
1060
|
+
passed++;
|
|
1061
|
+
console.log(`✅ ${result.name}`);
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
failed++;
|
|
1065
|
+
console.log(`❌ ${result.name}: ${result.error}`);
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1069
|
+
return { passed, failed };
|
|
1070
|
+
}
|
|
958
1071
|
function runListLabelsSchemaTests() {
|
|
959
1072
|
console.log('\n=== List Labels Schema Tests ===');
|
|
960
1073
|
const cases = [
|
|
@@ -1284,13 +1397,14 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|
|
1284
1397
|
const emojiReactionResult = runEmojiReactionSchemaTests();
|
|
1285
1398
|
const repositorySchemaResult = runGitLabRepositorySchemaTests();
|
|
1286
1399
|
const labelsCoercionResult = runLabelsCoercionSchemaTests();
|
|
1400
|
+
const approvedByUsernamesResult = runApprovedByUsernamesSchemaTests();
|
|
1287
1401
|
const listLabelsResult = runListLabelsSchemaTests();
|
|
1288
1402
|
const treeItemResult = runGitLabTreeItemSchemaTests();
|
|
1289
1403
|
const repositoryTreeResult = runGetRepositoryTreeSchemaTests();
|
|
1290
1404
|
const gitLabUserFullResult = runGitLabUserFullSchemaTests();
|
|
1291
1405
|
const gitLabMarkdownUploadResult = runGitLabMarkdownUploadSchemaTests();
|
|
1292
|
-
const totalPassed = getFileContentsResult.passed + fileContentResult.passed + createPipelineResult.passed + commitStatusResult.passed + createIssueNoteResult.passed + getMergeRequestResult.passed + listMergeRequestPipelinesResult.passed + gitLabMergeRequestResult.passed + emojiReactionResult.passed + repositorySchemaResult.passed + labelsCoercionResult.passed + listLabelsResult.passed + treeItemResult.passed + repositoryTreeResult.passed + gitLabUserFullResult.passed + gitLabMarkdownUploadResult.passed;
|
|
1293
|
-
const totalFailed = getFileContentsResult.failed + fileContentResult.failed + createPipelineResult.failed + commitStatusResult.failed + createIssueNoteResult.failed + getMergeRequestResult.failed + listMergeRequestPipelinesResult.failed + gitLabMergeRequestResult.failed + emojiReactionResult.failed + repositorySchemaResult.failed + labelsCoercionResult.failed + listLabelsResult.failed + treeItemResult.failed + repositoryTreeResult.failed + gitLabUserFullResult.failed + gitLabMarkdownUploadResult.failed;
|
|
1406
|
+
const totalPassed = getFileContentsResult.passed + fileContentResult.passed + createPipelineResult.passed + commitStatusResult.passed + createIssueNoteResult.passed + getMergeRequestResult.passed + listMergeRequestPipelinesResult.passed + gitLabMergeRequestResult.passed + emojiReactionResult.passed + repositorySchemaResult.passed + labelsCoercionResult.passed + approvedByUsernamesResult.passed + listLabelsResult.passed + treeItemResult.passed + repositoryTreeResult.passed + gitLabUserFullResult.passed + gitLabMarkdownUploadResult.passed;
|
|
1407
|
+
const totalFailed = getFileContentsResult.failed + fileContentResult.failed + createPipelineResult.failed + commitStatusResult.failed + createIssueNoteResult.failed + getMergeRequestResult.failed + listMergeRequestPipelinesResult.failed + gitLabMergeRequestResult.failed + emojiReactionResult.failed + repositorySchemaResult.failed + labelsCoercionResult.failed + approvedByUsernamesResult.failed + listLabelsResult.failed + treeItemResult.failed + repositoryTreeResult.failed + gitLabUserFullResult.failed + gitLabMarkdownUploadResult.failed;
|
|
1294
1408
|
console.log(`\nTotal Results: ${totalPassed} passed, ${totalFailed} failed`);
|
|
1295
1409
|
if (totalFailed > 0) {
|
|
1296
1410
|
process.exit(1);
|
|
@@ -0,0 +1,306 @@
|
|
|
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-ci-variables";
|
|
6
|
+
const TEST_PROJECT_ID = "123";
|
|
7
|
+
const TEST_GROUP_ID = "my-group";
|
|
8
|
+
const TEST_VAR_KEY = "DB_URL";
|
|
9
|
+
const TEST_GROUP_VAR_KEY = "SHARED_SECRET";
|
|
10
|
+
const TEST_HIDDEN_VAR_KEY = "HIDDEN_VAR";
|
|
11
|
+
const TEST_SCOPE = "production";
|
|
12
|
+
const MOCK_PROJECT_VARIABLE = {
|
|
13
|
+
variable_type: "env_var",
|
|
14
|
+
key: TEST_VAR_KEY,
|
|
15
|
+
value: "postgres://localhost/db",
|
|
16
|
+
protected: false,
|
|
17
|
+
masked: true,
|
|
18
|
+
raw: false,
|
|
19
|
+
environment_scope: "*",
|
|
20
|
+
description: "Database connection URL",
|
|
21
|
+
};
|
|
22
|
+
const MOCK_GROUP_VARIABLE = {
|
|
23
|
+
variable_type: "env_var",
|
|
24
|
+
key: TEST_GROUP_VAR_KEY,
|
|
25
|
+
value: "s3cr3t",
|
|
26
|
+
protected: false,
|
|
27
|
+
masked: true,
|
|
28
|
+
raw: false,
|
|
29
|
+
environment_scope: "*",
|
|
30
|
+
description: null,
|
|
31
|
+
};
|
|
32
|
+
const MOCK_HIDDEN_PROJECT_VARIABLE = {
|
|
33
|
+
...MOCK_PROJECT_VARIABLE,
|
|
34
|
+
key: TEST_HIDDEN_VAR_KEY,
|
|
35
|
+
value: null,
|
|
36
|
+
hidden: true,
|
|
37
|
+
description: null,
|
|
38
|
+
};
|
|
39
|
+
async function callTool(toolName, args, env) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const proc = spawn("node", ["build/index.js"], {
|
|
42
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
43
|
+
env: { ...process.env, ...env },
|
|
44
|
+
});
|
|
45
|
+
let output = "";
|
|
46
|
+
let errorOutput = "";
|
|
47
|
+
proc.stdout?.on("data", (d) => (output += d));
|
|
48
|
+
proc.stderr?.on("data", (d) => (errorOutput += d));
|
|
49
|
+
proc.on("close", code => {
|
|
50
|
+
if (code !== 0) {
|
|
51
|
+
return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
52
|
+
}
|
|
53
|
+
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
54
|
+
if (!line)
|
|
55
|
+
return reject(new Error("No JSON output found"));
|
|
56
|
+
try {
|
|
57
|
+
const response = JSON.parse(line);
|
|
58
|
+
if (response.error) {
|
|
59
|
+
reject(new Error(response.error?.message ?? String(response.error)));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const content = response.result?.content?.[0]?.text;
|
|
63
|
+
resolve(content ? JSON.parse(content) : response.result);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
reject(e);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
proc.stdin?.end(JSON.stringify({
|
|
71
|
+
jsonrpc: "2.0",
|
|
72
|
+
id: 1,
|
|
73
|
+
method: "tools/call",
|
|
74
|
+
params: { name: toolName, arguments: args },
|
|
75
|
+
}) + "\n");
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
describe("CI/CD variable tools", () => {
|
|
79
|
+
let mockServer;
|
|
80
|
+
let mockPort;
|
|
81
|
+
let baseEnv;
|
|
82
|
+
let lastReceivedFilterScope;
|
|
83
|
+
before(async () => {
|
|
84
|
+
mockPort = await findMockServerPort();
|
|
85
|
+
mockServer = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
|
|
86
|
+
// --- Project variable endpoints ---
|
|
87
|
+
mockServer.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/variables`, (_req, res) => {
|
|
88
|
+
res.json([MOCK_PROJECT_VARIABLE]);
|
|
89
|
+
});
|
|
90
|
+
mockServer.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/variables/${TEST_VAR_KEY}`, (req, res) => {
|
|
91
|
+
const scope = req.query["filter[environment_scope]"];
|
|
92
|
+
lastReceivedFilterScope = scope;
|
|
93
|
+
res.json({ ...MOCK_PROJECT_VARIABLE, environment_scope: scope ?? "*" });
|
|
94
|
+
});
|
|
95
|
+
mockServer.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/variables/${TEST_HIDDEN_VAR_KEY}`, (_req, res) => {
|
|
96
|
+
res.json(MOCK_HIDDEN_PROJECT_VARIABLE);
|
|
97
|
+
});
|
|
98
|
+
mockServer.addMockHandler("post", `/projects/${TEST_PROJECT_ID}/variables`, (req, res) => {
|
|
99
|
+
res.status(201).json({ ...MOCK_PROJECT_VARIABLE, ...req.body });
|
|
100
|
+
});
|
|
101
|
+
mockServer.addMockHandler("put", `/projects/${TEST_PROJECT_ID}/variables/${TEST_VAR_KEY}`, (req, res) => {
|
|
102
|
+
const scope = req.query["filter[environment_scope]"];
|
|
103
|
+
lastReceivedFilterScope = scope;
|
|
104
|
+
res.json({ ...MOCK_PROJECT_VARIABLE, ...req.body, environment_scope: scope ?? "*" });
|
|
105
|
+
});
|
|
106
|
+
mockServer.addMockHandler("delete", `/projects/${TEST_PROJECT_ID}/variables/${TEST_VAR_KEY}`, (req, res) => {
|
|
107
|
+
lastReceivedFilterScope = req.query["filter[environment_scope]"];
|
|
108
|
+
res.status(204).send();
|
|
109
|
+
});
|
|
110
|
+
// --- Group variable endpoints ---
|
|
111
|
+
mockServer.addMockHandler("get", `/groups/${TEST_GROUP_ID}/variables`, (_req, res) => {
|
|
112
|
+
res.json([MOCK_GROUP_VARIABLE]);
|
|
113
|
+
});
|
|
114
|
+
mockServer.addMockHandler("get", `/groups/${TEST_GROUP_ID}/variables/${TEST_GROUP_VAR_KEY}`, (_req, res) => {
|
|
115
|
+
res.json(MOCK_GROUP_VARIABLE);
|
|
116
|
+
});
|
|
117
|
+
mockServer.addMockHandler("post", `/groups/${TEST_GROUP_ID}/variables`, (req, res) => {
|
|
118
|
+
res.status(201).json({ ...MOCK_GROUP_VARIABLE, ...req.body });
|
|
119
|
+
});
|
|
120
|
+
mockServer.addMockHandler("put", `/groups/${TEST_GROUP_ID}/variables/${TEST_GROUP_VAR_KEY}`, (req, res) => {
|
|
121
|
+
res.json({ ...MOCK_GROUP_VARIABLE, ...req.body });
|
|
122
|
+
});
|
|
123
|
+
mockServer.addMockHandler("delete", `/groups/${TEST_GROUP_ID}/variables/${TEST_GROUP_VAR_KEY}`, (_req, res) => {
|
|
124
|
+
res.status(204).send();
|
|
125
|
+
});
|
|
126
|
+
await mockServer.start();
|
|
127
|
+
baseEnv = {
|
|
128
|
+
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
129
|
+
GITLAB_API_URL: `http://localhost:${mockPort}/api/v4`,
|
|
130
|
+
GITLAB_TOOLSETS: "variables",
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
after(async () => {
|
|
134
|
+
await mockServer.stop();
|
|
135
|
+
});
|
|
136
|
+
// --- Project variable tests ---
|
|
137
|
+
test("list_project_variables returns variable array", async () => {
|
|
138
|
+
const result = await callTool("list_project_variables", { project_id: TEST_PROJECT_ID }, baseEnv);
|
|
139
|
+
assert.ok(Array.isArray(result));
|
|
140
|
+
assert.strictEqual(result.length, 1);
|
|
141
|
+
assert.strictEqual(result[0].key, TEST_VAR_KEY);
|
|
142
|
+
assert.strictEqual(result[0].value, MOCK_PROJECT_VARIABLE.value);
|
|
143
|
+
assert.strictEqual(result[0].masked, true);
|
|
144
|
+
});
|
|
145
|
+
test("get_project_variable returns single variable", async () => {
|
|
146
|
+
const result = await callTool("get_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY }, baseEnv);
|
|
147
|
+
assert.strictEqual(result.key, TEST_VAR_KEY);
|
|
148
|
+
assert.strictEqual(result.environment_scope, "*");
|
|
149
|
+
assert.strictEqual(result.variable_type, "env_var");
|
|
150
|
+
});
|
|
151
|
+
test("get_project_variable returns hidden variable with null value", async () => {
|
|
152
|
+
const result = await callTool("get_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_HIDDEN_VAR_KEY }, baseEnv);
|
|
153
|
+
assert.strictEqual(result.key, TEST_HIDDEN_VAR_KEY);
|
|
154
|
+
assert.strictEqual(result.value, null);
|
|
155
|
+
assert.strictEqual(result.hidden, true);
|
|
156
|
+
});
|
|
157
|
+
test("create_project_variable returns created variable", async () => {
|
|
158
|
+
const result = await callTool("create_project_variable", {
|
|
159
|
+
project_id: TEST_PROJECT_ID,
|
|
160
|
+
key: TEST_VAR_KEY,
|
|
161
|
+
value: "new-value",
|
|
162
|
+
masked: true,
|
|
163
|
+
}, baseEnv);
|
|
164
|
+
assert.strictEqual(result.key, TEST_VAR_KEY);
|
|
165
|
+
assert.strictEqual(result.value, "new-value");
|
|
166
|
+
});
|
|
167
|
+
test("update_project_variable returns updated variable", async () => {
|
|
168
|
+
const result = await callTool("update_project_variable", {
|
|
169
|
+
project_id: TEST_PROJECT_ID,
|
|
170
|
+
key: TEST_VAR_KEY,
|
|
171
|
+
value: "updated-value",
|
|
172
|
+
}, baseEnv);
|
|
173
|
+
assert.strictEqual(result.value, "updated-value");
|
|
174
|
+
});
|
|
175
|
+
test("delete_project_variable returns success status", async () => {
|
|
176
|
+
const result = await callTool("delete_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY }, baseEnv);
|
|
177
|
+
assert.strictEqual(result.status, "success");
|
|
178
|
+
assert.ok(result.message.includes(TEST_VAR_KEY));
|
|
179
|
+
});
|
|
180
|
+
// --- Group variable tests ---
|
|
181
|
+
test("list_group_variables returns variable array", async () => {
|
|
182
|
+
const result = await callTool("list_group_variables", { group_id: TEST_GROUP_ID }, baseEnv);
|
|
183
|
+
assert.ok(Array.isArray(result));
|
|
184
|
+
assert.strictEqual(result.length, 1);
|
|
185
|
+
assert.strictEqual(result[0].key, TEST_GROUP_VAR_KEY);
|
|
186
|
+
assert.strictEqual(result[0].masked, true);
|
|
187
|
+
});
|
|
188
|
+
test("get_group_variable returns single variable", async () => {
|
|
189
|
+
const result = await callTool("get_group_variable", { group_id: TEST_GROUP_ID, key: TEST_GROUP_VAR_KEY }, baseEnv);
|
|
190
|
+
assert.strictEqual(result.key, TEST_GROUP_VAR_KEY);
|
|
191
|
+
assert.strictEqual(result.variable_type, "env_var");
|
|
192
|
+
});
|
|
193
|
+
test("create_group_variable returns created variable", async () => {
|
|
194
|
+
const result = await callTool("create_group_variable", {
|
|
195
|
+
group_id: TEST_GROUP_ID,
|
|
196
|
+
key: TEST_GROUP_VAR_KEY,
|
|
197
|
+
value: "new-secret",
|
|
198
|
+
masked: true,
|
|
199
|
+
}, baseEnv);
|
|
200
|
+
assert.strictEqual(result.key, TEST_GROUP_VAR_KEY);
|
|
201
|
+
assert.strictEqual(result.value, "new-secret");
|
|
202
|
+
});
|
|
203
|
+
test("update_group_variable returns updated variable", async () => {
|
|
204
|
+
const result = await callTool("update_group_variable", {
|
|
205
|
+
group_id: TEST_GROUP_ID,
|
|
206
|
+
key: TEST_GROUP_VAR_KEY,
|
|
207
|
+
value: "updated-secret",
|
|
208
|
+
}, baseEnv);
|
|
209
|
+
assert.strictEqual(result.value, "updated-secret");
|
|
210
|
+
});
|
|
211
|
+
test("delete_group_variable returns success status", async () => {
|
|
212
|
+
const result = await callTool("delete_group_variable", { group_id: TEST_GROUP_ID, key: TEST_GROUP_VAR_KEY }, baseEnv);
|
|
213
|
+
assert.strictEqual(result.status, "success");
|
|
214
|
+
assert.ok(result.message.includes(TEST_GROUP_VAR_KEY));
|
|
215
|
+
});
|
|
216
|
+
// --- filter[environment_scope] tests ---
|
|
217
|
+
test("get_project_variable passes filter[environment_scope] to GitLab", async () => {
|
|
218
|
+
lastReceivedFilterScope = undefined;
|
|
219
|
+
const result = await callTool("get_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY, filter: { environment_scope: TEST_SCOPE } }, baseEnv);
|
|
220
|
+
assert.strictEqual(lastReceivedFilterScope, TEST_SCOPE);
|
|
221
|
+
assert.strictEqual(result.environment_scope, TEST_SCOPE);
|
|
222
|
+
});
|
|
223
|
+
test("update_project_variable passes filter[environment_scope] to GitLab", async () => {
|
|
224
|
+
lastReceivedFilterScope = undefined;
|
|
225
|
+
const result = await callTool("update_project_variable", {
|
|
226
|
+
project_id: TEST_PROJECT_ID,
|
|
227
|
+
key: TEST_VAR_KEY,
|
|
228
|
+
value: "scoped-value",
|
|
229
|
+
filter: { environment_scope: TEST_SCOPE },
|
|
230
|
+
}, baseEnv);
|
|
231
|
+
assert.strictEqual(lastReceivedFilterScope, TEST_SCOPE);
|
|
232
|
+
assert.strictEqual(result.environment_scope, TEST_SCOPE);
|
|
233
|
+
});
|
|
234
|
+
test("delete_project_variable passes filter[environment_scope] to GitLab", async () => {
|
|
235
|
+
lastReceivedFilterScope = undefined;
|
|
236
|
+
const result = await callTool("delete_project_variable", { project_id: TEST_PROJECT_ID, key: TEST_VAR_KEY, filter: { environment_scope: TEST_SCOPE } }, baseEnv);
|
|
237
|
+
assert.strictEqual(lastReceivedFilterScope, TEST_SCOPE);
|
|
238
|
+
assert.strictEqual(result.status, "success");
|
|
239
|
+
});
|
|
240
|
+
// --- Toolset behaviour ---
|
|
241
|
+
test("variables tools are absent when toolset is not activated", async () => {
|
|
242
|
+
return new Promise((resolve, reject) => {
|
|
243
|
+
const proc = spawn("node", ["build/index.js"], {
|
|
244
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
245
|
+
env: {
|
|
246
|
+
...process.env,
|
|
247
|
+
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
248
|
+
GITLAB_API_URL: `http://localhost:${mockPort}/api/v4`,
|
|
249
|
+
// No GITLAB_TOOLSETS — default toolsets only
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
let output = "";
|
|
253
|
+
proc.stdout?.on("data", (d) => (output += d));
|
|
254
|
+
proc.on("close", () => {
|
|
255
|
+
try {
|
|
256
|
+
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
257
|
+
if (!line)
|
|
258
|
+
return reject(new Error("No JSON output found"));
|
|
259
|
+
const response = JSON.parse(line);
|
|
260
|
+
const names = (response.result?.tools ?? []).map((t) => t.name);
|
|
261
|
+
assert.ok(!names.includes("list_project_variables"), "tool should not be in default toolset");
|
|
262
|
+
assert.ok(!names.includes("create_project_variable"), "tool should not be in default toolset");
|
|
263
|
+
assert.ok(!names.includes("list_group_variables"), "tool should not be in default toolset");
|
|
264
|
+
resolve();
|
|
265
|
+
}
|
|
266
|
+
catch (e) {
|
|
267
|
+
reject(e);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
proc.stdin?.end(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }) + "\n");
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
test("write tools are absent from tools/list in read-only mode", async () => {
|
|
274
|
+
return new Promise((resolve, reject) => {
|
|
275
|
+
const proc = spawn("node", ["build/index.js"], {
|
|
276
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
277
|
+
env: { ...process.env, ...baseEnv, GITLAB_READ_ONLY_MODE: "true" },
|
|
278
|
+
});
|
|
279
|
+
let output = "";
|
|
280
|
+
proc.stdout?.on("data", (d) => (output += d));
|
|
281
|
+
proc.on("close", () => {
|
|
282
|
+
try {
|
|
283
|
+
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
284
|
+
if (!line)
|
|
285
|
+
return reject(new Error("No JSON output found"));
|
|
286
|
+
const response = JSON.parse(line);
|
|
287
|
+
const names = (response.result?.tools ?? []).map((t) => t.name);
|
|
288
|
+
assert.ok(!names.includes("create_project_variable"), "create should be absent in read-only mode");
|
|
289
|
+
assert.ok(!names.includes("update_project_variable"), "update should be absent in read-only mode");
|
|
290
|
+
assert.ok(!names.includes("delete_project_variable"), "delete should be absent in read-only mode");
|
|
291
|
+
assert.ok(!names.includes("create_group_variable"), "create should be absent in read-only mode");
|
|
292
|
+
assert.ok(!names.includes("delete_group_variable"), "delete should be absent in read-only mode");
|
|
293
|
+
assert.ok(names.includes("list_project_variables"), "list should be present in read-only mode");
|
|
294
|
+
assert.ok(names.includes("get_project_variable"), "get should be present in read-only mode");
|
|
295
|
+
assert.ok(names.includes("list_group_variables"), "list should be present in read-only mode");
|
|
296
|
+
assert.ok(names.includes("get_group_variable"), "get should be present in read-only mode");
|
|
297
|
+
resolve();
|
|
298
|
+
}
|
|
299
|
+
catch (e) {
|
|
300
|
+
reject(e);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
proc.stdin?.end(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }) + "\n");
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|
|
@@ -271,6 +271,7 @@ describe('getEffectiveProjectId', { concurrency: 1 }, () => {
|
|
|
271
271
|
REMOTE_AUTHORIZATION: 'true',
|
|
272
272
|
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
273
273
|
GITLAB_PROJECT_ID: DEFAULT_PROJECT_ID,
|
|
274
|
+
GITLAB_TOOLSETS: 'variables',
|
|
274
275
|
}
|
|
275
276
|
});
|
|
276
277
|
servers.push(server);
|
|
@@ -317,6 +318,26 @@ describe('getEffectiveProjectId', { concurrency: 1 }, () => {
|
|
|
317
318
|
assert.ok(error.message.includes('create_group is not allowed'), 'Should mention create_group');
|
|
318
319
|
}
|
|
319
320
|
});
|
|
321
|
+
test('should reject list_group_variables when GITLAB_PROJECT_ID is set', async () => {
|
|
322
|
+
try {
|
|
323
|
+
await client.callTool('list_group_variables', { group_id: 'my-group' });
|
|
324
|
+
assert.fail('Should have rejected list_group_variables');
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
assert.ok(error instanceof Error);
|
|
328
|
+
assert.ok(error.message.includes('list_group_variables is not allowed'), 'Should mention list_group_variables');
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
test('should reject get_group_variable when GITLAB_PROJECT_ID is set', async () => {
|
|
332
|
+
try {
|
|
333
|
+
await client.callTool('get_group_variable', { group_id: 'my-group', key: 'SHARED_SECRET' });
|
|
334
|
+
assert.fail('Should have rejected get_group_variable');
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
assert.ok(error instanceof Error);
|
|
338
|
+
assert.ok(error.message.includes('get_group_variable is not allowed'), 'Should mention get_group_variable');
|
|
339
|
+
}
|
|
340
|
+
});
|
|
320
341
|
test('should allow get_project (non-mutator) when GITLAB_PROJECT_ID is set', async () => {
|
|
321
342
|
const result = await client.callTool('get_project', { project_id: '' });
|
|
322
343
|
assert.ok(result.content, 'Should have content');
|
|
@@ -348,6 +369,7 @@ describe('getEffectiveProjectId', { concurrency: 1 }, () => {
|
|
|
348
369
|
REMOTE_AUTHORIZATION: 'true',
|
|
349
370
|
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
350
371
|
GITLAB_ALLOWED_PROJECT_IDS: DEFAULT_PROJECT_ID,
|
|
372
|
+
GITLAB_TOOLSETS: 'variables',
|
|
351
373
|
}
|
|
352
374
|
});
|
|
353
375
|
servers.push(server);
|
|
@@ -394,6 +416,26 @@ describe('getEffectiveProjectId', { concurrency: 1 }, () => {
|
|
|
394
416
|
assert.ok(error.message.includes('create_group is not allowed'), 'Should mention create_group');
|
|
395
417
|
}
|
|
396
418
|
});
|
|
419
|
+
test('should reject list_group_variables with GITLAB_ALLOWED_PROJECT_IDS', async () => {
|
|
420
|
+
try {
|
|
421
|
+
await client.callTool('list_group_variables', { group_id: 'my-group' });
|
|
422
|
+
assert.fail('Should have rejected list_group_variables');
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
assert.ok(error instanceof Error);
|
|
426
|
+
assert.ok(error.message.includes('list_group_variables is not allowed'), 'Should mention list_group_variables');
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
test('should reject get_group_variable with GITLAB_ALLOWED_PROJECT_IDS', async () => {
|
|
430
|
+
try {
|
|
431
|
+
await client.callTool('get_group_variable', { group_id: 'my-group', key: 'SHARED_SECRET' });
|
|
432
|
+
assert.fail('Should have rejected get_group_variable');
|
|
433
|
+
}
|
|
434
|
+
catch (error) {
|
|
435
|
+
assert.ok(error instanceof Error);
|
|
436
|
+
assert.ok(error.message.includes('get_group_variable is not allowed'), 'Should mention get_group_variable');
|
|
437
|
+
}
|
|
438
|
+
});
|
|
397
439
|
test('should allow get_project (non-mutator) with GITLAB_ALLOWED_PROJECT_IDS', async () => {
|
|
398
440
|
const result = await client.callTool('get_project', { project_id: '' });
|
|
399
441
|
assert.ok(result.content, 'Should have content');
|
|
@@ -103,4 +103,23 @@ describe('list_merge_requests', () => {
|
|
|
103
103
|
assert.ok(Array.isArray(mrs), 'Response should be an array');
|
|
104
104
|
assert.strictEqual(mrs.length, 2, 'Should return 2 mock MRs');
|
|
105
105
|
});
|
|
106
|
+
test('forwards approved_by_usernames in bracket-array form', async () => {
|
|
107
|
+
let capturedUrl;
|
|
108
|
+
mockGitLab.addMockHandler('get', '/merge_requests', (req, res) => {
|
|
109
|
+
capturedUrl = req.originalUrl;
|
|
110
|
+
res.json([]);
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
await callListMergeRequests({ approved_by_usernames: ['alice', 'bob'] }, {
|
|
114
|
+
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
115
|
+
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
116
|
+
});
|
|
117
|
+
assert.ok(capturedUrl, 'Mock handler should have received a request');
|
|
118
|
+
assert.match(capturedUrl, /approved_by_usernames%5B%5D=alice/, 'Request URL should contain approved_by_usernames[]=alice (URL-encoded)');
|
|
119
|
+
assert.match(capturedUrl, /approved_by_usernames%5B%5D=bob/, 'Request URL should contain approved_by_usernames[]=bob (URL-encoded)');
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
mockGitLab.clearCustomHandlers();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
106
125
|
});
|
|
@@ -33,6 +33,7 @@ const TOOLSET_TOOL_COUNTS = {
|
|
|
33
33
|
workitems: 18,
|
|
34
34
|
webhooks: 3,
|
|
35
35
|
groups: 1,
|
|
36
|
+
variables: 10,
|
|
36
37
|
};
|
|
37
38
|
const LEGACY_PIPELINE_TOOL_COUNT = TOOLSET_TOOL_COUNTS.pipelines + TOOLSET_TOOL_COUNTS.ci;
|
|
38
39
|
const DEFAULT_TOOLSETS = [
|
|
@@ -55,6 +56,7 @@ const NON_DEFAULT_TOOLSETS = [
|
|
|
55
56
|
"workitems",
|
|
56
57
|
"webhooks",
|
|
57
58
|
"search",
|
|
59
|
+
"variables",
|
|
58
60
|
];
|
|
59
61
|
// discover_tools meta-tool is always force-injected (Step 5.5)
|
|
60
62
|
const DISCOVER_TOOLS_COUNT = 1;
|
|
@@ -78,6 +80,7 @@ const TOOLSET_SAMPLE_TOOLS = {
|
|
|
78
80
|
search: ["search_code", "search_project_code", "search_group_code"],
|
|
79
81
|
webhooks: ["list_webhooks", "list_webhook_events", "get_webhook_event"],
|
|
80
82
|
groups: ["create_group"],
|
|
83
|
+
variables: ["list_project_variables", "create_project_variable", "delete_project_variable", "list_group_variables", "create_group_variable", "delete_group_variable"],
|
|
81
84
|
};
|
|
82
85
|
// --- Helpers ---
|
|
83
86
|
async function launchMcpServer(mockGitLabUrl, mcpPort, extraEnv = {}) {
|