scorecard-ai-mcp 1.0.0-alpha.4
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/LICENSE +201 -0
- package/README.md +228 -0
- package/compat.d.mts +53 -0
- package/compat.d.mts.map +1 -0
- package/compat.d.ts +53 -0
- package/compat.d.ts.map +1 -0
- package/compat.js +351 -0
- package/compat.js.map +1 -0
- package/compat.mjs +338 -0
- package/compat.mjs.map +1 -0
- package/compat.test.d.mts +2 -0
- package/compat.test.d.mts.map +1 -0
- package/compat.test.d.ts +2 -0
- package/compat.test.d.ts.map +1 -0
- package/compat.test.js +950 -0
- package/compat.test.js.map +1 -0
- package/compat.test.mjs +948 -0
- package/compat.test.mjs.map +1 -0
- package/index.d.mts +2 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +89 -0
- package/index.js.map +1 -0
- package/index.mjs +86 -0
- package/index.mjs.map +1 -0
- package/options.d.mts +9 -0
- package/options.d.mts.map +1 -0
- package/options.d.ts +9 -0
- package/options.d.ts.map +1 -0
- package/options.js +321 -0
- package/options.js.map +1 -0
- package/options.mjs +314 -0
- package/options.mjs.map +1 -0
- package/options.test.d.mts +2 -0
- package/options.test.d.mts.map +1 -0
- package/options.test.d.ts +2 -0
- package/options.test.d.ts.map +1 -0
- package/options.test.js +154 -0
- package/options.test.js.map +1 -0
- package/options.test.mjs +152 -0
- package/options.test.mjs.map +1 -0
- package/package.json +129 -0
- package/server.d.mts +33 -0
- package/server.d.mts.map +1 -0
- package/server.d.ts +33 -0
- package/server.d.ts.map +1 -0
- package/server.js +85 -0
- package/server.js.map +1 -0
- package/server.mjs +74 -0
- package/server.mjs.map +1 -0
- package/src/compat.test.ts +1068 -0
- package/src/compat.ts +437 -0
- package/src/index.ts +106 -0
- package/src/options.test.ts +193 -0
- package/src/options.ts +339 -0
- package/src/server.ts +98 -0
- package/src/tools/index.ts +129 -0
- package/src/tools/projects/list-projects.ts +39 -0
- package/src/tools/records/create-records.ts +47 -0
- package/src/tools/runs/create-runs.ts +46 -0
- package/src/tools/runs/update-runs.ts +44 -0
- package/src/tools/system-configs/create-system-configs.ts +59 -0
- package/src/tools/system-configs/get-system-configs.ts +34 -0
- package/src/tools/system-configs/list-system-configs.ts +42 -0
- package/src/tools/systems/create-systems.ts +52 -0
- package/src/tools/systems/delete-systems.ts +31 -0
- package/src/tools/systems/get-systems.ts +31 -0
- package/src/tools/systems/list-systems.ts +41 -0
- package/src/tools/systems/update-systems.ts +52 -0
- package/src/tools/testcases/create-testcases.ts +47 -0
- package/src/tools/testcases/delete-testcases.ts +35 -0
- package/src/tools/testcases/get-testcases.ts +31 -0
- package/src/tools/testcases/list-testcases.ts +41 -0
- package/src/tools/testcases/update-testcases.ts +35 -0
- package/src/tools/testsets/create-testsets.ts +73 -0
- package/src/tools/testsets/delete-testsets.ts +31 -0
- package/src/tools/testsets/get-testsets.ts +31 -0
- package/src/tools/testsets/list-testsets.ts +41 -0
- package/src/tools/testsets/update-testsets.ts +73 -0
- package/src/tools.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/tools/index.d.mts +21 -0
- package/tools/index.d.mts.map +1 -0
- package/tools/index.d.ts +21 -0
- package/tools/index.d.ts.map +1 -0
- package/tools/index.js +99 -0
- package/tools/index.js.map +1 -0
- package/tools/index.mjs +92 -0
- package/tools/index.mjs.map +1 -0
- package/tools/projects/list-projects.d.mts +24 -0
- package/tools/projects/list-projects.d.mts.map +1 -0
- package/tools/projects/list-projects.d.ts +24 -0
- package/tools/projects/list-projects.d.ts.map +1 -0
- package/tools/projects/list-projects.js +33 -0
- package/tools/projects/list-projects.js.map +1 -0
- package/tools/projects/list-projects.mjs +29 -0
- package/tools/projects/list-projects.mjs.map +1 -0
- package/tools/records/create-records.d.mts +24 -0
- package/tools/records/create-records.d.mts.map +1 -0
- package/tools/records/create-records.d.ts +24 -0
- package/tools/records/create-records.d.ts.map +1 -0
- package/tools/records/create-records.js +44 -0
- package/tools/records/create-records.js.map +1 -0
- package/tools/records/create-records.mjs +40 -0
- package/tools/records/create-records.mjs.map +1 -0
- package/tools/runs/create-runs.d.mts +24 -0
- package/tools/runs/create-runs.d.mts.map +1 -0
- package/tools/runs/create-runs.d.ts +24 -0
- package/tools/runs/create-runs.d.ts.map +1 -0
- package/tools/runs/create-runs.js +43 -0
- package/tools/runs/create-runs.js.map +1 -0
- package/tools/runs/create-runs.mjs +39 -0
- package/tools/runs/create-runs.mjs.map +1 -0
- package/tools/runs/update-runs.d.mts +24 -0
- package/tools/runs/update-runs.d.mts.map +1 -0
- package/tools/runs/update-runs.d.ts +24 -0
- package/tools/runs/update-runs.d.ts.map +1 -0
- package/tools/runs/update-runs.js +41 -0
- package/tools/runs/update-runs.js.map +1 -0
- package/tools/runs/update-runs.mjs +37 -0
- package/tools/runs/update-runs.mjs.map +1 -0
- package/tools/system-configs/create-system-configs.d.mts +24 -0
- package/tools/system-configs/create-system-configs.d.mts.map +1 -0
- package/tools/system-configs/create-system-configs.d.ts +24 -0
- package/tools/system-configs/create-system-configs.d.ts.map +1 -0
- package/tools/system-configs/create-system-configs.js +54 -0
- package/tools/system-configs/create-system-configs.js.map +1 -0
- package/tools/system-configs/create-system-configs.mjs +50 -0
- package/tools/system-configs/create-system-configs.mjs.map +1 -0
- package/tools/system-configs/get-system-configs.d.mts +24 -0
- package/tools/system-configs/get-system-configs.d.mts.map +1 -0
- package/tools/system-configs/get-system-configs.d.ts +24 -0
- package/tools/system-configs/get-system-configs.d.ts.map +1 -0
- package/tools/system-configs/get-system-configs.js +31 -0
- package/tools/system-configs/get-system-configs.js.map +1 -0
- package/tools/system-configs/get-system-configs.mjs +27 -0
- package/tools/system-configs/get-system-configs.mjs.map +1 -0
- package/tools/system-configs/list-system-configs.d.mts +24 -0
- package/tools/system-configs/list-system-configs.d.mts.map +1 -0
- package/tools/system-configs/list-system-configs.d.ts +24 -0
- package/tools/system-configs/list-system-configs.d.ts.map +1 -0
- package/tools/system-configs/list-system-configs.js +36 -0
- package/tools/system-configs/list-system-configs.js.map +1 -0
- package/tools/system-configs/list-system-configs.mjs +32 -0
- package/tools/system-configs/list-system-configs.mjs.map +1 -0
- package/tools/systems/create-systems.d.mts +24 -0
- package/tools/systems/create-systems.d.mts.map +1 -0
- package/tools/systems/create-systems.d.ts +24 -0
- package/tools/systems/create-systems.d.ts.map +1 -0
- package/tools/systems/create-systems.js +48 -0
- package/tools/systems/create-systems.js.map +1 -0
- package/tools/systems/create-systems.mjs +44 -0
- package/tools/systems/create-systems.mjs.map +1 -0
- package/tools/systems/delete-systems.d.mts +24 -0
- package/tools/systems/delete-systems.d.mts.map +1 -0
- package/tools/systems/delete-systems.d.ts +24 -0
- package/tools/systems/delete-systems.d.ts.map +1 -0
- package/tools/systems/delete-systems.js +28 -0
- package/tools/systems/delete-systems.js.map +1 -0
- package/tools/systems/delete-systems.mjs +24 -0
- package/tools/systems/delete-systems.mjs.map +1 -0
- package/tools/systems/get-systems.d.mts +24 -0
- package/tools/systems/get-systems.d.mts.map +1 -0
- package/tools/systems/get-systems.d.ts +24 -0
- package/tools/systems/get-systems.d.ts.map +1 -0
- package/tools/systems/get-systems.js +28 -0
- package/tools/systems/get-systems.js.map +1 -0
- package/tools/systems/get-systems.mjs +24 -0
- package/tools/systems/get-systems.mjs.map +1 -0
- package/tools/systems/list-systems.d.mts +24 -0
- package/tools/systems/list-systems.d.mts.map +1 -0
- package/tools/systems/list-systems.d.ts +24 -0
- package/tools/systems/list-systems.d.ts.map +1 -0
- package/tools/systems/list-systems.js +36 -0
- package/tools/systems/list-systems.js.map +1 -0
- package/tools/systems/list-systems.mjs +32 -0
- package/tools/systems/list-systems.mjs.map +1 -0
- package/tools/systems/update-systems.d.mts +24 -0
- package/tools/systems/update-systems.d.mts.map +1 -0
- package/tools/systems/update-systems.d.ts +24 -0
- package/tools/systems/update-systems.d.ts.map +1 -0
- package/tools/systems/update-systems.js +48 -0
- package/tools/systems/update-systems.js.map +1 -0
- package/tools/systems/update-systems.mjs +44 -0
- package/tools/systems/update-systems.mjs.map +1 -0
- package/tools/testcases/create-testcases.d.mts +24 -0
- package/tools/testcases/create-testcases.d.mts.map +1 -0
- package/tools/testcases/create-testcases.d.ts +24 -0
- package/tools/testcases/create-testcases.d.ts.map +1 -0
- package/tools/testcases/create-testcases.js +43 -0
- package/tools/testcases/create-testcases.js.map +1 -0
- package/tools/testcases/create-testcases.mjs +39 -0
- package/tools/testcases/create-testcases.mjs.map +1 -0
- package/tools/testcases/delete-testcases.d.mts +24 -0
- package/tools/testcases/delete-testcases.d.mts.map +1 -0
- package/tools/testcases/delete-testcases.d.ts +24 -0
- package/tools/testcases/delete-testcases.d.ts.map +1 -0
- package/tools/testcases/delete-testcases.js +32 -0
- package/tools/testcases/delete-testcases.js.map +1 -0
- package/tools/testcases/delete-testcases.mjs +28 -0
- package/tools/testcases/delete-testcases.mjs.map +1 -0
- package/tools/testcases/get-testcases.d.mts +24 -0
- package/tools/testcases/get-testcases.d.mts.map +1 -0
- package/tools/testcases/get-testcases.d.ts +24 -0
- package/tools/testcases/get-testcases.d.ts.map +1 -0
- package/tools/testcases/get-testcases.js +28 -0
- package/tools/testcases/get-testcases.js.map +1 -0
- package/tools/testcases/get-testcases.mjs +24 -0
- package/tools/testcases/get-testcases.mjs.map +1 -0
- package/tools/testcases/list-testcases.d.mts +24 -0
- package/tools/testcases/list-testcases.d.mts.map +1 -0
- package/tools/testcases/list-testcases.d.ts +24 -0
- package/tools/testcases/list-testcases.d.ts.map +1 -0
- package/tools/testcases/list-testcases.js +36 -0
- package/tools/testcases/list-testcases.js.map +1 -0
- package/tools/testcases/list-testcases.mjs +32 -0
- package/tools/testcases/list-testcases.mjs.map +1 -0
- package/tools/testcases/update-testcases.d.mts +24 -0
- package/tools/testcases/update-testcases.d.mts.map +1 -0
- package/tools/testcases/update-testcases.d.ts +24 -0
- package/tools/testcases/update-testcases.d.ts.map +1 -0
- package/tools/testcases/update-testcases.js +32 -0
- package/tools/testcases/update-testcases.js.map +1 -0
- package/tools/testcases/update-testcases.mjs +28 -0
- package/tools/testcases/update-testcases.mjs.map +1 -0
- package/tools/testsets/create-testsets.d.mts +24 -0
- package/tools/testsets/create-testsets.d.mts.map +1 -0
- package/tools/testsets/create-testsets.d.ts +24 -0
- package/tools/testsets/create-testsets.d.ts.map +1 -0
- package/tools/testsets/create-testsets.js +68 -0
- package/tools/testsets/create-testsets.js.map +1 -0
- package/tools/testsets/create-testsets.mjs +64 -0
- package/tools/testsets/create-testsets.mjs.map +1 -0
- package/tools/testsets/delete-testsets.d.mts +24 -0
- package/tools/testsets/delete-testsets.d.mts.map +1 -0
- package/tools/testsets/delete-testsets.d.ts +24 -0
- package/tools/testsets/delete-testsets.d.ts.map +1 -0
- package/tools/testsets/delete-testsets.js +28 -0
- package/tools/testsets/delete-testsets.js.map +1 -0
- package/tools/testsets/delete-testsets.mjs +24 -0
- package/tools/testsets/delete-testsets.mjs.map +1 -0
- package/tools/testsets/get-testsets.d.mts +24 -0
- package/tools/testsets/get-testsets.d.mts.map +1 -0
- package/tools/testsets/get-testsets.d.ts +24 -0
- package/tools/testsets/get-testsets.d.ts.map +1 -0
- package/tools/testsets/get-testsets.js +28 -0
- package/tools/testsets/get-testsets.js.map +1 -0
- package/tools/testsets/get-testsets.mjs +24 -0
- package/tools/testsets/get-testsets.mjs.map +1 -0
- package/tools/testsets/list-testsets.d.mts +24 -0
- package/tools/testsets/list-testsets.d.mts.map +1 -0
- package/tools/testsets/list-testsets.d.ts +24 -0
- package/tools/testsets/list-testsets.d.ts.map +1 -0
- package/tools/testsets/list-testsets.js +36 -0
- package/tools/testsets/list-testsets.js.map +1 -0
- package/tools/testsets/list-testsets.mjs +32 -0
- package/tools/testsets/list-testsets.mjs.map +1 -0
- package/tools/testsets/update-testsets.d.mts +24 -0
- package/tools/testsets/update-testsets.d.mts.map +1 -0
- package/tools/testsets/update-testsets.d.ts +24 -0
- package/tools/testsets/update-testsets.d.ts.map +1 -0
- package/tools/testsets/update-testsets.js +68 -0
- package/tools/testsets/update-testsets.js.map +1 -0
- package/tools/testsets/update-testsets.mjs +64 -0
- package/tools/testsets/update-testsets.mjs.map +1 -0
- package/tools.d.mts +2 -0
- package/tools.d.mts.map +1 -0
- package/tools.d.ts +2 -0
- package/tools.d.ts.map +1 -0
- package/tools.js +18 -0
- package/tools.js.map +1 -0
- package/tools.mjs +2 -0
- package/tools.mjs.map +1 -0
package/compat.test.js
ADDED
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const compat_1 = require("./compat.js");
|
|
4
|
+
describe('truncateToolNames', () => {
|
|
5
|
+
it('should return original names when maxLength is 0 or negative', () => {
|
|
6
|
+
const names = ['tool1', 'tool2', 'tool3'];
|
|
7
|
+
expect((0, compat_1.truncateToolNames)(names, 0)).toEqual(new Map());
|
|
8
|
+
expect((0, compat_1.truncateToolNames)(names, -1)).toEqual(new Map());
|
|
9
|
+
});
|
|
10
|
+
it('should return original names when all names are shorter than maxLength', () => {
|
|
11
|
+
const names = ['tool1', 'tool2', 'tool3'];
|
|
12
|
+
expect((0, compat_1.truncateToolNames)(names, 10)).toEqual(new Map());
|
|
13
|
+
});
|
|
14
|
+
it('should truncate names longer than maxLength', () => {
|
|
15
|
+
const names = ['very-long-tool-name', 'another-long-tool-name', 'short'];
|
|
16
|
+
expect((0, compat_1.truncateToolNames)(names, 10)).toEqual(new Map([
|
|
17
|
+
['very-long-tool-name', 'very-long-'],
|
|
18
|
+
['another-long-tool-name', 'another-lo'],
|
|
19
|
+
]));
|
|
20
|
+
});
|
|
21
|
+
it('should handle duplicate truncated names by appending numbers', () => {
|
|
22
|
+
const names = ['tool-name-a', 'tool-name-b', 'tool-name-c'];
|
|
23
|
+
expect((0, compat_1.truncateToolNames)(names, 8)).toEqual(new Map([
|
|
24
|
+
['tool-name-a', 'tool-na1'],
|
|
25
|
+
['tool-name-b', 'tool-na2'],
|
|
26
|
+
['tool-name-c', 'tool-na3'],
|
|
27
|
+
]));
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe('removeTopLevelUnions', () => {
|
|
31
|
+
const createTestTool = (overrides = {}) => ({
|
|
32
|
+
name: 'test-tool',
|
|
33
|
+
description: 'Test tool',
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {},
|
|
37
|
+
},
|
|
38
|
+
...overrides,
|
|
39
|
+
});
|
|
40
|
+
it('should return the original tool if it has no anyOf at the top level', () => {
|
|
41
|
+
const tool = createTestTool({
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
foo: { type: 'string' },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
expect((0, compat_1.removeTopLevelUnions)(tool)).toEqual([tool]);
|
|
50
|
+
});
|
|
51
|
+
it('should split a tool with top-level anyOf into multiple tools', () => {
|
|
52
|
+
const tool = createTestTool({
|
|
53
|
+
name: 'union-tool',
|
|
54
|
+
description: 'A tool with unions',
|
|
55
|
+
inputSchema: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
common: { type: 'string' },
|
|
59
|
+
},
|
|
60
|
+
anyOf: [
|
|
61
|
+
{
|
|
62
|
+
title: 'first variant',
|
|
63
|
+
description: 'Its the first variant',
|
|
64
|
+
properties: {
|
|
65
|
+
variant1: { type: 'string' },
|
|
66
|
+
},
|
|
67
|
+
required: ['variant1'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
title: 'second variant',
|
|
71
|
+
properties: {
|
|
72
|
+
variant2: { type: 'number' },
|
|
73
|
+
},
|
|
74
|
+
required: ['variant2'],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const result = (0, compat_1.removeTopLevelUnions)(tool);
|
|
80
|
+
expect(result).toEqual([
|
|
81
|
+
{
|
|
82
|
+
name: 'union-tool_first_variant',
|
|
83
|
+
description: 'Its the first variant',
|
|
84
|
+
inputSchema: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
title: 'first variant',
|
|
87
|
+
description: 'Its the first variant',
|
|
88
|
+
properties: {
|
|
89
|
+
common: { type: 'string' },
|
|
90
|
+
variant1: { type: 'string' },
|
|
91
|
+
},
|
|
92
|
+
required: ['variant1'],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'union-tool_second_variant',
|
|
97
|
+
description: 'A tool with unions',
|
|
98
|
+
inputSchema: {
|
|
99
|
+
type: 'object',
|
|
100
|
+
title: 'second variant',
|
|
101
|
+
description: 'A tool with unions',
|
|
102
|
+
properties: {
|
|
103
|
+
common: { type: 'string' },
|
|
104
|
+
variant2: { type: 'number' },
|
|
105
|
+
},
|
|
106
|
+
required: ['variant2'],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
it('should handle $defs and only include those used by the variant', () => {
|
|
112
|
+
const tool = createTestTool({
|
|
113
|
+
name: 'defs-tool',
|
|
114
|
+
description: 'A tool with $defs',
|
|
115
|
+
inputSchema: {
|
|
116
|
+
type: 'object',
|
|
117
|
+
properties: {
|
|
118
|
+
common: { type: 'string' },
|
|
119
|
+
},
|
|
120
|
+
$defs: {
|
|
121
|
+
def1: { type: 'string', format: 'email' },
|
|
122
|
+
def2: { type: 'number', minimum: 0 },
|
|
123
|
+
unused: { type: 'boolean' },
|
|
124
|
+
},
|
|
125
|
+
anyOf: [
|
|
126
|
+
{
|
|
127
|
+
properties: {
|
|
128
|
+
email: { $ref: '#/$defs/def1' },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
properties: {
|
|
133
|
+
count: { $ref: '#/$defs/def2' },
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
const result = (0, compat_1.removeTopLevelUnions)(tool);
|
|
140
|
+
expect(result).toEqual([
|
|
141
|
+
{
|
|
142
|
+
name: 'defs-tool_variant1',
|
|
143
|
+
description: 'A tool with $defs',
|
|
144
|
+
inputSchema: {
|
|
145
|
+
type: 'object',
|
|
146
|
+
description: 'A tool with $defs',
|
|
147
|
+
properties: {
|
|
148
|
+
common: { type: 'string' },
|
|
149
|
+
email: { $ref: '#/$defs/def1' },
|
|
150
|
+
},
|
|
151
|
+
$defs: {
|
|
152
|
+
def1: { type: 'string', format: 'email' },
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: 'defs-tool_variant2',
|
|
158
|
+
description: 'A tool with $defs',
|
|
159
|
+
inputSchema: {
|
|
160
|
+
type: 'object',
|
|
161
|
+
description: 'A tool with $defs',
|
|
162
|
+
properties: {
|
|
163
|
+
common: { type: 'string' },
|
|
164
|
+
count: { $ref: '#/$defs/def2' },
|
|
165
|
+
},
|
|
166
|
+
$defs: {
|
|
167
|
+
def2: { type: 'number', minimum: 0 },
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
describe('removeAnyOf', () => {
|
|
175
|
+
it('should return original schema if it has no anyOf', () => {
|
|
176
|
+
const schema = {
|
|
177
|
+
type: 'object',
|
|
178
|
+
properties: {
|
|
179
|
+
foo: { type: 'string' },
|
|
180
|
+
bar: { type: 'number' },
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
expect((0, compat_1.removeAnyOf)(schema)).toEqual(schema);
|
|
184
|
+
});
|
|
185
|
+
it('should remove anyOf field and use the first variant', () => {
|
|
186
|
+
const schema = {
|
|
187
|
+
type: 'object',
|
|
188
|
+
properties: {
|
|
189
|
+
common: { type: 'string' },
|
|
190
|
+
},
|
|
191
|
+
anyOf: [
|
|
192
|
+
{
|
|
193
|
+
properties: {
|
|
194
|
+
variant1: { type: 'string' },
|
|
195
|
+
},
|
|
196
|
+
required: ['variant1'],
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
properties: {
|
|
200
|
+
variant2: { type: 'number' },
|
|
201
|
+
},
|
|
202
|
+
required: ['variant2'],
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
};
|
|
206
|
+
const expected = {
|
|
207
|
+
type: 'object',
|
|
208
|
+
properties: {
|
|
209
|
+
common: { type: 'string' },
|
|
210
|
+
variant1: { type: 'string' },
|
|
211
|
+
},
|
|
212
|
+
required: ['variant1'],
|
|
213
|
+
};
|
|
214
|
+
expect((0, compat_1.removeAnyOf)(schema)).toEqual(expected);
|
|
215
|
+
});
|
|
216
|
+
it('should recursively remove anyOf fields from nested properties', () => {
|
|
217
|
+
const schema = {
|
|
218
|
+
type: 'object',
|
|
219
|
+
properties: {
|
|
220
|
+
foo: { type: 'string' },
|
|
221
|
+
nested: {
|
|
222
|
+
type: 'object',
|
|
223
|
+
properties: {
|
|
224
|
+
bar: { type: 'number' },
|
|
225
|
+
},
|
|
226
|
+
anyOf: [
|
|
227
|
+
{
|
|
228
|
+
properties: {
|
|
229
|
+
option1: { type: 'boolean' },
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
properties: {
|
|
234
|
+
option2: { type: 'array' },
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
const expected = {
|
|
242
|
+
type: 'object',
|
|
243
|
+
properties: {
|
|
244
|
+
foo: { type: 'string' },
|
|
245
|
+
nested: {
|
|
246
|
+
type: 'object',
|
|
247
|
+
properties: {
|
|
248
|
+
bar: { type: 'number' },
|
|
249
|
+
option1: { type: 'boolean' },
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
expect((0, compat_1.removeAnyOf)(schema)).toEqual(expected);
|
|
255
|
+
});
|
|
256
|
+
it('should handle arrays', () => {
|
|
257
|
+
const schema = {
|
|
258
|
+
type: 'object',
|
|
259
|
+
properties: {
|
|
260
|
+
items: {
|
|
261
|
+
type: 'array',
|
|
262
|
+
items: {
|
|
263
|
+
anyOf: [{ type: 'string' }, { type: 'number' }],
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
const expected = {
|
|
269
|
+
type: 'object',
|
|
270
|
+
properties: {
|
|
271
|
+
items: {
|
|
272
|
+
type: 'array',
|
|
273
|
+
items: {
|
|
274
|
+
type: 'string',
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
expect((0, compat_1.removeAnyOf)(schema)).toEqual(expected);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
describe('inlineRefs', () => {
|
|
283
|
+
it('should return the original schema if it does not contain $refs', () => {
|
|
284
|
+
const schema = {
|
|
285
|
+
type: 'object',
|
|
286
|
+
properties: {
|
|
287
|
+
name: { type: 'string' },
|
|
288
|
+
age: { type: 'number' },
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
expect((0, compat_1.inlineRefs)(schema)).toEqual(schema);
|
|
292
|
+
});
|
|
293
|
+
it('should inline simple $refs', () => {
|
|
294
|
+
const schema = {
|
|
295
|
+
type: 'object',
|
|
296
|
+
properties: {
|
|
297
|
+
user: { $ref: '#/$defs/user' },
|
|
298
|
+
},
|
|
299
|
+
$defs: {
|
|
300
|
+
user: {
|
|
301
|
+
type: 'object',
|
|
302
|
+
properties: {
|
|
303
|
+
name: { type: 'string' },
|
|
304
|
+
email: { type: 'string' },
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
const expected = {
|
|
310
|
+
type: 'object',
|
|
311
|
+
properties: {
|
|
312
|
+
user: {
|
|
313
|
+
type: 'object',
|
|
314
|
+
properties: {
|
|
315
|
+
name: { type: 'string' },
|
|
316
|
+
email: { type: 'string' },
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
expect((0, compat_1.inlineRefs)(schema)).toEqual(expected);
|
|
322
|
+
});
|
|
323
|
+
it('should inline nested $refs', () => {
|
|
324
|
+
const schema = {
|
|
325
|
+
type: 'object',
|
|
326
|
+
properties: {
|
|
327
|
+
order: { $ref: '#/$defs/order' },
|
|
328
|
+
},
|
|
329
|
+
$defs: {
|
|
330
|
+
order: {
|
|
331
|
+
type: 'object',
|
|
332
|
+
properties: {
|
|
333
|
+
id: { type: 'string' },
|
|
334
|
+
items: { type: 'array', items: { $ref: '#/$defs/item' } },
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
item: {
|
|
338
|
+
type: 'object',
|
|
339
|
+
properties: {
|
|
340
|
+
product: { type: 'string' },
|
|
341
|
+
quantity: { type: 'integer' },
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
const expected = {
|
|
347
|
+
type: 'object',
|
|
348
|
+
properties: {
|
|
349
|
+
order: {
|
|
350
|
+
type: 'object',
|
|
351
|
+
properties: {
|
|
352
|
+
id: { type: 'string' },
|
|
353
|
+
items: {
|
|
354
|
+
type: 'array',
|
|
355
|
+
items: {
|
|
356
|
+
type: 'object',
|
|
357
|
+
properties: {
|
|
358
|
+
product: { type: 'string' },
|
|
359
|
+
quantity: { type: 'integer' },
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
expect((0, compat_1.inlineRefs)(schema)).toEqual(expected);
|
|
368
|
+
});
|
|
369
|
+
it('should handle circular references by removing the circular part', () => {
|
|
370
|
+
const schema = {
|
|
371
|
+
type: 'object',
|
|
372
|
+
properties: {
|
|
373
|
+
person: { $ref: '#/$defs/person' },
|
|
374
|
+
},
|
|
375
|
+
$defs: {
|
|
376
|
+
person: {
|
|
377
|
+
type: 'object',
|
|
378
|
+
properties: {
|
|
379
|
+
name: { type: 'string' },
|
|
380
|
+
friend: { $ref: '#/$defs/person' }, // Circular reference
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
const expected = {
|
|
386
|
+
type: 'object',
|
|
387
|
+
properties: {
|
|
388
|
+
person: {
|
|
389
|
+
type: 'object',
|
|
390
|
+
properties: {
|
|
391
|
+
name: { type: 'string' },
|
|
392
|
+
// friend property is removed to break the circular reference
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
expect((0, compat_1.inlineRefs)(schema)).toEqual(expected);
|
|
398
|
+
});
|
|
399
|
+
it('should handle indirect circular references', () => {
|
|
400
|
+
const schema = {
|
|
401
|
+
type: 'object',
|
|
402
|
+
properties: {
|
|
403
|
+
node: { $ref: '#/$defs/node' },
|
|
404
|
+
},
|
|
405
|
+
$defs: {
|
|
406
|
+
node: {
|
|
407
|
+
type: 'object',
|
|
408
|
+
properties: {
|
|
409
|
+
value: { type: 'string' },
|
|
410
|
+
child: { $ref: '#/$defs/childNode' },
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
childNode: {
|
|
414
|
+
type: 'object',
|
|
415
|
+
properties: {
|
|
416
|
+
value: { type: 'string' },
|
|
417
|
+
parent: { $ref: '#/$defs/node' }, // Circular reference through childNode
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
const expected = {
|
|
423
|
+
type: 'object',
|
|
424
|
+
properties: {
|
|
425
|
+
node: {
|
|
426
|
+
type: 'object',
|
|
427
|
+
properties: {
|
|
428
|
+
value: { type: 'string' },
|
|
429
|
+
child: {
|
|
430
|
+
type: 'object',
|
|
431
|
+
properties: {
|
|
432
|
+
value: { type: 'string' },
|
|
433
|
+
// parent property is removed to break the circular reference
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
expect((0, compat_1.inlineRefs)(schema)).toEqual(expected);
|
|
441
|
+
});
|
|
442
|
+
it('should preserve other properties when inlining references', () => {
|
|
443
|
+
const schema = {
|
|
444
|
+
type: 'object',
|
|
445
|
+
properties: {
|
|
446
|
+
address: { $ref: '#/$defs/address', description: 'User address' },
|
|
447
|
+
},
|
|
448
|
+
$defs: {
|
|
449
|
+
address: {
|
|
450
|
+
type: 'object',
|
|
451
|
+
properties: {
|
|
452
|
+
street: { type: 'string' },
|
|
453
|
+
city: { type: 'string' },
|
|
454
|
+
},
|
|
455
|
+
required: ['street'],
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
const expected = {
|
|
460
|
+
type: 'object',
|
|
461
|
+
properties: {
|
|
462
|
+
address: {
|
|
463
|
+
type: 'object',
|
|
464
|
+
description: 'User address',
|
|
465
|
+
properties: {
|
|
466
|
+
street: { type: 'string' },
|
|
467
|
+
city: { type: 'string' },
|
|
468
|
+
},
|
|
469
|
+
required: ['street'],
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
expect((0, compat_1.inlineRefs)(schema)).toEqual(expected);
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
describe('removeFormats', () => {
|
|
477
|
+
it('should return original schema if formats capability is true', () => {
|
|
478
|
+
const schema = {
|
|
479
|
+
type: 'object',
|
|
480
|
+
properties: {
|
|
481
|
+
date: { type: 'string', description: 'A date field', format: 'date' },
|
|
482
|
+
email: { type: 'string', description: 'An email field', format: 'email' },
|
|
483
|
+
},
|
|
484
|
+
};
|
|
485
|
+
expect((0, compat_1.removeFormats)(schema, true)).toEqual(schema);
|
|
486
|
+
});
|
|
487
|
+
it('should move format to description when formats capability is false', () => {
|
|
488
|
+
const schema = {
|
|
489
|
+
type: 'object',
|
|
490
|
+
properties: {
|
|
491
|
+
date: { type: 'string', description: 'A date field', format: 'date' },
|
|
492
|
+
email: { type: 'string', description: 'An email field', format: 'email' },
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
const expected = {
|
|
496
|
+
type: 'object',
|
|
497
|
+
properties: {
|
|
498
|
+
date: { type: 'string', description: 'A date field (format: "date")' },
|
|
499
|
+
email: { type: 'string', description: 'An email field (format: "email")' },
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
expect((0, compat_1.removeFormats)(schema, false)).toEqual(expected);
|
|
503
|
+
});
|
|
504
|
+
it('should handle properties without description', () => {
|
|
505
|
+
const schema = {
|
|
506
|
+
type: 'object',
|
|
507
|
+
properties: {
|
|
508
|
+
date: { type: 'string', format: 'date' },
|
|
509
|
+
},
|
|
510
|
+
};
|
|
511
|
+
const expected = {
|
|
512
|
+
type: 'object',
|
|
513
|
+
properties: {
|
|
514
|
+
date: { type: 'string', description: '(format: "date")' },
|
|
515
|
+
},
|
|
516
|
+
};
|
|
517
|
+
expect((0, compat_1.removeFormats)(schema, false)).toEqual(expected);
|
|
518
|
+
});
|
|
519
|
+
it('should handle nested properties', () => {
|
|
520
|
+
const schema = {
|
|
521
|
+
type: 'object',
|
|
522
|
+
properties: {
|
|
523
|
+
user: {
|
|
524
|
+
type: 'object',
|
|
525
|
+
properties: {
|
|
526
|
+
created_at: { type: 'string', description: 'Creation date', format: 'date-time' },
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
},
|
|
530
|
+
};
|
|
531
|
+
const expected = {
|
|
532
|
+
type: 'object',
|
|
533
|
+
properties: {
|
|
534
|
+
user: {
|
|
535
|
+
type: 'object',
|
|
536
|
+
properties: {
|
|
537
|
+
created_at: { type: 'string', description: 'Creation date (format: "date-time")' },
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
};
|
|
542
|
+
expect((0, compat_1.removeFormats)(schema, false)).toEqual(expected);
|
|
543
|
+
});
|
|
544
|
+
it('should handle arrays of objects', () => {
|
|
545
|
+
const schema = {
|
|
546
|
+
type: 'object',
|
|
547
|
+
properties: {
|
|
548
|
+
dates: {
|
|
549
|
+
type: 'array',
|
|
550
|
+
items: {
|
|
551
|
+
type: 'object',
|
|
552
|
+
properties: {
|
|
553
|
+
start: { type: 'string', description: 'Start date', format: 'date' },
|
|
554
|
+
end: { type: 'string', description: 'End date', format: 'date' },
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
const expected = {
|
|
561
|
+
type: 'object',
|
|
562
|
+
properties: {
|
|
563
|
+
dates: {
|
|
564
|
+
type: 'array',
|
|
565
|
+
items: {
|
|
566
|
+
type: 'object',
|
|
567
|
+
properties: {
|
|
568
|
+
start: { type: 'string', description: 'Start date (format: "date")' },
|
|
569
|
+
end: { type: 'string', description: 'End date (format: "date")' },
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
};
|
|
575
|
+
expect((0, compat_1.removeFormats)(schema, false)).toEqual(expected);
|
|
576
|
+
});
|
|
577
|
+
it('should handle schemas with $defs', () => {
|
|
578
|
+
const schema = {
|
|
579
|
+
type: 'object',
|
|
580
|
+
properties: {
|
|
581
|
+
date: { type: 'string', description: 'A date field', format: 'date' },
|
|
582
|
+
},
|
|
583
|
+
$defs: {
|
|
584
|
+
timestamp: {
|
|
585
|
+
type: 'string',
|
|
586
|
+
description: 'A timestamp field',
|
|
587
|
+
format: 'date-time',
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
};
|
|
591
|
+
const expected = {
|
|
592
|
+
type: 'object',
|
|
593
|
+
properties: {
|
|
594
|
+
date: { type: 'string', description: 'A date field (format: "date")' },
|
|
595
|
+
},
|
|
596
|
+
$defs: {
|
|
597
|
+
timestamp: {
|
|
598
|
+
type: 'string',
|
|
599
|
+
description: 'A timestamp field (format: "date-time")',
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
};
|
|
603
|
+
expect((0, compat_1.removeFormats)(schema, false)).toEqual(expected);
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
describe('applyCompatibilityTransformations', () => {
|
|
607
|
+
const createTestTool = (name, overrides = {}) => ({
|
|
608
|
+
name,
|
|
609
|
+
description: 'Test tool',
|
|
610
|
+
inputSchema: {
|
|
611
|
+
type: 'object',
|
|
612
|
+
properties: {},
|
|
613
|
+
},
|
|
614
|
+
...overrides,
|
|
615
|
+
});
|
|
616
|
+
const createTestEndpoint = (tool) => ({
|
|
617
|
+
tool,
|
|
618
|
+
handler: jest.fn(),
|
|
619
|
+
metadata: {
|
|
620
|
+
resource: 'test',
|
|
621
|
+
operation: 'read',
|
|
622
|
+
tags: [],
|
|
623
|
+
},
|
|
624
|
+
});
|
|
625
|
+
it('should not modify endpoints when all capabilities are enabled', () => {
|
|
626
|
+
const tool = createTestTool('test-tool');
|
|
627
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
628
|
+
const capabilities = {
|
|
629
|
+
topLevelUnions: true,
|
|
630
|
+
validJson: true,
|
|
631
|
+
refs: true,
|
|
632
|
+
unions: true,
|
|
633
|
+
formats: true,
|
|
634
|
+
toolNameLength: undefined,
|
|
635
|
+
};
|
|
636
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
637
|
+
expect(transformed).toEqual(endpoints);
|
|
638
|
+
});
|
|
639
|
+
it('should split tools with top-level unions when topLevelUnions is disabled', () => {
|
|
640
|
+
const tool = createTestTool('union-tool', {
|
|
641
|
+
inputSchema: {
|
|
642
|
+
type: 'object',
|
|
643
|
+
properties: {
|
|
644
|
+
common: { type: 'string' },
|
|
645
|
+
},
|
|
646
|
+
anyOf: [
|
|
647
|
+
{
|
|
648
|
+
title: 'first variant',
|
|
649
|
+
properties: {
|
|
650
|
+
variant1: { type: 'string' },
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
title: 'second variant',
|
|
655
|
+
properties: {
|
|
656
|
+
variant2: { type: 'number' },
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
],
|
|
660
|
+
},
|
|
661
|
+
});
|
|
662
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
663
|
+
const capabilities = {
|
|
664
|
+
topLevelUnions: false,
|
|
665
|
+
validJson: true,
|
|
666
|
+
refs: true,
|
|
667
|
+
unions: true,
|
|
668
|
+
formats: true,
|
|
669
|
+
toolNameLength: undefined,
|
|
670
|
+
};
|
|
671
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
672
|
+
expect(transformed.length).toBe(2);
|
|
673
|
+
expect(transformed[0].tool.name).toBe('union-tool_first_variant');
|
|
674
|
+
expect(transformed[1].tool.name).toBe('union-tool_second_variant');
|
|
675
|
+
});
|
|
676
|
+
it('should handle variants without titles in removeTopLevelUnions', () => {
|
|
677
|
+
const tool = createTestTool('union-tool', {
|
|
678
|
+
inputSchema: {
|
|
679
|
+
type: 'object',
|
|
680
|
+
properties: {
|
|
681
|
+
common: { type: 'string' },
|
|
682
|
+
},
|
|
683
|
+
anyOf: [
|
|
684
|
+
{
|
|
685
|
+
properties: {
|
|
686
|
+
variant1: { type: 'string' },
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
properties: {
|
|
691
|
+
variant2: { type: 'number' },
|
|
692
|
+
},
|
|
693
|
+
},
|
|
694
|
+
],
|
|
695
|
+
},
|
|
696
|
+
});
|
|
697
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
698
|
+
const capabilities = {
|
|
699
|
+
topLevelUnions: false,
|
|
700
|
+
validJson: true,
|
|
701
|
+
refs: true,
|
|
702
|
+
unions: true,
|
|
703
|
+
formats: true,
|
|
704
|
+
toolNameLength: undefined,
|
|
705
|
+
};
|
|
706
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
707
|
+
expect(transformed.length).toBe(2);
|
|
708
|
+
expect(transformed[0].tool.name).toBe('union-tool_variant1');
|
|
709
|
+
expect(transformed[1].tool.name).toBe('union-tool_variant2');
|
|
710
|
+
});
|
|
711
|
+
it('should truncate tool names when toolNameLength is set', () => {
|
|
712
|
+
const tools = [
|
|
713
|
+
createTestTool('very-long-tool-name-that-exceeds-limit'),
|
|
714
|
+
createTestTool('another-long-tool-name-to-truncate'),
|
|
715
|
+
createTestTool('short-name'),
|
|
716
|
+
];
|
|
717
|
+
const endpoints = tools.map(createTestEndpoint);
|
|
718
|
+
const capabilities = {
|
|
719
|
+
topLevelUnions: true,
|
|
720
|
+
validJson: true,
|
|
721
|
+
refs: true,
|
|
722
|
+
unions: true,
|
|
723
|
+
formats: true,
|
|
724
|
+
toolNameLength: 20,
|
|
725
|
+
};
|
|
726
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
727
|
+
expect(transformed[0].tool.name).toBe('very-long-tool-name-');
|
|
728
|
+
expect(transformed[1].tool.name).toBe('another-long-tool-na');
|
|
729
|
+
expect(transformed[2].tool.name).toBe('short-name');
|
|
730
|
+
});
|
|
731
|
+
it('should inline refs when refs capability is disabled', () => {
|
|
732
|
+
const tool = createTestTool('ref-tool', {
|
|
733
|
+
inputSchema: {
|
|
734
|
+
type: 'object',
|
|
735
|
+
properties: {
|
|
736
|
+
user: { $ref: '#/$defs/user' },
|
|
737
|
+
},
|
|
738
|
+
$defs: {
|
|
739
|
+
user: {
|
|
740
|
+
type: 'object',
|
|
741
|
+
properties: {
|
|
742
|
+
name: { type: 'string' },
|
|
743
|
+
email: { type: 'string' },
|
|
744
|
+
},
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
},
|
|
748
|
+
});
|
|
749
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
750
|
+
const capabilities = {
|
|
751
|
+
topLevelUnions: true,
|
|
752
|
+
validJson: true,
|
|
753
|
+
refs: false,
|
|
754
|
+
unions: true,
|
|
755
|
+
formats: true,
|
|
756
|
+
toolNameLength: undefined,
|
|
757
|
+
};
|
|
758
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
759
|
+
const schema = transformed[0].tool.inputSchema;
|
|
760
|
+
expect(schema.$defs).toBeUndefined();
|
|
761
|
+
if (schema.properties) {
|
|
762
|
+
expect(schema.properties['user']).toEqual({
|
|
763
|
+
type: 'object',
|
|
764
|
+
properties: {
|
|
765
|
+
name: { type: 'string' },
|
|
766
|
+
email: { type: 'string' },
|
|
767
|
+
},
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
it('should preserve external refs when inlining', () => {
|
|
772
|
+
const tool = createTestTool('ref-tool', {
|
|
773
|
+
inputSchema: {
|
|
774
|
+
type: 'object',
|
|
775
|
+
properties: {
|
|
776
|
+
internal: { $ref: '#/$defs/internal' },
|
|
777
|
+
external: { $ref: 'https://example.com/schemas/external.json' },
|
|
778
|
+
},
|
|
779
|
+
$defs: {
|
|
780
|
+
internal: {
|
|
781
|
+
type: 'object',
|
|
782
|
+
properties: {
|
|
783
|
+
name: { type: 'string' },
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
},
|
|
787
|
+
},
|
|
788
|
+
});
|
|
789
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
790
|
+
const capabilities = {
|
|
791
|
+
topLevelUnions: true,
|
|
792
|
+
validJson: true,
|
|
793
|
+
refs: false,
|
|
794
|
+
unions: true,
|
|
795
|
+
formats: true,
|
|
796
|
+
toolNameLength: undefined,
|
|
797
|
+
};
|
|
798
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
799
|
+
const schema = transformed[0].tool.inputSchema;
|
|
800
|
+
if (schema.properties) {
|
|
801
|
+
expect(schema.properties['internal']).toEqual({
|
|
802
|
+
type: 'object',
|
|
803
|
+
properties: {
|
|
804
|
+
name: { type: 'string' },
|
|
805
|
+
},
|
|
806
|
+
});
|
|
807
|
+
expect(schema.properties['external']).toEqual({
|
|
808
|
+
$ref: 'https://example.com/schemas/external.json',
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
it('should remove anyOf fields when unions capability is disabled', () => {
|
|
813
|
+
const tool = createTestTool('union-tool', {
|
|
814
|
+
inputSchema: {
|
|
815
|
+
type: 'object',
|
|
816
|
+
properties: {
|
|
817
|
+
field: {
|
|
818
|
+
anyOf: [{ type: 'string' }, { type: 'number' }],
|
|
819
|
+
},
|
|
820
|
+
},
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
824
|
+
const capabilities = {
|
|
825
|
+
topLevelUnions: true,
|
|
826
|
+
validJson: true,
|
|
827
|
+
refs: true,
|
|
828
|
+
unions: false,
|
|
829
|
+
formats: true,
|
|
830
|
+
toolNameLength: undefined,
|
|
831
|
+
};
|
|
832
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
833
|
+
const schema = transformed[0].tool.inputSchema;
|
|
834
|
+
if (schema.properties && schema.properties['field']) {
|
|
835
|
+
const field = schema.properties['field'];
|
|
836
|
+
expect(field.anyOf).toBeUndefined();
|
|
837
|
+
expect(field.type).toBe('string');
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
it('should correctly combine topLevelUnions and toolNameLength transformations', () => {
|
|
841
|
+
const tool = createTestTool('very-long-union-tool-name', {
|
|
842
|
+
inputSchema: {
|
|
843
|
+
type: 'object',
|
|
844
|
+
properties: {
|
|
845
|
+
common: { type: 'string' },
|
|
846
|
+
},
|
|
847
|
+
anyOf: [
|
|
848
|
+
{
|
|
849
|
+
title: 'first variant',
|
|
850
|
+
properties: {
|
|
851
|
+
variant1: { type: 'string' },
|
|
852
|
+
},
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
title: 'second variant',
|
|
856
|
+
properties: {
|
|
857
|
+
variant2: { type: 'number' },
|
|
858
|
+
},
|
|
859
|
+
},
|
|
860
|
+
],
|
|
861
|
+
},
|
|
862
|
+
});
|
|
863
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
864
|
+
const capabilities = {
|
|
865
|
+
topLevelUnions: false,
|
|
866
|
+
validJson: true,
|
|
867
|
+
refs: true,
|
|
868
|
+
unions: true,
|
|
869
|
+
formats: true,
|
|
870
|
+
toolNameLength: 20,
|
|
871
|
+
};
|
|
872
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
873
|
+
expect(transformed.length).toBe(2);
|
|
874
|
+
// Both names should be truncated because they exceed 20 characters
|
|
875
|
+
expect(transformed[0].tool.name).toBe('very-long-union-too1');
|
|
876
|
+
expect(transformed[1].tool.name).toBe('very-long-union-too2');
|
|
877
|
+
});
|
|
878
|
+
it('should correctly combine refs and unions transformations', () => {
|
|
879
|
+
const tool = createTestTool('complex-tool', {
|
|
880
|
+
inputSchema: {
|
|
881
|
+
type: 'object',
|
|
882
|
+
properties: {
|
|
883
|
+
user: { $ref: '#/$defs/user' },
|
|
884
|
+
},
|
|
885
|
+
$defs: {
|
|
886
|
+
user: {
|
|
887
|
+
type: 'object',
|
|
888
|
+
properties: {
|
|
889
|
+
preference: {
|
|
890
|
+
anyOf: [{ type: 'string' }, { type: 'number' }],
|
|
891
|
+
},
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
},
|
|
896
|
+
});
|
|
897
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
898
|
+
const capabilities = {
|
|
899
|
+
topLevelUnions: true,
|
|
900
|
+
validJson: true,
|
|
901
|
+
refs: false,
|
|
902
|
+
unions: false,
|
|
903
|
+
formats: true,
|
|
904
|
+
toolNameLength: undefined,
|
|
905
|
+
};
|
|
906
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
907
|
+
const schema = transformed[0].tool.inputSchema;
|
|
908
|
+
// Refs should be inlined
|
|
909
|
+
expect(schema.$defs).toBeUndefined();
|
|
910
|
+
// Safely access nested properties
|
|
911
|
+
if (schema.properties && schema.properties['user']) {
|
|
912
|
+
const user = schema.properties['user'];
|
|
913
|
+
// User should be inlined
|
|
914
|
+
expect(user.type).toBe('object');
|
|
915
|
+
// AnyOf in the inlined user.preference should be removed
|
|
916
|
+
if (user.properties && user.properties['preference']) {
|
|
917
|
+
const preference = user.properties['preference'];
|
|
918
|
+
expect(preference.anyOf).toBeUndefined();
|
|
919
|
+
expect(preference.type).toBe('string');
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
it('should handle formats capability being false', () => {
|
|
924
|
+
const tool = createTestTool('format-tool', {
|
|
925
|
+
inputSchema: {
|
|
926
|
+
type: 'object',
|
|
927
|
+
properties: {
|
|
928
|
+
date: { type: 'string', description: 'A date', format: 'date' },
|
|
929
|
+
},
|
|
930
|
+
},
|
|
931
|
+
});
|
|
932
|
+
const endpoints = [createTestEndpoint(tool)];
|
|
933
|
+
const capabilities = {
|
|
934
|
+
topLevelUnions: true,
|
|
935
|
+
validJson: true,
|
|
936
|
+
refs: true,
|
|
937
|
+
unions: true,
|
|
938
|
+
formats: false,
|
|
939
|
+
toolNameLength: undefined,
|
|
940
|
+
};
|
|
941
|
+
const transformed = (0, compat_1.applyCompatibilityTransformations)(endpoints, capabilities);
|
|
942
|
+
const schema = transformed[0].tool.inputSchema;
|
|
943
|
+
if (schema.properties && schema.properties['date']) {
|
|
944
|
+
const dateField = schema.properties['date'];
|
|
945
|
+
expect(dateField['format']).toBeUndefined();
|
|
946
|
+
expect(dateField['description']).toBe('A date (format: "date")');
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
//# sourceMappingURL=compat.test.js.map
|