@zereight/mcp-gitlab 2.1.4 → 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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ts-node
2
- import { GetFileContentsSchema, GitLabFileContentSchema, GitLabRepositorySchema, CreatePipelineSchema, CreateIssueNoteSchema, CreateMergeRequestEmojiReactionSchema, CreateIssueEmojiReactionSchema, DeleteMergeRequestEmojiReactionSchema, DeleteIssueEmojiReactionSchema, CreateWorkItemEmojiReactionSchema, CreateWorkItemNoteEmojiReactionSchema, CreateIssueSchema, ListIssuesSchema, ListMergeRequestsSchema, GitLabTreeItemSchema, GetRepositoryTreeSchema } from '../schemas.js';
2
+ import { GetFileContentsSchema, GitLabFileContentSchema, GitLabRepositorySchema, CreatePipelineSchema, CreateIssueNoteSchema, CreateMergeRequestEmojiReactionSchema, CreateIssueEmojiReactionSchema, DeleteMergeRequestEmojiReactionSchema, DeleteIssueEmojiReactionSchema, CreateWorkItemEmojiReactionSchema, CreateWorkItemNoteEmojiReactionSchema, CreateIssueSchema, ListIssuesSchema, ListMergeRequestsSchema, GitLabTreeItemSchema, GetMergeRequestSchema, GetRepositoryTreeSchema } from '../schemas.js';
3
3
  function runGetFileContentsSchemaTests() {
4
4
  console.log('🧪 Testing GetFileContentsSchema...');
5
5
  const cases = [
@@ -371,6 +371,83 @@ function runCreateIssueNoteSchemaTests() {
371
371
  console.log(`\nResults: ${passed} passed, ${failed} failed`);
372
372
  return { passed, failed };
373
373
  }
374
+ function runGetMergeRequestSchemaTests() {
375
+ console.log('\n🧪 Testing GetMergeRequestSchema...');
376
+ const cases = [
377
+ {
378
+ name: 'schema:get_merge_request:with-project-id-and-merge-request-iid',
379
+ input: { project_id: 'my/project', merge_request_iid: '42' },
380
+ expected: { project_id: 'my/project', merge_request_iid: '42' },
381
+ },
382
+ {
383
+ name: 'schema:get_merge_request:with-project-id-and-source-branch',
384
+ input: { project_id: 'my/project', source_branch: 'feature-branch' },
385
+ expected: { project_id: 'my/project', source_branch: 'feature-branch' },
386
+ },
387
+ {
388
+ name: 'schema:get_merge_request:with-all-params',
389
+ input: { project_id: 'my/project', merge_request_iid: '42', source_branch: 'feature-branch' },
390
+ expected: {
391
+ project_id: 'my/project',
392
+ merge_request_iid: '42',
393
+ source_branch: 'feature-branch',
394
+ },
395
+ },
396
+ {
397
+ name: 'schema:get_merge_request:coerced-merge-request-iid',
398
+ input: { project_id: 'my/project', merge_request_iid: 24 },
399
+ expected: { project_id: 'my/project', merge_request_iid: '24' },
400
+ },
401
+ {
402
+ name: 'schema:get_merge_request:coerced-source-branch',
403
+ input: { project_id: 'my/project', source_branch: 'feature' },
404
+ expected: { project_id: 'my/project', source_branch: 'feature' },
405
+ },
406
+ ];
407
+ let passed = 0;
408
+ let failed = 0;
409
+ cases.forEach(testCase => {
410
+ const result = {
411
+ name: testCase.name,
412
+ status: 'failed'
413
+ };
414
+ const parsed = GetMergeRequestSchema.safeParse(testCase.input);
415
+ if (testCase.shouldFail) {
416
+ if (parsed.success) {
417
+ result.error = 'Expected schema validation to fail';
418
+ }
419
+ else {
420
+ result.status = 'passed';
421
+ }
422
+ }
423
+ else if (parsed.success) {
424
+ const expected = testCase.expected || {};
425
+ const matches = Object.entries(expected).every(([key, value]) => {
426
+ const actual = parsed.data[key];
427
+ return actual === value;
428
+ });
429
+ if (matches) {
430
+ result.status = 'passed';
431
+ }
432
+ else {
433
+ result.error = `Unexpected parsed result: ${JSON.stringify(parsed.data)}`;
434
+ }
435
+ }
436
+ else {
437
+ result.error = parsed.error?.message || 'Schema validation failed';
438
+ }
439
+ if (result.status === 'passed') {
440
+ passed++;
441
+ console.log(`✅ ${result.name}`);
442
+ }
443
+ else {
444
+ failed++;
445
+ console.log(`❌ ${result.name}: ${result.error}`);
446
+ }
447
+ });
448
+ console.log(`\nResults: ${passed} passed, ${failed} failed`);
449
+ return { passed, failed };
450
+ }
374
451
  function runEmojiReactionSchemaTests() {
375
452
  console.log('\n🧪 Testing Emoji Reaction Schemas...');
376
453
  const cases = [
@@ -702,13 +779,14 @@ if (import.meta.url === `file://${process.argv[1]}`) {
702
779
  const fileContentResult = runGitLabFileContentSchemaTests();
703
780
  const createPipelineResult = runCreatePipelineSchemaTests();
704
781
  const createIssueNoteResult = runCreateIssueNoteSchemaTests();
782
+ const getMergeRequestResult = runGetMergeRequestSchemaTests();
705
783
  const emojiReactionResult = runEmojiReactionSchemaTests();
706
784
  const repositorySchemaResult = runGitLabRepositorySchemaTests();
707
785
  const labelsCoercionResult = runLabelsCoercionSchemaTests();
708
786
  const treeItemResult = runGitLabTreeItemSchemaTests();
709
787
  const repositoryTreeResult = runGetRepositoryTreeSchemaTests();
710
- const totalPassed = getFileContentsResult.passed + fileContentResult.passed + createPipelineResult.passed + createIssueNoteResult.passed + emojiReactionResult.passed + repositorySchemaResult.passed + labelsCoercionResult.passed + treeItemResult.passed + repositoryTreeResult.passed;
711
- const totalFailed = getFileContentsResult.failed + fileContentResult.failed + createPipelineResult.failed + createIssueNoteResult.failed + emojiReactionResult.failed + repositorySchemaResult.failed + labelsCoercionResult.failed + treeItemResult.failed + repositoryTreeResult.failed;
788
+ const totalPassed = getFileContentsResult.passed + fileContentResult.passed + createPipelineResult.passed + createIssueNoteResult.passed + getMergeRequestResult.passed + emojiReactionResult.passed + repositorySchemaResult.passed + labelsCoercionResult.passed + treeItemResult.passed + repositoryTreeResult.passed;
789
+ const totalFailed = getFileContentsResult.failed + fileContentResult.failed + createPipelineResult.failed + createIssueNoteResult.failed + getMergeRequestResult.failed + emojiReactionResult.failed + repositorySchemaResult.failed + labelsCoercionResult.failed + treeItemResult.failed + repositoryTreeResult.failed;
712
790
  console.log(`\nTotal Results: ${totalPassed} passed, ${totalFailed} failed`);
713
791
  if (totalFailed > 0) {
714
792
  process.exit(1);
@@ -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();
@@ -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.4",
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",