@zereight/mcp-gitlab 2.1.3 → 2.1.5
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 +5 -0
- package/build/config.js +1 -0
- package/build/index.js +30 -7
- package/build/oauth-proxy.js +250 -46
- package/build/schemas.js +8 -2
- package/build/test/callback-proxy-tests.js +321 -0
- package/build/test/dynamic-routing-tests.js +49 -0
- package/build/test/schema-tests.js +154 -3
- package/build/test/test-json-schema.js +148 -0
- package/build/utils/schema.js +40 -6
- package/package.json +2 -2
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { toJSONSchema } from "../utils/schema.js";
|
|
4
|
+
function assert(condition, message) {
|
|
5
|
+
if (!condition) {
|
|
6
|
+
throw new Error(message);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function runTests() {
|
|
10
|
+
console.log("Testing toJSONSchema utility...");
|
|
11
|
+
const results = [];
|
|
12
|
+
// Test 1: Required field extraction
|
|
13
|
+
try {
|
|
14
|
+
const schema = z.object({
|
|
15
|
+
requiredField: z.string(),
|
|
16
|
+
optionalField: z.string().optional(),
|
|
17
|
+
});
|
|
18
|
+
const result = toJSONSchema(schema);
|
|
19
|
+
assert(result.required?.includes("requiredField"), "requiredField should be in required array");
|
|
20
|
+
assert(!result.required?.includes("optionalField"), "optionalField should NOT be in required array");
|
|
21
|
+
results.push({ name: "required field extraction", status: "passed" });
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
results.push({
|
|
25
|
+
name: "required field extraction",
|
|
26
|
+
status: "failed",
|
|
27
|
+
error: error.message,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// Test 2: Nullable fields
|
|
31
|
+
try {
|
|
32
|
+
const schema = z.object({
|
|
33
|
+
nullableField: z.string().nullable(),
|
|
34
|
+
requiredField: z.string(),
|
|
35
|
+
});
|
|
36
|
+
const result = toJSONSchema(schema);
|
|
37
|
+
assert(result.required?.includes("requiredField"), "requiredField should be in required array");
|
|
38
|
+
assert(!result.required?.includes("nullableField"), "nullableField should NOT be in required array");
|
|
39
|
+
results.push({ name: "nullable fields", status: "passed" });
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
results.push({
|
|
43
|
+
name: "nullable fields",
|
|
44
|
+
status: "failed",
|
|
45
|
+
error: error.message,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Test 3: Optional nullable fields
|
|
49
|
+
try {
|
|
50
|
+
const schema = z.object({
|
|
51
|
+
optionalNullable: z.string().optional().nullable(),
|
|
52
|
+
requiredField: z.string(),
|
|
53
|
+
});
|
|
54
|
+
const result = toJSONSchema(schema);
|
|
55
|
+
assert(result.required?.includes("requiredField"), "requiredField should be in required array");
|
|
56
|
+
assert(!result.required?.includes("optionalNullable"), "optionalNullable should NOT be in required array");
|
|
57
|
+
results.push({ name: "optional nullable fields", status: "passed" });
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
results.push({
|
|
61
|
+
name: "optional nullable fields",
|
|
62
|
+
status: "failed",
|
|
63
|
+
error: error.message,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Test 4: Fields with defaults
|
|
67
|
+
try {
|
|
68
|
+
const schema = z.object({
|
|
69
|
+
fieldWithDefault: z.string().default("default-value"),
|
|
70
|
+
requiredField: z.string(),
|
|
71
|
+
});
|
|
72
|
+
const result = toJSONSchema(schema);
|
|
73
|
+
assert(result.required?.includes("requiredField"), "requiredField should be in required array");
|
|
74
|
+
assert(!result.required?.includes("fieldWithDefault"), "fieldWithDefault should NOT be in required array");
|
|
75
|
+
assert(result.properties.fieldWithDefault.default === "default-value", "default value should be preserved");
|
|
76
|
+
results.push({ name: "fields with defaults", status: "passed" });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
results.push({
|
|
80
|
+
name: "fields with defaults",
|
|
81
|
+
status: "failed",
|
|
82
|
+
error: error.message,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// Test 5: Nested objects with shared property names
|
|
86
|
+
try {
|
|
87
|
+
const schema = z.object({
|
|
88
|
+
foo: z.string(), // Required at root
|
|
89
|
+
nested: z.object({
|
|
90
|
+
foo: z.string().optional(), // Optional in nested, shares name with root
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
const result = toJSONSchema(schema);
|
|
94
|
+
assert(result.required?.includes("foo"), "root foo should be in required array");
|
|
95
|
+
assert(result.required?.includes("nested"), "nested object should be in required array");
|
|
96
|
+
assert(result.properties.nested.required === undefined, "nested foo should NOT be in required array");
|
|
97
|
+
results.push({
|
|
98
|
+
name: "nested objects with shared property names",
|
|
99
|
+
status: "passed",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
results.push({
|
|
104
|
+
name: "nested objects with shared property names",
|
|
105
|
+
status: "failed",
|
|
106
|
+
error: error.message,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// Test 6: Coerced fields
|
|
110
|
+
try {
|
|
111
|
+
const schema = z.object({
|
|
112
|
+
coercedField: z.coerce.string(),
|
|
113
|
+
optionalCoercedField: z.coerce.string().optional(),
|
|
114
|
+
});
|
|
115
|
+
const result = toJSONSchema(schema);
|
|
116
|
+
assert(result.required?.includes("coercedField"), "coercedField should be in required array (z.coerce without optional)");
|
|
117
|
+
assert(!result.required?.includes("optionalCoercedField"), "optionalCoercedField should NOT be in required array (z.coerce with optional)");
|
|
118
|
+
results.push({ name: "coerced fields", status: "passed" });
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
results.push({
|
|
122
|
+
name: "coerced fields",
|
|
123
|
+
status: "failed",
|
|
124
|
+
error: error.message,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
// Print results
|
|
128
|
+
const passed = results.filter((r) => r.status === "passed").length;
|
|
129
|
+
const failed = results.filter((r) => r.status === "failed").length;
|
|
130
|
+
console.log("\nTest Results:");
|
|
131
|
+
console.log("=".repeat(50));
|
|
132
|
+
results.forEach((result) => {
|
|
133
|
+
if (result.status === "passed") {
|
|
134
|
+
console.log(` ${result.name}: ${result.status}`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
console.log(` ${result.name}: ${result.status}`);
|
|
138
|
+
console.log(` Error: ${result.error}`);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
console.log("=".repeat(50));
|
|
142
|
+
console.log(`Total: ${results.length} tests`);
|
|
143
|
+
console.log(`Passed: ${passed}`);
|
|
144
|
+
console.log(`Failed: ${failed}`);
|
|
145
|
+
return { passed, failed };
|
|
146
|
+
}
|
|
147
|
+
// Run tests
|
|
148
|
+
runTests();
|
package/build/utils/schema.js
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
3
|
/**
|
|
3
4
|
* Convert a Zod schema to JSON Schema, fixing nullable/optional fields
|
|
4
|
-
* so they are not marked as required.
|
|
5
|
+
* so they are not marked as required, and extracting required fields from the Zod schema.
|
|
5
6
|
*/
|
|
6
7
|
export const toJSONSchema = (schema) => {
|
|
7
8
|
const jsonSchema = zodToJsonSchema(schema, { $refStrategy: "none" });
|
|
9
|
+
// Extract required fields from Zod schema
|
|
10
|
+
const zodRequiredFields = (() => {
|
|
11
|
+
if (schema instanceof z.ZodObject) {
|
|
12
|
+
const shape = schema.shape;
|
|
13
|
+
const requiredFields = [];
|
|
14
|
+
Object.entries(shape).forEach(([key, fieldDef]) => {
|
|
15
|
+
const zodType = fieldDef;
|
|
16
|
+
const typeName = zodType._def?.typeName;
|
|
17
|
+
// Check if field is wrapped in zod required types
|
|
18
|
+
const isRequired = [
|
|
19
|
+
"ZodOptional",
|
|
20
|
+
"ZodNullable",
|
|
21
|
+
"ZodDefault",
|
|
22
|
+
"ZodEffects",
|
|
23
|
+
"ZodCatch",
|
|
24
|
+
"ZodBranded",
|
|
25
|
+
].includes(typeName);
|
|
26
|
+
if (!isRequired) {
|
|
27
|
+
requiredFields.push(key);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return requiredFields;
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
})();
|
|
8
34
|
// Post-process to fix nullable/optional fields and strip verbose keys
|
|
9
|
-
function fixNullableOptional(obj) {
|
|
35
|
+
function fixNullableOptional(obj, isRoot = false) {
|
|
10
36
|
if (obj && typeof obj === "object") {
|
|
11
37
|
// Strip $schema (meta-only, not needed for tool input validation)
|
|
12
38
|
delete obj.$schema;
|
|
@@ -15,6 +41,14 @@ export const toJSONSchema = (schema) => {
|
|
|
15
41
|
// If this object has properties, process them
|
|
16
42
|
if (obj.properties) {
|
|
17
43
|
const requiredSet = new Set(obj.required || []);
|
|
44
|
+
// Add required fields extracted from Zod schema (only for root object)
|
|
45
|
+
if (isRoot) {
|
|
46
|
+
zodRequiredFields.forEach(field => {
|
|
47
|
+
if (obj.properties[field]) {
|
|
48
|
+
requiredSet.add(field);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
18
52
|
Object.keys(obj.properties).forEach(key => {
|
|
19
53
|
const prop = obj.properties[key];
|
|
20
54
|
// Handle fields that can be null or omitted
|
|
@@ -25,8 +59,8 @@ export const toJSONSchema = (schema) => {
|
|
|
25
59
|
else if (Array.isArray(prop.type) && prop.type.includes("null")) {
|
|
26
60
|
requiredSet.delete(key);
|
|
27
61
|
}
|
|
28
|
-
// Recursively process nested objects
|
|
29
|
-
obj.properties[key] = fixNullableOptional(prop);
|
|
62
|
+
// Recursively process nested objects (not root)
|
|
63
|
+
obj.properties[key] = fixNullableOptional(prop, false);
|
|
30
64
|
});
|
|
31
65
|
// Normalize the required array after processing all properties
|
|
32
66
|
if (requiredSet.size > 0) {
|
|
@@ -39,11 +73,11 @@ export const toJSONSchema = (schema) => {
|
|
|
39
73
|
// Process anyOf/allOf/oneOf
|
|
40
74
|
["anyOf", "allOf", "oneOf"].forEach(combiner => {
|
|
41
75
|
if (obj[combiner]) {
|
|
42
|
-
obj[combiner] = obj[combiner].map(fixNullableOptional);
|
|
76
|
+
obj[combiner] = obj[combiner].map((item) => fixNullableOptional(item, false));
|
|
43
77
|
}
|
|
44
78
|
});
|
|
45
79
|
}
|
|
46
80
|
return obj;
|
|
47
81
|
}
|
|
48
|
-
return fixNullableOptional(jsonSchema);
|
|
82
|
+
return fixNullableOptional(jsonSchema, true);
|
|
49
83
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zereight/mcp-gitlab",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
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": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"test:mcp-oauth": "npm run build && node --import tsx/esm --test test/mcp-oauth-tests.ts",
|
|
56
56
|
"test:live": "node test/validate-api.js",
|
|
57
57
|
"test:remote-auth": "npm run build && node --import tsx/esm --test test/remote-auth-simple-test.ts",
|
|
58
|
-
"test:schema": "tsx test/schema-tests.ts",
|
|
58
|
+
"test:schema": "tsx test/schema-tests.ts && tsx test/test-json-schema.ts",
|
|
59
59
|
"test:oauth": "tsx test/oauth-tests.ts",
|
|
60
60
|
"test:list-merge-requests": "npm run build && tsx test/test-list-merge-requests.ts",
|
|
61
61
|
"test:approvals": "npm run build && tsx test/test-merge-request-approvals.ts",
|