@zereight/mcp-gitlab 2.1.63 → 2.1.64
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 +1 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/build/index.js +84 -215
- package/build/schemas.js +2 -2
- package/build/scripts/generate-tool-coverage.js +58 -0
- package/build/scripts/generate-tool-docs.js +3 -0
- package/build/scripts/tool-coverage/coverage.js +339 -0
- package/build/scripts/tool-coverage/coverage.test.js +142 -0
- package/build/test/test-blank-filters.js +156 -0
- package/build/test/test-empty-toolsets.js +535 -0
- package/build/test/test-list-issues.js +47 -0
- package/build/test/test-list-merge-requests.js +76 -0
- package/build/test/test-list-milestones.js +145 -0
- package/build/test/utils/tool-args.test.js +57 -1
- package/build/utils/tool-args.js +35 -0
- package/package.json +2 -1
|
@@ -0,0 +1,145 @@
|
|
|
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_GROUP_ID = "my-group";
|
|
8
|
+
// Milestone tools live in the non-default "milestones" toolset
|
|
9
|
+
const TOOLSET_ENV = { GITLAB_TOOLSETS: "milestones" };
|
|
10
|
+
// Helper to run an MCP tool through the stdio server
|
|
11
|
+
async function callTool(toolName, args, env) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const proc = spawn("node", ["build/index.js"], {
|
|
14
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
15
|
+
env: {
|
|
16
|
+
...process.env,
|
|
17
|
+
...TOOLSET_ENV,
|
|
18
|
+
...env,
|
|
19
|
+
GITLAB_READ_ONLY_MODE: "true",
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
let output = "";
|
|
23
|
+
let errorOutput = "";
|
|
24
|
+
proc.stdout?.on("data", d => (output += d));
|
|
25
|
+
proc.stderr?.on("data", d => (errorOutput += d));
|
|
26
|
+
proc.on("close", code => {
|
|
27
|
+
if (code !== 0)
|
|
28
|
+
return reject(new Error(`Process exited with code ${code}: ${errorOutput}`));
|
|
29
|
+
const line = output.split("\n").find(l => l.startsWith("{"));
|
|
30
|
+
if (!line)
|
|
31
|
+
return reject(new Error("No JSON output found"));
|
|
32
|
+
try {
|
|
33
|
+
const response = JSON.parse(line);
|
|
34
|
+
if (response.error) {
|
|
35
|
+
reject(new Error(JSON.stringify(response.error)));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const content = response.result?.content?.[0]?.text;
|
|
39
|
+
if (content) {
|
|
40
|
+
try {
|
|
41
|
+
resolve(JSON.parse(content));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
reject(new Error(`Failed to parse tool output JSON: ${content}`));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
resolve(response.result);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
proc.stdin?.end(JSON.stringify({
|
|
56
|
+
jsonrpc: "2.0",
|
|
57
|
+
id: 1,
|
|
58
|
+
method: "tools/call",
|
|
59
|
+
params: { name: toolName, arguments: args },
|
|
60
|
+
}) + "\n");
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
describe("milestone list iids filters", () => {
|
|
64
|
+
let mockGitLab;
|
|
65
|
+
let mockGitLabUrl;
|
|
66
|
+
before(async () => {
|
|
67
|
+
const mockPort = await findMockServerPort();
|
|
68
|
+
mockGitLab = new MockGitLabServer({ port: mockPort, validTokens: [MOCK_TOKEN] });
|
|
69
|
+
await mockGitLab.start();
|
|
70
|
+
mockGitLabUrl = mockGitLab.getUrl();
|
|
71
|
+
});
|
|
72
|
+
after(async () => {
|
|
73
|
+
await mockGitLab.stop();
|
|
74
|
+
});
|
|
75
|
+
const env = () => ({
|
|
76
|
+
GITLAB_API_URL: `${mockGitLabUrl}/api/v4`,
|
|
77
|
+
GITLAB_PERSONAL_ACCESS_TOKEN: MOCK_TOKEN,
|
|
78
|
+
});
|
|
79
|
+
test("omits an empty iids filter for list_milestones", async () => {
|
|
80
|
+
let capturedUrl;
|
|
81
|
+
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/milestones`, (req, res) => {
|
|
82
|
+
capturedUrl = req.originalUrl;
|
|
83
|
+
res.json([]);
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
const milestones = await callTool("list_milestones", { project_id: TEST_PROJECT_ID, iids: [] }, env());
|
|
87
|
+
assert.deepStrictEqual(milestones, []);
|
|
88
|
+
assert.ok(capturedUrl, "Mock handler should have received a request");
|
|
89
|
+
assert.strictEqual(new URL(capturedUrl, "http://localhost").search, "", "An empty iids array should not be serialized as `iids=`");
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
mockGitLab.clearCustomHandlers();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
test("forwards non-empty iids in bracket-array form", async () => {
|
|
96
|
+
let capturedUrl;
|
|
97
|
+
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/milestones`, (req, res) => {
|
|
98
|
+
capturedUrl = req.originalUrl;
|
|
99
|
+
res.json([]);
|
|
100
|
+
});
|
|
101
|
+
try {
|
|
102
|
+
await callTool("list_milestones", { project_id: TEST_PROJECT_ID, iids: [1, 2] }, env());
|
|
103
|
+
assert.ok(capturedUrl, "Mock handler should have received a request");
|
|
104
|
+
const params = new URL(capturedUrl, "http://localhost").searchParams;
|
|
105
|
+
assert.deepStrictEqual(params.getAll("iids[]"), ["1", "2"]);
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
mockGitLab.clearCustomHandlers();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
test("omits blank milestone filters", async () => {
|
|
112
|
+
let capturedUrl;
|
|
113
|
+
mockGitLab.addMockHandler("get", `/projects/${TEST_PROJECT_ID}/milestones`, (req, res) => {
|
|
114
|
+
capturedUrl = req.originalUrl;
|
|
115
|
+
res.json([]);
|
|
116
|
+
});
|
|
117
|
+
try {
|
|
118
|
+
await callTool("list_milestones", { project_id: TEST_PROJECT_ID, iids: [], title: " ", search: "" }, env());
|
|
119
|
+
assert.ok(capturedUrl, "Mock handler should have received a request");
|
|
120
|
+
assert.strictEqual(new URL(capturedUrl, "http://localhost").search, "", "Blank milestone filters should not be serialized");
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
mockGitLab.clearCustomHandlers();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
test("omits an empty iids filter for list_group_milestones", async () => {
|
|
127
|
+
let capturedUrl;
|
|
128
|
+
mockGitLab.addMockHandler("get", `/groups/${TEST_GROUP_ID}/milestones`, (req, res) => {
|
|
129
|
+
capturedUrl = req.originalUrl;
|
|
130
|
+
res.json([]);
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
const milestones = await callTool("list_group_milestones", { group_id: TEST_GROUP_ID, iids: [], state: "active" }, env());
|
|
134
|
+
assert.deepStrictEqual(milestones, []);
|
|
135
|
+
assert.ok(capturedUrl, "Mock handler should have received a request");
|
|
136
|
+
const params = new URL(capturedUrl, "http://localhost").searchParams;
|
|
137
|
+
assert.equal(params.has("iids"), false, "An empty iids array should not be serialized as `iids=`");
|
|
138
|
+
assert.deepStrictEqual(params.getAll("iids[]"), []);
|
|
139
|
+
assert.deepStrictEqual(params.getAll("state"), ["active"]);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
mockGitLab.clearCustomHandlers();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { describe, test } from "node:test";
|
|
3
|
-
import { cleanMutuallyExclusiveIdUsernameOptions, LIST_MERGE_REQUESTS_ID_USERNAME_PAIRS, sanitizeToolArguments, } from "../../utils/tool-args.js";
|
|
3
|
+
import { appendFilterParam, appendFilterParams, cleanMutuallyExclusiveIdUsernameOptions, dropBlankArrayEntries, isBlankFilterValue, LIST_MERGE_REQUESTS_ID_USERNAME_PAIRS, sanitizeToolArguments, } from "../../utils/tool-args.js";
|
|
4
4
|
describe("When sanitizeToolArguments runs", () => {
|
|
5
5
|
describe("with top-level null optionals", () => {
|
|
6
6
|
test("should omit null and undefined keys for generic tools", () => {
|
|
@@ -120,3 +120,59 @@ describe("When cleanMutuallyExclusiveIdUsernameOptions runs", () => {
|
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
+
describe("When dropBlankArrayEntries runs", () => {
|
|
124
|
+
test("should drop blank string entries and keep meaningful ones", () => {
|
|
125
|
+
assert.deepEqual(dropBlankArrayEntries(["", " ", "bug"]), ["bug"]);
|
|
126
|
+
assert.deepEqual(dropBlankArrayEntries(["\t", "alice", ""]), ["alice"]);
|
|
127
|
+
});
|
|
128
|
+
test("should leave non-array values untouched", () => {
|
|
129
|
+
assert.equal(dropBlankArrayEntries("bug"), "bug");
|
|
130
|
+
assert.equal(dropBlankArrayEntries(" "), " ");
|
|
131
|
+
assert.equal(dropBlankArrayEntries(undefined), undefined);
|
|
132
|
+
assert.equal(dropBlankArrayEntries(false), false);
|
|
133
|
+
});
|
|
134
|
+
test("should keep non-string array entries", () => {
|
|
135
|
+
assert.deepEqual(dropBlankArrayEntries([0, "bug", false]), [0, "bug", false]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe("When isBlankFilterValue runs", () => {
|
|
139
|
+
test("should treat undefined, blank strings and empty arrays as blank", () => {
|
|
140
|
+
assert.equal(isBlankFilterValue(undefined), true);
|
|
141
|
+
assert.equal(isBlankFilterValue(""), true);
|
|
142
|
+
assert.equal(isBlankFilterValue(" \t\n"), true);
|
|
143
|
+
assert.equal(isBlankFilterValue([]), true);
|
|
144
|
+
});
|
|
145
|
+
test("should keep meaningful values, including false and zero", () => {
|
|
146
|
+
assert.equal(isBlankFilterValue("bug"), false);
|
|
147
|
+
assert.equal(isBlankFilterValue(["bug"]), false);
|
|
148
|
+
assert.equal(isBlankFilterValue(0), false);
|
|
149
|
+
assert.equal(isBlankFilterValue(false), false);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe("When appendFilterParams runs", () => {
|
|
153
|
+
test("should omit blank scalars, blank array entries and empty arrays", () => {
|
|
154
|
+
const searchParams = new URLSearchParams();
|
|
155
|
+
appendFilterParams(searchParams, {
|
|
156
|
+
search: "",
|
|
157
|
+
ref: " ",
|
|
158
|
+
labels: ["", "bug"],
|
|
159
|
+
iids: [],
|
|
160
|
+
omitted: undefined,
|
|
161
|
+
});
|
|
162
|
+
assert.deepEqual([...searchParams.entries()], [["labels", "bug"]]);
|
|
163
|
+
});
|
|
164
|
+
test("should keep booleans, zero and non-blank values", () => {
|
|
165
|
+
const searchParams = new URLSearchParams();
|
|
166
|
+
appendFilterParams(searchParams, { with_labels_details: false, page: 0, search: "bug" });
|
|
167
|
+
assert.deepEqual([...searchParams.entries()], [
|
|
168
|
+
["with_labels_details", "false"],
|
|
169
|
+
["page", "0"],
|
|
170
|
+
["search", "bug"],
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
test("should append a single parameter without dropping a meaningful value", () => {
|
|
174
|
+
const searchParams = new URLSearchParams();
|
|
175
|
+
appendFilterParam(searchParams, "filter[environment_scope]", "production");
|
|
176
|
+
assert.deepEqual([...searchParams.entries()], [["filter[environment_scope]", "production"]]);
|
|
177
|
+
});
|
|
178
|
+
});
|
package/build/utils/tool-args.js
CHANGED
|
@@ -20,6 +20,41 @@ export function sanitizeToolArguments(toolName, args) {
|
|
|
20
20
|
}
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Drop blank string entries inside array filters so ["", "bug"] behaves like the scalar blank guard.
|
|
25
|
+
*/
|
|
26
|
+
export function dropBlankArrayEntries(value) {
|
|
27
|
+
if (!Array.isArray(value)) {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
return value.filter(item => !(typeof item === "string" && item.trim() === ""));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Blank filters must be omitted entirely instead of being serialized as empty query parameters
|
|
34
|
+
* such as `labels=`, `labels[]=` or `iids=`.
|
|
35
|
+
*/
|
|
36
|
+
export function isBlankFilterValue(value) {
|
|
37
|
+
return (value === undefined ||
|
|
38
|
+
(typeof value === "string" && value.trim() === "") ||
|
|
39
|
+
(Array.isArray(value) && value.length === 0));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Append one query parameter, skipping blank filters and blank entries inside arrays.
|
|
43
|
+
* Booleans serialize as `true`/`false`, matching the inline branches this replaces.
|
|
44
|
+
*/
|
|
45
|
+
export function appendFilterParam(searchParams, key, value) {
|
|
46
|
+
const normalized = dropBlankArrayEntries(value);
|
|
47
|
+
if (isBlankFilterValue(normalized)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
searchParams.append(key, String(normalized));
|
|
51
|
+
}
|
|
52
|
+
/** Append every option as a query parameter while dropping blank filters. */
|
|
53
|
+
export function appendFilterParams(searchParams, options) {
|
|
54
|
+
for (const [key, value] of Object.entries(options)) {
|
|
55
|
+
appendFilterParam(searchParams, key, value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
23
58
|
/** Pairs where GitLab rejects sending both *_id and *_username query params. */
|
|
24
59
|
export const LIST_ISSUES_ID_USERNAME_PAIRS = [
|
|
25
60
|
["author_id", "author_username"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zereight/mcp-gitlab",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.64",
|
|
4
4
|
"mcpName": "io.github.zereight/gitlab-mcp",
|
|
5
5
|
"description": "GitLab MCP server for projects, merge requests, issues, pipelines, wiki, releases, and more",
|
|
6
6
|
"keywords": [
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"lint": "eslint . --ext .ts",
|
|
66
66
|
"check:runtime-deps": "node scripts/check-runtime-deps.mjs",
|
|
67
67
|
"check:skill-sync": "tsx scripts/check-skill-sync.ts",
|
|
68
|
+
"docs:tools": "tsx scripts/generate-tool-docs.ts && tsx scripts/generate-tool-coverage.ts",
|
|
68
69
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
69
70
|
"release": "bash scripts/release.sh",
|
|
70
71
|
"release:mcp-registry": "bash scripts/publish_mcp_registry.sh",
|