@outfitter/mcp 0.4.0 → 0.4.2

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/index.js CHANGED
@@ -44,343 +44,7 @@ function shouldEmitLog(messageLevel, threshold) {
44
44
  }
45
45
 
46
46
  // src/schema.ts
47
- function zodToJsonSchema(schema) {
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/logging.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { McpLogLevel, mapLogLevelToMcp, shouldEmitLog } from "./shared/@outfitter/mcp-cqpyer9m";
1
+ import { McpLogLevel, mapLogLevelToMcp, shouldEmitLog } from "./shared/@outfitter/mcp-cqpyer9m.js";
2
2
  export { shouldEmitLog, mapLogLevelToMcp, McpLogLevel };
package/dist/schema.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { JsonSchema, zodToJsonSchema } from "./shared/@outfitter/mcp-s80bqcsb";
1
+ import { JsonSchema, zodToJsonSchema } from "./shared/@outfitter/mcp-83zvbna8.js";
2
2
  export { zodToJsonSchema, JsonSchema };
package/dist/schema.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  zodToJsonSchema
4
- } from "./shared/@outfitter/mcp-f91wbr49.js";
4
+ } from "./shared/@outfitter/mcp-zy7b487d.js";
5
5
  export {
6
6
  zodToJsonSchema
7
7
  };
package/dist/server.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { createMcpServer, definePrompt, defineResource, defineResourceTemplate, defineTool } from "./shared/@outfitter/mcp-2vqyt1fj";
2
- import "./shared/@outfitter/mcp-h2twz77x";
3
- import "./shared/@outfitter/mcp-cqpyer9m";
1
+ import { createMcpServer, definePrompt, defineResource, defineResourceTemplate, defineTool } from "./shared/@outfitter/mcp-5b5726ga.js";
2
+ import "./shared/@outfitter/mcp-fks4zt1z.js";
3
+ import "./shared/@outfitter/mcp-cqpyer9m.js";
4
4
  export { defineTool, defineResourceTemplate, defineResource, definePrompt, createMcpServer };
package/dist/server.js CHANGED
@@ -5,10 +5,10 @@ import {
5
5
  defineResource,
6
6
  defineResourceTemplate,
7
7
  defineTool
8
- } from "./shared/@outfitter/mcp-k8r6kefr.js";
8
+ } from "./shared/@outfitter/mcp-hh12tqfg.js";
9
9
  import"./shared/@outfitter/mcp-fjtxsa0x.js";
10
+ import"./shared/@outfitter/mcp-zy7b487d.js";
10
11
  import"./shared/@outfitter/mcp-9m5hs2z0.js";
11
- import"./shared/@outfitter/mcp-f91wbr49.js";
12
12
  export {
13
13
  defineTool,
14
14
  defineResourceTemplate,
@@ -1,4 +1,4 @@
1
- import { McpServer, McpServerOptions, PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ToolDefinition } from "./mcp-h2twz77x";
1
+ import { McpServer, McpServerOptions, PromptDefinition, ResourceDefinition, ResourceTemplateDefinition, ToolDefinition } from "./mcp-fks4zt1z.js";
2
2
  import { OutfitterError } from "@outfitter/contracts";
3
3
  /**
4
4
  * Create an MCP server instance.
@@ -1,4 +1,4 @@
1
- import { ToolDefinition } from "./mcp-h2twz77x";
1
+ import { ToolDefinition } from "./mcp-fks4zt1z.js";
2
2
  import { ActionRegistry, ActionSurface, AnyActionSpec } from "@outfitter/contracts";
3
3
  interface BuildMcpToolsOptions {
4
4
  readonly includeSurfaces?: readonly ActionSurface[];
@@ -0,0 +1,2 @@
1
+ import { JsonSchema, zodToJsonSchema } from "@outfitter/contracts/schema";
2
+ export { JsonSchema, zodToJsonSchema };