@zereight/mcp-gitlab 2.3.27-next.232 → 2.3.27-next.234
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 +4 -0
- package/README.md +4 -0
- package/README.pt-BR.md +4 -0
- package/README.zh-CN.md +4 -0
- package/build/cli/args.js +5 -3
- package/build/cli/compact-mcp-result.js +3 -1
- package/build/cli/replay-command.js +40 -9
- package/build/index.js +1 -0
- package/build/schemas.js +11 -9
- package/build/utils/helpers.js +47 -12
- package/package.json +1 -1
package/README.ko.md
CHANGED
package/README.md
CHANGED
package/README.pt-BR.md
CHANGED
package/README.zh-CN.md
CHANGED
package/build/cli/args.js
CHANGED
|
@@ -240,9 +240,11 @@ export function isCliOutputMode(value) {
|
|
|
240
240
|
}
|
|
241
241
|
function userArgv(argv) {
|
|
242
242
|
const args = argv.slice(2);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
// Only the first positional can be the script a runner passes in. A later
|
|
244
|
+
// value such as `src/app.ts` is a tool argument, not a script path.
|
|
245
|
+
const first = args.findIndex(arg => !arg.startsWith("-"));
|
|
246
|
+
if (first >= 0 && SCRIPT_PATH_PATTERN.test(args[first])) {
|
|
247
|
+
return args.slice(first + 1);
|
|
246
248
|
}
|
|
247
249
|
return args;
|
|
248
250
|
}
|
|
@@ -24,12 +24,14 @@ export function compactMcpToolResult(input) {
|
|
|
24
24
|
if (text.length <= input.maxChars) {
|
|
25
25
|
return toolResultRecord(input.result);
|
|
26
26
|
}
|
|
27
|
+
const cli = buildToolReplayCommand(input.toolName, input.args, input.inputSchema);
|
|
27
28
|
const compact = {
|
|
28
29
|
compact: true,
|
|
29
30
|
tool: input.toolName,
|
|
30
31
|
original_chars: text.length,
|
|
31
32
|
...buildPreview(text),
|
|
32
|
-
|
|
33
|
+
// No safe replay line exists for these arguments: the preview stays, without `cli`.
|
|
34
|
+
...(cli === undefined ? {} : { cli }),
|
|
33
35
|
};
|
|
34
36
|
return {
|
|
35
37
|
content: [{ type: "text", text: JSON.stringify(compact) }],
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { snakeToKebab } from "./args.js";
|
|
1
|
+
import { readObjectSchema, snakeToKebab } from "./args.js";
|
|
2
2
|
const BINARY = "zereight-mcp-gitlab";
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
// Words that POSIX sh passes through unchanged. Anything else is single-quoted.
|
|
4
|
+
const SIMPLE_SHELL_WORD = /^[A-Za-z0-9._:/=+-]+$/;
|
|
5
|
+
const TOOL_NAME = /^[a-z][a-z0-9_]*$/;
|
|
6
|
+
const ARGUMENT_NAME = /^[a-z][a-z0-9_]*$/;
|
|
7
|
+
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
8
|
+
export const SECRET_ARGUMENT_NAMES = new Set([
|
|
5
9
|
"token",
|
|
6
10
|
"job_token",
|
|
7
11
|
"private_token",
|
|
@@ -12,7 +16,18 @@ const SECRET_ARGUMENT_NAMES = new Set([
|
|
|
12
16
|
"signing_token",
|
|
13
17
|
"authorization",
|
|
14
18
|
]);
|
|
15
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Builds the `zereight-mcp-gitlab tool ...` line for a compacted reply, or returns
|
|
21
|
+
* undefined when no safe line exists. Every token is either a plain word or
|
|
22
|
+
* single-quoted, so the line is inert when a shell runs it. Only keys that the
|
|
23
|
+
* tool's input schema declares become flags; the CLI reads any other flag from
|
|
24
|
+
* the same argv, and names such as `api_url` would then change its configuration.
|
|
25
|
+
*/
|
|
26
|
+
export function buildToolReplayCommand(toolName, args, inputSchema) {
|
|
27
|
+
if (!TOOL_NAME.test(toolName)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const declared = new Set(Object.keys(readObjectSchema(inputSchema).properties ?? {}));
|
|
16
31
|
const parts = [BINARY, "tool", toolName];
|
|
17
32
|
const nested = {};
|
|
18
33
|
if (args !== undefined) {
|
|
@@ -24,15 +39,23 @@ export function buildToolReplayCommand(toolName, args) {
|
|
|
24
39
|
if (value === undefined) {
|
|
25
40
|
continue;
|
|
26
41
|
}
|
|
42
|
+
if (!ARGUMENT_NAME.test(key) || !declared.has(key)) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
27
45
|
if (isScalarReplayValue(value)) {
|
|
28
|
-
|
|
46
|
+
const text = String(value);
|
|
47
|
+
// argv cannot carry a NUL byte, and a lone surrogate does not survive UTF-8.
|
|
48
|
+
if (text.includes("\0") || LONE_SURROGATE.test(text)) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
parts.push(...flagTokens(snakeToKebab(key), text));
|
|
29
52
|
continue;
|
|
30
53
|
}
|
|
31
54
|
nested[key] = value;
|
|
32
55
|
}
|
|
33
56
|
}
|
|
34
57
|
if (Object.keys(nested).length > 0) {
|
|
35
|
-
parts.push("--args-json",
|
|
58
|
+
parts.push("--args-json", shellWord(JSON.stringify(nested)));
|
|
36
59
|
}
|
|
37
60
|
return parts.join(" ");
|
|
38
61
|
}
|
|
@@ -45,9 +68,17 @@ function shouldOmitReplayArgument(name) {
|
|
|
45
68
|
function isScalarReplayValue(value) {
|
|
46
69
|
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
47
70
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
71
|
+
function flagTokens(flag, value) {
|
|
72
|
+
// The CLI reads `--flag -x` as a missing value, so a value that starts with a
|
|
73
|
+
// dash goes in the `--flag=value` form, which it parses as one token.
|
|
74
|
+
if (value.startsWith("-")) {
|
|
75
|
+
return [`--${flag}=${shellWord(value)}`];
|
|
76
|
+
}
|
|
77
|
+
return [`--${flag}`, shellWord(value)];
|
|
78
|
+
}
|
|
79
|
+
function shellWord(value) {
|
|
80
|
+
if (SIMPLE_SHELL_WORD.test(value)) {
|
|
50
81
|
return value;
|
|
51
82
|
}
|
|
52
|
-
return
|
|
83
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
53
84
|
}
|
package/build/index.js
CHANGED
|
@@ -274,6 +274,7 @@ function createServer() {
|
|
|
274
274
|
maxChars: GITLAB_MCP_COMPACT_RESULT_CHARS,
|
|
275
275
|
toolName,
|
|
276
276
|
args: readOwnRecord(request.params.arguments),
|
|
277
|
+
inputSchema: allTools.find(tool => tool.name === toolName)?.inputSchema,
|
|
277
278
|
});
|
|
278
279
|
};
|
|
279
280
|
const logError = (error) => {
|
package/build/schemas.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { EXCLUDED_FILE_PATTERN_MAX_COUNT, EXCLUDED_FILE_PATTERN_MAX_LENGTH, } from "./utils/helpers.js";
|
|
2
3
|
import { omitIncompleteMergeRequestPosition } from "./utils/merge-request-position.js";
|
|
3
4
|
// Helper: coerce a JSON-stringified array to an actual array.
|
|
4
5
|
// LLMs sometimes send '["a", "b"]' (string) instead of ["a", "b"] (array).
|
|
@@ -2242,16 +2243,19 @@ export const GitLabBranchSchema = z.object({
|
|
|
2242
2243
|
default: z.boolean(),
|
|
2243
2244
|
web_url: z.string().optional(),
|
|
2244
2245
|
});
|
|
2246
|
+
const excludedFilePatternsSchema = z
|
|
2247
|
+
.array(z.string().max(EXCLUDED_FILE_PATTERN_MAX_LENGTH))
|
|
2248
|
+
.max(EXCLUDED_FILE_PATTERN_MAX_COUNT);
|
|
2249
|
+
const EXCLUDED_DIFF_PATTERNS_DESCRIPTION = 'Array of regex patterns to exclude files from the diff results. Each pattern is an RE2 regular expression that matches file paths to ignore. RE2 runs in linear time but does not support lookahead, lookbehind, or backreferences. At most 50 patterns of at most 200 characters each. Examples: ["^vendor/", "^test/mocks/", "\\.spec\\.ts$", "package-lock\\.json"]';
|
|
2245
2250
|
export const GetBranchDiffsSchema = ProjectParamsSchema.extend({
|
|
2246
2251
|
from: z.string().describe("The base branch or commit SHA to compare from"),
|
|
2247
2252
|
to: z.string().describe("The target branch or commit SHA to compare to"),
|
|
2248
2253
|
straight: coerceBooleanString
|
|
2249
2254
|
.optional()
|
|
2250
2255
|
.describe("Comparison method: false for '...' (default), true for '--'"),
|
|
2251
|
-
excluded_file_patterns:
|
|
2252
|
-
.array(z.string())
|
|
2256
|
+
excluded_file_patterns: excludedFilePatternsSchema
|
|
2253
2257
|
.optional()
|
|
2254
|
-
.describe(
|
|
2258
|
+
.describe(EXCLUDED_DIFF_PATTERNS_DESCRIPTION),
|
|
2255
2259
|
});
|
|
2256
2260
|
const flexibleBooleanOptional = z.preprocess(val => {
|
|
2257
2261
|
if (typeof val !== "string")
|
|
@@ -2425,10 +2429,9 @@ export const ListMergeRequestPipelinesSchema = ProjectParamsSchema.extend({
|
|
|
2425
2429
|
}).merge(PaginationOptionsSchema);
|
|
2426
2430
|
export const GetMergeRequestDiffsSchema = MergeRequestParamsSchema.extend({
|
|
2427
2431
|
view: z.enum(["inline", "parallel"]).optional().describe("Diff view type"),
|
|
2428
|
-
excluded_file_patterns:
|
|
2429
|
-
.array(z.string())
|
|
2432
|
+
excluded_file_patterns: excludedFilePatternsSchema
|
|
2430
2433
|
.optional()
|
|
2431
|
-
.describe(
|
|
2434
|
+
.describe(EXCLUDED_DIFF_PATTERNS_DESCRIPTION),
|
|
2432
2435
|
});
|
|
2433
2436
|
export const ListMergeRequestDiffsSchema = MergeRequestParamsSchema.extend({
|
|
2434
2437
|
page: z.coerce.number().optional().describe("Page number for pagination (default: 1)"),
|
|
@@ -2441,10 +2444,9 @@ export const ListMergeRequestDiffsSchema = MergeRequestParamsSchema.extend({
|
|
|
2441
2444
|
.describe("Present diffs in the unified diff format. Default is false. Introduced in GitLab 16.5."),
|
|
2442
2445
|
});
|
|
2443
2446
|
export const ListMergeRequestChangedFilesSchema = MergeRequestParamsSchema.extend({
|
|
2444
|
-
excluded_file_patterns:
|
|
2445
|
-
.array(z.string())
|
|
2447
|
+
excluded_file_patterns: excludedFilePatternsSchema
|
|
2446
2448
|
.optional()
|
|
2447
|
-
.describe('Array of regex patterns to exclude files. Examples: ["^vendor/", "\\.pb\\.go$"]'),
|
|
2449
|
+
.describe('Array of regex patterns to exclude files. Each pattern is an RE2 regular expression (linear time; no lookahead, lookbehind, or backreferences). At most 50 patterns of at most 200 characters each. Examples: ["^vendor/", "\\.pb\\.go$"]'),
|
|
2448
2450
|
});
|
|
2449
2451
|
export const GetMergeRequestFileDiffSchema = MergeRequestParamsSchema.extend({
|
|
2450
2452
|
file_paths: z
|
package/build/utils/helpers.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { RE2JS } from "re2js";
|
|
4
|
+
/**
|
|
5
|
+
* Limits on excluded_file_patterns. The tool schemas reject input over these
|
|
6
|
+
* limits, and filterDiffsByPatterns ignores anything over them.
|
|
7
|
+
*/
|
|
8
|
+
export const EXCLUDED_FILE_PATTERN_MAX_LENGTH = 200;
|
|
9
|
+
export const EXCLUDED_FILE_PATTERN_MAX_COUNT = 50;
|
|
10
|
+
// Matching cost per character grows with the compiled program. A counted
|
|
11
|
+
// repeat such as .{1000} repeated many times produces a large program.
|
|
12
|
+
export const EXCLUDED_FILE_PATTERN_MAX_PROGRAM_SIZE = 1000;
|
|
3
13
|
/**
|
|
4
14
|
* Reject absolute paths and directory-traversal sequences for user-supplied
|
|
5
15
|
* local filesystem paths (e.g. local_path / file_path tool arguments).
|
|
@@ -289,27 +299,52 @@ export function summarizeWebhookEvents(events) {
|
|
|
289
299
|
execution_duration: event.execution_duration,
|
|
290
300
|
}));
|
|
291
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Compile excluded_file_patterns with RE2, which matches in time linear in the
|
|
304
|
+
* path length. A pattern RE2 cannot compile (lookaround, backreferences, or
|
|
305
|
+
* \uXXXX escapes, for example) is skipped with a warning, so it excludes no files.
|
|
306
|
+
*/
|
|
307
|
+
function compileExcludedFilePatterns(patterns) {
|
|
308
|
+
if (patterns.length > EXCLUDED_FILE_PATTERN_MAX_COUNT) {
|
|
309
|
+
console.warn(`Excluded file patterns after the first ${EXCLUDED_FILE_PATTERN_MAX_COUNT} ignored (${patterns.length} given).`);
|
|
310
|
+
}
|
|
311
|
+
const compiled = [];
|
|
312
|
+
for (const pattern of patterns.slice(0, EXCLUDED_FILE_PATTERN_MAX_COUNT)) {
|
|
313
|
+
if (pattern.length > EXCLUDED_FILE_PATTERN_MAX_LENGTH) {
|
|
314
|
+
console.warn(`Excluded file pattern ignored: ${pattern.length} characters exceeds ${EXCLUDED_FILE_PATTERN_MAX_LENGTH}.`);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
let regex;
|
|
318
|
+
try {
|
|
319
|
+
regex = RE2JS.compile(pattern);
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
console.warn(`Invalid regex pattern ignored: ${pattern} (RE2 rejects lookaround, backreferences, and \\uXXXX escapes)`);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
const programSize = regex.programSize();
|
|
326
|
+
if (programSize > EXCLUDED_FILE_PATTERN_MAX_PROGRAM_SIZE) {
|
|
327
|
+
console.warn(`Excluded file pattern ignored: compiled size ${programSize} exceeds ${EXCLUDED_FILE_PATTERN_MAX_PROGRAM_SIZE}: ${pattern}`);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
compiled.push(regex);
|
|
331
|
+
}
|
|
332
|
+
return compiled;
|
|
333
|
+
}
|
|
292
334
|
/**
|
|
293
335
|
* Filter MR diffs by excluding files matching regex patterns.
|
|
294
336
|
*
|
|
337
|
+
* Patterns use RE2 syntax (see compileExcludedFilePatterns), so matching cannot
|
|
338
|
+
* backtrack catastrophically on a long path.
|
|
339
|
+
*
|
|
295
340
|
* @param diffs - Array of diff objects with new_path property
|
|
296
|
-
* @param excludedFilePatterns - Array of regex patterns to exclude
|
|
341
|
+
* @param excludedFilePatterns - Array of RE2 regex patterns to exclude
|
|
297
342
|
* @returns Filtered array of diffs
|
|
298
343
|
*/
|
|
299
344
|
export function filterDiffsByPatterns(diffs, excludedFilePatterns) {
|
|
300
345
|
if (!excludedFilePatterns?.length)
|
|
301
346
|
return diffs;
|
|
302
|
-
const regexPatterns = excludedFilePatterns
|
|
303
|
-
.map(pattern => {
|
|
304
|
-
try {
|
|
305
|
-
return new RegExp(pattern);
|
|
306
|
-
}
|
|
307
|
-
catch {
|
|
308
|
-
console.warn(`Invalid regex pattern ignored: ${pattern}`);
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
})
|
|
312
|
-
.filter((regex) => regex !== null);
|
|
347
|
+
const regexPatterns = compileExcludedFilePatterns(excludedFilePatterns);
|
|
313
348
|
if (regexPatterns.length === 0)
|
|
314
349
|
return diffs;
|
|
315
350
|
const matchesAnyPattern = (path) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zereight/mcp-gitlab",
|
|
3
|
-
"version": "2.3.27-next.
|
|
3
|
+
"version": "2.3.27-next.234",
|
|
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": [
|