@mcp-b/global 2.0.2-canary.20260125211849 → 2.0.3-canary.0

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
@@ -91,46 +91,32 @@ function createLogger(namespace) {
91
91
  //#region src/validation.ts
92
92
  const logger$2 = createLogger("WebModelContext");
93
93
  /**
94
- * Detect if a schema is a Zod schema object and which version.
94
+ * Detect if a schema is a Zod schema object (Record<string, ZodType>)
95
+ * or a JSON Schema object.
95
96
  *
96
97
  * Uses duck-typing to detect Zod schemas:
97
98
  * - Zod 4 schemas have `_zod` property
98
- * - Zod 3 schemas have `_def` property (but not `_zod`)
99
+ * - Zod 3 schemas have `_def` property
100
+ *
101
+ * Both are supported as of Zod 3.25+ (which includes Zod 4 under the hood).
99
102
  */
100
- function detectZodSchema(schema) {
101
- if (typeof schema !== "object" || schema === null) return {
102
- isZodSchema: false,
103
- hasZod4: false,
104
- hasZod3: false
105
- };
106
- if ("type" in schema && typeof schema.type === "string") return {
107
- isZodSchema: false,
108
- hasZod4: false,
109
- hasZod3: false
110
- };
103
+ function isZodSchema(schema) {
104
+ if (typeof schema !== "object" || schema === null) return false;
105
+ if ("type" in schema && typeof schema.type === "string") return false;
111
106
  const values = Object.values(schema);
112
- if (values.length === 0) return {
113
- isZodSchema: false,
114
- hasZod4: false,
115
- hasZod3: false
116
- };
117
- let hasZod4 = false;
118
- let hasZod3 = false;
107
+ if (values.length === 0) return false;
119
108
  for (const val of values) {
120
109
  if (val == null || typeof val !== "object") continue;
121
110
  const obj = val;
122
- if ("_zod" in obj) hasZod4 = true;
123
- else if ("_def" in obj) hasZod3 = true;
111
+ if ("_zod" in obj || "_def" in obj) return true;
124
112
  }
125
- return {
126
- isZodSchema: hasZod4 || hasZod3,
127
- hasZod4,
128
- hasZod3
129
- };
113
+ return false;
130
114
  }
131
115
  /**
132
- * Convert JSON Schema to Zod validator
133
- * Uses Zod 4's native z.fromJSONSchema() for conversion
116
+ * Convert JSON Schema to Zod validator.
117
+ * Uses z.fromJSONSchema() which is available in Zod 4.2+.
118
+ *
119
+ * Works with both Zod 3.25+ and Zod 4.
134
120
  */
135
121
  function jsonSchemaToZod(jsonSchema) {
136
122
  try {
@@ -141,8 +127,11 @@ function jsonSchemaToZod(jsonSchema) {
141
127
  }
142
128
  }
143
129
  /**
144
- * Convert Zod schema object to JSON Schema
145
- * Uses Zod 4's native z.toJSONSchema() for conversion
130
+ * Convert Zod schema object to JSON Schema.
131
+ * Uses the toJSONSchema function from zod/v4.
132
+ *
133
+ * Works with schemas created from both `import { z } from 'zod'` (Zod 3.25+ compat)
134
+ * and `import { z } from 'zod/v4'` (native Zod 4).
146
135
  *
147
136
  * @param schema - Record of Zod type definitions (e.g., { name: z.string(), age: z.number() })
148
137
  * @returns JSON Schema object compatible with MCP InputSchema
@@ -153,25 +142,16 @@ function zodToJsonSchema(schema) {
153
142
  return rest;
154
143
  }
155
144
  /**
156
- * Error thrown when Zod 3 schemas are detected.
157
- * Zod 4 is required for schema conversion.
158
- */
159
- var Zod3SchemaError = class extends Error {
160
- constructor() {
161
- super("Zod 3 schema detected. This package requires Zod 4 for schema support.\n\nSolutions:\n 1. Upgrade to zod@4.x: pnpm add zod@4\n 2. If using zod@3.25+, import from the v4 subpath:\n import { z } from \"zod/v4\"\n 3. Use JSON Schema instead of Zod schemas\n\nSee https://zod.dev/v4/versioning for more information.");
162
- this.name = "Zod3SchemaError";
163
- }
164
- };
165
- /**
166
- * Normalize a schema to both JSON Schema and Zod formats
167
- * Detects which format is provided and converts to the other
145
+ * Normalize a schema to both JSON Schema and Zod formats.
146
+ * Detects which format is provided and converts to the other.
168
147
  *
169
- * @throws {Zod3SchemaError} If Zod 3 schemas are detected
148
+ * Supports:
149
+ * - Zod schemas from `import { z } from 'zod'` (Zod 3.25+ compat layer)
150
+ * - Zod schemas from `import { z } from 'zod/v4'` (native Zod 4)
151
+ * - Plain JSON Schema objects
170
152
  */
171
153
  function normalizeSchema(schema) {
172
- const detection = detectZodSchema(schema);
173
- if (detection.hasZod3 && !detection.hasZod4) throw new Zod3SchemaError();
174
- if (detection.isZodSchema) return {
154
+ if (isZodSchema(schema)) return {
175
155
  jsonSchema: zodToJsonSchema(schema),
176
156
  zodValidator: z.object(schema)
177
157
  };