@outfitter/mcp 0.4.0 → 0.4.1
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/dist/actions.js +3 -3
- package/dist/index.d.ts +1 -59
- package/dist/index.js +1 -337
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +1 -1
- package/dist/server.js +2 -2
- package/dist/shared/@outfitter/mcp-83zvbna8.d.ts +2 -0
- package/dist/shared/@outfitter/{mcp-9whem1wr.js → mcp-ktapzh9d.js} +1 -1
- package/dist/shared/@outfitter/{mcp-k8r6kefr.js → mcp-nmp5wf0w.js} +1 -1
- package/dist/shared/@outfitter/mcp-zy7b487d.js +5 -0
- package/package.json +3 -3
- package/dist/shared/@outfitter/mcp-f91wbr49.js +0 -341
- package/dist/shared/@outfitter/mcp-s80bqcsb.d.ts +0 -60
package/dist/actions.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
buildMcpTools
|
|
4
|
-
} from "./shared/@outfitter/mcp-
|
|
5
|
-
import"./shared/@outfitter/mcp-
|
|
4
|
+
} from "./shared/@outfitter/mcp-ktapzh9d.js";
|
|
5
|
+
import"./shared/@outfitter/mcp-nmp5wf0w.js";
|
|
6
6
|
import"./shared/@outfitter/mcp-fjtxsa0x.js";
|
|
7
7
|
import"./shared/@outfitter/mcp-9m5hs2z0.js";
|
|
8
|
-
import"./shared/@outfitter/mcp-
|
|
8
|
+
import"./shared/@outfitter/mcp-zy7b487d.js";
|
|
9
9
|
export {
|
|
10
10
|
buildMcpTools
|
|
11
11
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -819,65 +819,7 @@ interface CoreToolsOptions {
|
|
|
819
819
|
type NormalizedQueryInput = Required<Pick<QueryToolInput, "q">> & Omit<QueryToolInput, "q">;
|
|
820
820
|
type CoreToolDefinition = ToolDefinition<DocsToolInput, DocsToolResponse> | ToolDefinition<ConfigToolInput, ConfigToolResponse> | ToolDefinition<QueryToolInput, QueryToolResponse>;
|
|
821
821
|
declare function createCoreTools(options?: CoreToolsOptions): CoreToolDefinition[];
|
|
822
|
-
import {
|
|
823
|
-
/**
|
|
824
|
-
* JSON Schema representation.
|
|
825
|
-
*/
|
|
826
|
-
interface JsonSchema {
|
|
827
|
-
type?: string;
|
|
828
|
-
properties?: Record<string, JsonSchema>;
|
|
829
|
-
required?: string[];
|
|
830
|
-
items?: JsonSchema | JsonSchema[];
|
|
831
|
-
description?: string;
|
|
832
|
-
default?: unknown;
|
|
833
|
-
minimum?: number;
|
|
834
|
-
maximum?: number;
|
|
835
|
-
exclusiveMinimum?: number;
|
|
836
|
-
exclusiveMaximum?: number;
|
|
837
|
-
minLength?: number;
|
|
838
|
-
maxLength?: number;
|
|
839
|
-
pattern?: string;
|
|
840
|
-
format?: string;
|
|
841
|
-
enum?: unknown[];
|
|
842
|
-
const?: unknown;
|
|
843
|
-
anyOf?: JsonSchema[];
|
|
844
|
-
oneOf?: JsonSchema[];
|
|
845
|
-
allOf?: JsonSchema[];
|
|
846
|
-
not?: JsonSchema | Record<string, never>;
|
|
847
|
-
$ref?: string;
|
|
848
|
-
$schema?: string;
|
|
849
|
-
$defs?: Record<string, JsonSchema>;
|
|
850
|
-
definitions?: Record<string, JsonSchema>;
|
|
851
|
-
additionalProperties?: boolean | JsonSchema;
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Convert a Zod schema to JSON Schema format.
|
|
855
|
-
*
|
|
856
|
-
* This is a simplified converter that handles common Zod types.
|
|
857
|
-
* For complex schemas, consider using a full zod-to-json-schema library.
|
|
858
|
-
*
|
|
859
|
-
* @param schema - Zod schema to convert
|
|
860
|
-
* @returns JSON Schema representation
|
|
861
|
-
*
|
|
862
|
-
* @example
|
|
863
|
-
* ```typescript
|
|
864
|
-
* const zodSchema = z.object({
|
|
865
|
-
* name: z.string(),
|
|
866
|
-
* age: z.number().optional(),
|
|
867
|
-
* });
|
|
868
|
-
*
|
|
869
|
-
* const jsonSchema = zodToJsonSchema(zodSchema);
|
|
870
|
-
* // {
|
|
871
|
-
* // type: "object",
|
|
872
|
-
* // properties: {
|
|
873
|
-
* // name: { type: "string" },
|
|
874
|
-
* // age: { type: "number" },
|
|
875
|
-
* // },
|
|
876
|
-
* // required: ["name"],
|
|
877
|
-
* // }
|
|
878
|
-
* ```
|
|
879
|
-
*/
|
|
880
|
-
declare function zodToJsonSchema(schema: z2.ZodType<unknown>): JsonSchema;
|
|
822
|
+
import { JsonSchema, zodToJsonSchema } from "@outfitter/contracts/schema";
|
|
881
823
|
import { OutfitterError as OutfitterError3 } from "@outfitter/contracts";
|
|
882
824
|
/**
|
|
883
825
|
* Create an MCP server instance.
|
package/dist/index.js
CHANGED
|
@@ -44,343 +44,7 @@ function shouldEmitLog(messageLevel, threshold) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// src/schema.ts
|
|
47
|
-
|
|
48
|
-
return convertZodType(schema);
|
|
49
|
-
}
|
|
50
|
-
function getDef(schemaOrDef) {
|
|
51
|
-
if (!schemaOrDef) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (schemaOrDef._def) {
|
|
55
|
-
return schemaOrDef._def;
|
|
56
|
-
}
|
|
57
|
-
if (schemaOrDef.def) {
|
|
58
|
-
return schemaOrDef.def;
|
|
59
|
-
}
|
|
60
|
-
return schemaOrDef;
|
|
61
|
-
}
|
|
62
|
-
function getDescription(schema, def) {
|
|
63
|
-
if (typeof schema?.description === "string") {
|
|
64
|
-
return schema.description;
|
|
65
|
-
}
|
|
66
|
-
if (typeof def?.description === "string") {
|
|
67
|
-
return def.description;
|
|
68
|
-
}
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
function convertZodType(schema) {
|
|
72
|
-
const def = getDef(schema);
|
|
73
|
-
if (!def) {
|
|
74
|
-
return {};
|
|
75
|
-
}
|
|
76
|
-
const typeName = def.typeName ?? def.type;
|
|
77
|
-
let jsonSchema;
|
|
78
|
-
switch (typeName) {
|
|
79
|
-
case "ZodString":
|
|
80
|
-
case "string":
|
|
81
|
-
jsonSchema = convertString(def);
|
|
82
|
-
break;
|
|
83
|
-
case "ZodNumber":
|
|
84
|
-
case "number":
|
|
85
|
-
jsonSchema = convertNumber(def);
|
|
86
|
-
break;
|
|
87
|
-
case "ZodBoolean":
|
|
88
|
-
case "boolean":
|
|
89
|
-
jsonSchema = { type: "boolean" };
|
|
90
|
-
break;
|
|
91
|
-
case "ZodNull":
|
|
92
|
-
case "null":
|
|
93
|
-
jsonSchema = { type: "null" };
|
|
94
|
-
break;
|
|
95
|
-
case "ZodUndefined":
|
|
96
|
-
case "undefined":
|
|
97
|
-
jsonSchema = {};
|
|
98
|
-
break;
|
|
99
|
-
case "ZodArray":
|
|
100
|
-
case "array":
|
|
101
|
-
jsonSchema = convertArray(def);
|
|
102
|
-
break;
|
|
103
|
-
case "ZodObject":
|
|
104
|
-
case "object":
|
|
105
|
-
jsonSchema = convertObject(def);
|
|
106
|
-
break;
|
|
107
|
-
case "ZodOptional":
|
|
108
|
-
case "optional":
|
|
109
|
-
jsonSchema = convertZodType(def.innerType);
|
|
110
|
-
break;
|
|
111
|
-
case "ZodNullable":
|
|
112
|
-
case "nullable":
|
|
113
|
-
jsonSchema = {
|
|
114
|
-
anyOf: [convertZodType(def.innerType), { type: "null" }]
|
|
115
|
-
};
|
|
116
|
-
break;
|
|
117
|
-
case "ZodDefault":
|
|
118
|
-
case "default": {
|
|
119
|
-
const defaultValue = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
|
|
120
|
-
jsonSchema = {
|
|
121
|
-
...convertZodType(def.innerType),
|
|
122
|
-
default: defaultValue
|
|
123
|
-
};
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
case "ZodEnum":
|
|
127
|
-
case "enum": {
|
|
128
|
-
const values = def.values ?? Object.values(def.entries ?? {});
|
|
129
|
-
jsonSchema = {
|
|
130
|
-
type: "string",
|
|
131
|
-
enum: values
|
|
132
|
-
};
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
case "ZodNativeEnum":
|
|
136
|
-
jsonSchema = {
|
|
137
|
-
enum: Object.values(def.values ?? def.entries ?? {})
|
|
138
|
-
};
|
|
139
|
-
break;
|
|
140
|
-
case "ZodLiteral":
|
|
141
|
-
case "literal": {
|
|
142
|
-
const literalValues = Array.isArray(def.values) ? def.values : [def.value].filter((value) => value !== undefined);
|
|
143
|
-
if (literalValues.length > 1) {
|
|
144
|
-
jsonSchema = {
|
|
145
|
-
enum: literalValues
|
|
146
|
-
};
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
jsonSchema = literalValues.length ? {
|
|
150
|
-
const: literalValues[0]
|
|
151
|
-
} : {};
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case "ZodUnion":
|
|
155
|
-
case "union":
|
|
156
|
-
jsonSchema = {
|
|
157
|
-
anyOf: def.options.map(convertZodType)
|
|
158
|
-
};
|
|
159
|
-
break;
|
|
160
|
-
case "ZodIntersection":
|
|
161
|
-
case "intersection":
|
|
162
|
-
jsonSchema = {
|
|
163
|
-
allOf: [convertZodType(def.left), convertZodType(def.right)]
|
|
164
|
-
};
|
|
165
|
-
break;
|
|
166
|
-
case "ZodRecord":
|
|
167
|
-
case "record":
|
|
168
|
-
jsonSchema = {
|
|
169
|
-
type: "object",
|
|
170
|
-
additionalProperties: def.valueType ? convertZodType(def.valueType) : {}
|
|
171
|
-
};
|
|
172
|
-
break;
|
|
173
|
-
case "ZodTuple":
|
|
174
|
-
case "tuple":
|
|
175
|
-
jsonSchema = {
|
|
176
|
-
type: "array",
|
|
177
|
-
items: def.items.map(convertZodType)
|
|
178
|
-
};
|
|
179
|
-
break;
|
|
180
|
-
case "ZodAny":
|
|
181
|
-
case "any":
|
|
182
|
-
jsonSchema = {};
|
|
183
|
-
break;
|
|
184
|
-
case "ZodUnknown":
|
|
185
|
-
case "unknown":
|
|
186
|
-
jsonSchema = {};
|
|
187
|
-
break;
|
|
188
|
-
case "ZodVoid":
|
|
189
|
-
case "void":
|
|
190
|
-
jsonSchema = {};
|
|
191
|
-
break;
|
|
192
|
-
case "ZodNever":
|
|
193
|
-
case "never":
|
|
194
|
-
jsonSchema = { not: {} };
|
|
195
|
-
break;
|
|
196
|
-
case "ZodEffects":
|
|
197
|
-
jsonSchema = convertZodType(def.schema);
|
|
198
|
-
break;
|
|
199
|
-
case "ZodPipeline":
|
|
200
|
-
case "pipe": {
|
|
201
|
-
const outputDef = getDef(def.out);
|
|
202
|
-
const outputType = outputDef?.typeName ?? outputDef?.type;
|
|
203
|
-
jsonSchema = outputType === "transform" ? convertZodType(def.in) : convertZodType(def.out);
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
case "ZodLazy":
|
|
207
|
-
case "lazy":
|
|
208
|
-
jsonSchema = {};
|
|
209
|
-
break;
|
|
210
|
-
default:
|
|
211
|
-
jsonSchema = {};
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
const description = getDescription(schema, def);
|
|
215
|
-
if (description && !jsonSchema.description) {
|
|
216
|
-
jsonSchema.description = description;
|
|
217
|
-
}
|
|
218
|
-
return jsonSchema;
|
|
219
|
-
}
|
|
220
|
-
function convertString(def) {
|
|
221
|
-
const schema = { type: "string" };
|
|
222
|
-
if (def.checks) {
|
|
223
|
-
for (const check of def.checks) {
|
|
224
|
-
const normalizedCheck = check?._zod?.def ?? check?.def ?? check;
|
|
225
|
-
if (normalizedCheck?.kind) {
|
|
226
|
-
switch (normalizedCheck.kind) {
|
|
227
|
-
case "min":
|
|
228
|
-
schema.minLength = normalizedCheck.value;
|
|
229
|
-
break;
|
|
230
|
-
case "max":
|
|
231
|
-
schema.maxLength = normalizedCheck.value;
|
|
232
|
-
break;
|
|
233
|
-
case "length":
|
|
234
|
-
schema.minLength = normalizedCheck.value;
|
|
235
|
-
schema.maxLength = normalizedCheck.value;
|
|
236
|
-
break;
|
|
237
|
-
case "email":
|
|
238
|
-
schema.pattern = "^[^@]+@[^@]+\\.[^@]+$";
|
|
239
|
-
break;
|
|
240
|
-
case "url":
|
|
241
|
-
schema.pattern = "^https?://";
|
|
242
|
-
break;
|
|
243
|
-
case "uuid":
|
|
244
|
-
schema.pattern = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
|
|
245
|
-
break;
|
|
246
|
-
case "regex":
|
|
247
|
-
schema.pattern = normalizedCheck.regex?.source ?? normalizedCheck.pattern?.source ?? (typeof normalizedCheck.pattern === "string" ? normalizedCheck.pattern : undefined);
|
|
248
|
-
break;
|
|
249
|
-
default:
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
if (!normalizedCheck?.check) {
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
switch (normalizedCheck.check) {
|
|
258
|
-
case "min_length":
|
|
259
|
-
schema.minLength = normalizedCheck.minimum;
|
|
260
|
-
break;
|
|
261
|
-
case "max_length":
|
|
262
|
-
schema.maxLength = normalizedCheck.maximum;
|
|
263
|
-
break;
|
|
264
|
-
case "string_format":
|
|
265
|
-
if (normalizedCheck.pattern) {
|
|
266
|
-
schema.pattern = typeof normalizedCheck.pattern === "string" ? normalizedCheck.pattern : normalizedCheck.pattern.source;
|
|
267
|
-
}
|
|
268
|
-
if (normalizedCheck.format && normalizedCheck.format !== "regex") {
|
|
269
|
-
schema.format = normalizedCheck.format;
|
|
270
|
-
}
|
|
271
|
-
break;
|
|
272
|
-
default:
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return schema;
|
|
278
|
-
}
|
|
279
|
-
function convertNumber(def) {
|
|
280
|
-
const schema = { type: "number" };
|
|
281
|
-
if (def.checks) {
|
|
282
|
-
for (const check of def.checks) {
|
|
283
|
-
const normalizedCheck = check?._zod?.def ?? check?.def ?? check;
|
|
284
|
-
if (normalizedCheck?.kind) {
|
|
285
|
-
switch (normalizedCheck.kind) {
|
|
286
|
-
case "min":
|
|
287
|
-
schema.minimum = normalizedCheck.value;
|
|
288
|
-
break;
|
|
289
|
-
case "max":
|
|
290
|
-
schema.maximum = normalizedCheck.value;
|
|
291
|
-
break;
|
|
292
|
-
case "int":
|
|
293
|
-
schema.type = "integer";
|
|
294
|
-
break;
|
|
295
|
-
default:
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
if (!normalizedCheck?.check) {
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
switch (normalizedCheck.check) {
|
|
304
|
-
case "greater_than":
|
|
305
|
-
if (normalizedCheck.inclusive) {
|
|
306
|
-
schema.minimum = normalizedCheck.value;
|
|
307
|
-
} else {
|
|
308
|
-
schema.exclusiveMinimum = normalizedCheck.value;
|
|
309
|
-
}
|
|
310
|
-
break;
|
|
311
|
-
case "less_than":
|
|
312
|
-
if (normalizedCheck.inclusive) {
|
|
313
|
-
schema.maximum = normalizedCheck.value;
|
|
314
|
-
} else {
|
|
315
|
-
schema.exclusiveMaximum = normalizedCheck.value;
|
|
316
|
-
}
|
|
317
|
-
break;
|
|
318
|
-
case "number_format":
|
|
319
|
-
if (normalizedCheck.format === "int" || normalizedCheck.format === "safeint") {
|
|
320
|
-
schema.type = "integer";
|
|
321
|
-
}
|
|
322
|
-
break;
|
|
323
|
-
default:
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return schema;
|
|
329
|
-
}
|
|
330
|
-
function convertArray(def) {
|
|
331
|
-
const element = def.element ?? def.type;
|
|
332
|
-
const schema = {
|
|
333
|
-
type: "array",
|
|
334
|
-
items: element ? convertZodType(element) : {}
|
|
335
|
-
};
|
|
336
|
-
return schema;
|
|
337
|
-
}
|
|
338
|
-
function isFieldOptional(fieldDef) {
|
|
339
|
-
if (!(fieldDef?.typeName || fieldDef?.type)) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
const typeName = fieldDef.typeName ?? fieldDef.type;
|
|
343
|
-
if (typeName === "ZodOptional" || typeName === "ZodDefault" || typeName === "optional" || typeName === "default") {
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
if (typeName === "ZodEffects") {
|
|
347
|
-
return isFieldOptional(getDef(fieldDef.schema));
|
|
348
|
-
}
|
|
349
|
-
if (typeName === "ZodPipeline" || typeName === "pipe") {
|
|
350
|
-
const inputOptional = isFieldOptional(getDef(fieldDef.in));
|
|
351
|
-
const outputDef = getDef(fieldDef.out);
|
|
352
|
-
const outputType = outputDef?.typeName ?? outputDef?.type;
|
|
353
|
-
if (outputType === "transform") {
|
|
354
|
-
return inputOptional;
|
|
355
|
-
}
|
|
356
|
-
const outputOptional = isFieldOptional(outputDef);
|
|
357
|
-
return inputOptional && outputOptional;
|
|
358
|
-
}
|
|
359
|
-
if (typeName === "ZodNullable" || typeName === "nullable") {
|
|
360
|
-
return isFieldOptional(getDef(fieldDef.innerType));
|
|
361
|
-
}
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
function convertObject(def) {
|
|
365
|
-
const properties = {};
|
|
366
|
-
const required = [];
|
|
367
|
-
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
368
|
-
for (const [key, value] of Object.entries(shape ?? {})) {
|
|
369
|
-
properties[key] = convertZodType(value);
|
|
370
|
-
const fieldDef = getDef(value);
|
|
371
|
-
if (!isFieldOptional(fieldDef)) {
|
|
372
|
-
required.push(key);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
const schema = {
|
|
376
|
-
type: "object",
|
|
377
|
-
properties
|
|
378
|
-
};
|
|
379
|
-
if (required.length > 0) {
|
|
380
|
-
schema.required = required;
|
|
381
|
-
}
|
|
382
|
-
return schema;
|
|
383
|
-
}
|
|
47
|
+
import { zodToJsonSchema } from "@outfitter/contracts/schema";
|
|
384
48
|
|
|
385
49
|
// src/types.ts
|
|
386
50
|
import {
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { JsonSchema, zodToJsonSchema } from "./shared/@outfitter/mcp-
|
|
1
|
+
import { JsonSchema, zodToJsonSchema } from "./shared/@outfitter/mcp-83zvbna8";
|
|
2
2
|
export { zodToJsonSchema, JsonSchema };
|
package/dist/schema.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
defineResource,
|
|
6
6
|
defineResourceTemplate,
|
|
7
7
|
defineTool
|
|
8
|
-
} from "./shared/@outfitter/mcp-
|
|
8
|
+
} from "./shared/@outfitter/mcp-nmp5wf0w.js";
|
|
9
9
|
import"./shared/@outfitter/mcp-fjtxsa0x.js";
|
|
10
10
|
import"./shared/@outfitter/mcp-9m5hs2z0.js";
|
|
11
|
-
import"./shared/@outfitter/mcp-
|
|
11
|
+
import"./shared/@outfitter/mcp-zy7b487d.js";
|
|
12
12
|
export {
|
|
13
13
|
defineTool,
|
|
14
14
|
defineResourceTemplate,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outfitter/mcp",
|
|
3
3
|
"description": "MCP server framework with typed tools for Outfitter",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"@outfitter/logging": ">=0.3.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@outfitter/config": "0.3.
|
|
82
|
-
"@outfitter/contracts": "0.
|
|
81
|
+
"@outfitter/config": "0.3.2",
|
|
82
|
+
"@outfitter/contracts": "0.4.0",
|
|
83
83
|
"@outfitter/logging": "0.4.0",
|
|
84
84
|
"@types/bun": "latest",
|
|
85
85
|
"typescript": "^5.8.0"
|
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/mcp/src/schema.ts
|
|
3
|
-
function zodToJsonSchema(schema) {
|
|
4
|
-
return convertZodType(schema);
|
|
5
|
-
}
|
|
6
|
-
function getDef(schemaOrDef) {
|
|
7
|
-
if (!schemaOrDef) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (schemaOrDef._def) {
|
|
11
|
-
return schemaOrDef._def;
|
|
12
|
-
}
|
|
13
|
-
if (schemaOrDef.def) {
|
|
14
|
-
return schemaOrDef.def;
|
|
15
|
-
}
|
|
16
|
-
return schemaOrDef;
|
|
17
|
-
}
|
|
18
|
-
function getDescription(schema, def) {
|
|
19
|
-
if (typeof schema?.description === "string") {
|
|
20
|
-
return schema.description;
|
|
21
|
-
}
|
|
22
|
-
if (typeof def?.description === "string") {
|
|
23
|
-
return def.description;
|
|
24
|
-
}
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
function convertZodType(schema) {
|
|
28
|
-
const def = getDef(schema);
|
|
29
|
-
if (!def) {
|
|
30
|
-
return {};
|
|
31
|
-
}
|
|
32
|
-
const typeName = def.typeName ?? def.type;
|
|
33
|
-
let jsonSchema;
|
|
34
|
-
switch (typeName) {
|
|
35
|
-
case "ZodString":
|
|
36
|
-
case "string":
|
|
37
|
-
jsonSchema = convertString(def);
|
|
38
|
-
break;
|
|
39
|
-
case "ZodNumber":
|
|
40
|
-
case "number":
|
|
41
|
-
jsonSchema = convertNumber(def);
|
|
42
|
-
break;
|
|
43
|
-
case "ZodBoolean":
|
|
44
|
-
case "boolean":
|
|
45
|
-
jsonSchema = { type: "boolean" };
|
|
46
|
-
break;
|
|
47
|
-
case "ZodNull":
|
|
48
|
-
case "null":
|
|
49
|
-
jsonSchema = { type: "null" };
|
|
50
|
-
break;
|
|
51
|
-
case "ZodUndefined":
|
|
52
|
-
case "undefined":
|
|
53
|
-
jsonSchema = {};
|
|
54
|
-
break;
|
|
55
|
-
case "ZodArray":
|
|
56
|
-
case "array":
|
|
57
|
-
jsonSchema = convertArray(def);
|
|
58
|
-
break;
|
|
59
|
-
case "ZodObject":
|
|
60
|
-
case "object":
|
|
61
|
-
jsonSchema = convertObject(def);
|
|
62
|
-
break;
|
|
63
|
-
case "ZodOptional":
|
|
64
|
-
case "optional":
|
|
65
|
-
jsonSchema = convertZodType(def.innerType);
|
|
66
|
-
break;
|
|
67
|
-
case "ZodNullable":
|
|
68
|
-
case "nullable":
|
|
69
|
-
jsonSchema = {
|
|
70
|
-
anyOf: [convertZodType(def.innerType), { type: "null" }]
|
|
71
|
-
};
|
|
72
|
-
break;
|
|
73
|
-
case "ZodDefault":
|
|
74
|
-
case "default": {
|
|
75
|
-
const defaultValue = typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
|
|
76
|
-
jsonSchema = {
|
|
77
|
-
...convertZodType(def.innerType),
|
|
78
|
-
default: defaultValue
|
|
79
|
-
};
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
case "ZodEnum":
|
|
83
|
-
case "enum": {
|
|
84
|
-
const values = def.values ?? Object.values(def.entries ?? {});
|
|
85
|
-
jsonSchema = {
|
|
86
|
-
type: "string",
|
|
87
|
-
enum: values
|
|
88
|
-
};
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case "ZodNativeEnum":
|
|
92
|
-
jsonSchema = {
|
|
93
|
-
enum: Object.values(def.values ?? def.entries ?? {})
|
|
94
|
-
};
|
|
95
|
-
break;
|
|
96
|
-
case "ZodLiteral":
|
|
97
|
-
case "literal": {
|
|
98
|
-
const literalValues = Array.isArray(def.values) ? def.values : [def.value].filter((value) => value !== undefined);
|
|
99
|
-
if (literalValues.length > 1) {
|
|
100
|
-
jsonSchema = {
|
|
101
|
-
enum: literalValues
|
|
102
|
-
};
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
jsonSchema = literalValues.length ? {
|
|
106
|
-
const: literalValues[0]
|
|
107
|
-
} : {};
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
case "ZodUnion":
|
|
111
|
-
case "union":
|
|
112
|
-
jsonSchema = {
|
|
113
|
-
anyOf: def.options.map(convertZodType)
|
|
114
|
-
};
|
|
115
|
-
break;
|
|
116
|
-
case "ZodIntersection":
|
|
117
|
-
case "intersection":
|
|
118
|
-
jsonSchema = {
|
|
119
|
-
allOf: [convertZodType(def.left), convertZodType(def.right)]
|
|
120
|
-
};
|
|
121
|
-
break;
|
|
122
|
-
case "ZodRecord":
|
|
123
|
-
case "record":
|
|
124
|
-
jsonSchema = {
|
|
125
|
-
type: "object",
|
|
126
|
-
additionalProperties: def.valueType ? convertZodType(def.valueType) : {}
|
|
127
|
-
};
|
|
128
|
-
break;
|
|
129
|
-
case "ZodTuple":
|
|
130
|
-
case "tuple":
|
|
131
|
-
jsonSchema = {
|
|
132
|
-
type: "array",
|
|
133
|
-
items: def.items.map(convertZodType)
|
|
134
|
-
};
|
|
135
|
-
break;
|
|
136
|
-
case "ZodAny":
|
|
137
|
-
case "any":
|
|
138
|
-
jsonSchema = {};
|
|
139
|
-
break;
|
|
140
|
-
case "ZodUnknown":
|
|
141
|
-
case "unknown":
|
|
142
|
-
jsonSchema = {};
|
|
143
|
-
break;
|
|
144
|
-
case "ZodVoid":
|
|
145
|
-
case "void":
|
|
146
|
-
jsonSchema = {};
|
|
147
|
-
break;
|
|
148
|
-
case "ZodNever":
|
|
149
|
-
case "never":
|
|
150
|
-
jsonSchema = { not: {} };
|
|
151
|
-
break;
|
|
152
|
-
case "ZodEffects":
|
|
153
|
-
jsonSchema = convertZodType(def.schema);
|
|
154
|
-
break;
|
|
155
|
-
case "ZodPipeline":
|
|
156
|
-
case "pipe": {
|
|
157
|
-
const outputDef = getDef(def.out);
|
|
158
|
-
const outputType = outputDef?.typeName ?? outputDef?.type;
|
|
159
|
-
jsonSchema = outputType === "transform" ? convertZodType(def.in) : convertZodType(def.out);
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
case "ZodLazy":
|
|
163
|
-
case "lazy":
|
|
164
|
-
jsonSchema = {};
|
|
165
|
-
break;
|
|
166
|
-
default:
|
|
167
|
-
jsonSchema = {};
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
const description = getDescription(schema, def);
|
|
171
|
-
if (description && !jsonSchema.description) {
|
|
172
|
-
jsonSchema.description = description;
|
|
173
|
-
}
|
|
174
|
-
return jsonSchema;
|
|
175
|
-
}
|
|
176
|
-
function convertString(def) {
|
|
177
|
-
const schema = { type: "string" };
|
|
178
|
-
if (def.checks) {
|
|
179
|
-
for (const check of def.checks) {
|
|
180
|
-
const normalizedCheck = check?._zod?.def ?? check?.def ?? check;
|
|
181
|
-
if (normalizedCheck?.kind) {
|
|
182
|
-
switch (normalizedCheck.kind) {
|
|
183
|
-
case "min":
|
|
184
|
-
schema.minLength = normalizedCheck.value;
|
|
185
|
-
break;
|
|
186
|
-
case "max":
|
|
187
|
-
schema.maxLength = normalizedCheck.value;
|
|
188
|
-
break;
|
|
189
|
-
case "length":
|
|
190
|
-
schema.minLength = normalizedCheck.value;
|
|
191
|
-
schema.maxLength = normalizedCheck.value;
|
|
192
|
-
break;
|
|
193
|
-
case "email":
|
|
194
|
-
schema.pattern = "^[^@]+@[^@]+\\.[^@]+$";
|
|
195
|
-
break;
|
|
196
|
-
case "url":
|
|
197
|
-
schema.pattern = "^https?://";
|
|
198
|
-
break;
|
|
199
|
-
case "uuid":
|
|
200
|
-
schema.pattern = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
|
|
201
|
-
break;
|
|
202
|
-
case "regex":
|
|
203
|
-
schema.pattern = normalizedCheck.regex?.source ?? normalizedCheck.pattern?.source ?? (typeof normalizedCheck.pattern === "string" ? normalizedCheck.pattern : undefined);
|
|
204
|
-
break;
|
|
205
|
-
default:
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
if (!normalizedCheck?.check) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
switch (normalizedCheck.check) {
|
|
214
|
-
case "min_length":
|
|
215
|
-
schema.minLength = normalizedCheck.minimum;
|
|
216
|
-
break;
|
|
217
|
-
case "max_length":
|
|
218
|
-
schema.maxLength = normalizedCheck.maximum;
|
|
219
|
-
break;
|
|
220
|
-
case "string_format":
|
|
221
|
-
if (normalizedCheck.pattern) {
|
|
222
|
-
schema.pattern = typeof normalizedCheck.pattern === "string" ? normalizedCheck.pattern : normalizedCheck.pattern.source;
|
|
223
|
-
}
|
|
224
|
-
if (normalizedCheck.format && normalizedCheck.format !== "regex") {
|
|
225
|
-
schema.format = normalizedCheck.format;
|
|
226
|
-
}
|
|
227
|
-
break;
|
|
228
|
-
default:
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return schema;
|
|
234
|
-
}
|
|
235
|
-
function convertNumber(def) {
|
|
236
|
-
const schema = { type: "number" };
|
|
237
|
-
if (def.checks) {
|
|
238
|
-
for (const check of def.checks) {
|
|
239
|
-
const normalizedCheck = check?._zod?.def ?? check?.def ?? check;
|
|
240
|
-
if (normalizedCheck?.kind) {
|
|
241
|
-
switch (normalizedCheck.kind) {
|
|
242
|
-
case "min":
|
|
243
|
-
schema.minimum = normalizedCheck.value;
|
|
244
|
-
break;
|
|
245
|
-
case "max":
|
|
246
|
-
schema.maximum = normalizedCheck.value;
|
|
247
|
-
break;
|
|
248
|
-
case "int":
|
|
249
|
-
schema.type = "integer";
|
|
250
|
-
break;
|
|
251
|
-
default:
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
if (!normalizedCheck?.check) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
switch (normalizedCheck.check) {
|
|
260
|
-
case "greater_than":
|
|
261
|
-
if (normalizedCheck.inclusive) {
|
|
262
|
-
schema.minimum = normalizedCheck.value;
|
|
263
|
-
} else {
|
|
264
|
-
schema.exclusiveMinimum = normalizedCheck.value;
|
|
265
|
-
}
|
|
266
|
-
break;
|
|
267
|
-
case "less_than":
|
|
268
|
-
if (normalizedCheck.inclusive) {
|
|
269
|
-
schema.maximum = normalizedCheck.value;
|
|
270
|
-
} else {
|
|
271
|
-
schema.exclusiveMaximum = normalizedCheck.value;
|
|
272
|
-
}
|
|
273
|
-
break;
|
|
274
|
-
case "number_format":
|
|
275
|
-
if (normalizedCheck.format === "int" || normalizedCheck.format === "safeint") {
|
|
276
|
-
schema.type = "integer";
|
|
277
|
-
}
|
|
278
|
-
break;
|
|
279
|
-
default:
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return schema;
|
|
285
|
-
}
|
|
286
|
-
function convertArray(def) {
|
|
287
|
-
const element = def.element ?? def.type;
|
|
288
|
-
const schema = {
|
|
289
|
-
type: "array",
|
|
290
|
-
items: element ? convertZodType(element) : {}
|
|
291
|
-
};
|
|
292
|
-
return schema;
|
|
293
|
-
}
|
|
294
|
-
function isFieldOptional(fieldDef) {
|
|
295
|
-
if (!(fieldDef?.typeName || fieldDef?.type)) {
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
const typeName = fieldDef.typeName ?? fieldDef.type;
|
|
299
|
-
if (typeName === "ZodOptional" || typeName === "ZodDefault" || typeName === "optional" || typeName === "default") {
|
|
300
|
-
return true;
|
|
301
|
-
}
|
|
302
|
-
if (typeName === "ZodEffects") {
|
|
303
|
-
return isFieldOptional(getDef(fieldDef.schema));
|
|
304
|
-
}
|
|
305
|
-
if (typeName === "ZodPipeline" || typeName === "pipe") {
|
|
306
|
-
const inputOptional = isFieldOptional(getDef(fieldDef.in));
|
|
307
|
-
const outputDef = getDef(fieldDef.out);
|
|
308
|
-
const outputType = outputDef?.typeName ?? outputDef?.type;
|
|
309
|
-
if (outputType === "transform") {
|
|
310
|
-
return inputOptional;
|
|
311
|
-
}
|
|
312
|
-
const outputOptional = isFieldOptional(outputDef);
|
|
313
|
-
return inputOptional && outputOptional;
|
|
314
|
-
}
|
|
315
|
-
if (typeName === "ZodNullable" || typeName === "nullable") {
|
|
316
|
-
return isFieldOptional(getDef(fieldDef.innerType));
|
|
317
|
-
}
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
function convertObject(def) {
|
|
321
|
-
const properties = {};
|
|
322
|
-
const required = [];
|
|
323
|
-
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
324
|
-
for (const [key, value] of Object.entries(shape ?? {})) {
|
|
325
|
-
properties[key] = convertZodType(value);
|
|
326
|
-
const fieldDef = getDef(value);
|
|
327
|
-
if (!isFieldOptional(fieldDef)) {
|
|
328
|
-
required.push(key);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
const schema = {
|
|
332
|
-
type: "object",
|
|
333
|
-
properties
|
|
334
|
-
};
|
|
335
|
-
if (required.length > 0) {
|
|
336
|
-
schema.required = required;
|
|
337
|
-
}
|
|
338
|
-
return schema;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
export { zodToJsonSchema };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* JSON Schema representation.
|
|
4
|
-
*/
|
|
5
|
-
interface JsonSchema {
|
|
6
|
-
type?: string;
|
|
7
|
-
properties?: Record<string, JsonSchema>;
|
|
8
|
-
required?: string[];
|
|
9
|
-
items?: JsonSchema | JsonSchema[];
|
|
10
|
-
description?: string;
|
|
11
|
-
default?: unknown;
|
|
12
|
-
minimum?: number;
|
|
13
|
-
maximum?: number;
|
|
14
|
-
exclusiveMinimum?: number;
|
|
15
|
-
exclusiveMaximum?: number;
|
|
16
|
-
minLength?: number;
|
|
17
|
-
maxLength?: number;
|
|
18
|
-
pattern?: string;
|
|
19
|
-
format?: string;
|
|
20
|
-
enum?: unknown[];
|
|
21
|
-
const?: unknown;
|
|
22
|
-
anyOf?: JsonSchema[];
|
|
23
|
-
oneOf?: JsonSchema[];
|
|
24
|
-
allOf?: JsonSchema[];
|
|
25
|
-
not?: JsonSchema | Record<string, never>;
|
|
26
|
-
$ref?: string;
|
|
27
|
-
$schema?: string;
|
|
28
|
-
$defs?: Record<string, JsonSchema>;
|
|
29
|
-
definitions?: Record<string, JsonSchema>;
|
|
30
|
-
additionalProperties?: boolean | JsonSchema;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Convert a Zod schema to JSON Schema format.
|
|
34
|
-
*
|
|
35
|
-
* This is a simplified converter that handles common Zod types.
|
|
36
|
-
* For complex schemas, consider using a full zod-to-json-schema library.
|
|
37
|
-
*
|
|
38
|
-
* @param schema - Zod schema to convert
|
|
39
|
-
* @returns JSON Schema representation
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const zodSchema = z.object({
|
|
44
|
-
* name: z.string(),
|
|
45
|
-
* age: z.number().optional(),
|
|
46
|
-
* });
|
|
47
|
-
*
|
|
48
|
-
* const jsonSchema = zodToJsonSchema(zodSchema);
|
|
49
|
-
* // {
|
|
50
|
-
* // type: "object",
|
|
51
|
-
* // properties: {
|
|
52
|
-
* // name: { type: "string" },
|
|
53
|
-
* // age: { type: "number" },
|
|
54
|
-
* // },
|
|
55
|
-
* // required: ["name"],
|
|
56
|
-
* // }
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare function zodToJsonSchema(schema: z.ZodType<unknown>): JsonSchema;
|
|
60
|
-
export { JsonSchema, zodToJsonSchema };
|