neuro-vault-mcp 3.3.0 → 3.4.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/cli.js CHANGED
@@ -14263,6 +14263,16 @@ function date4(params) {
14263
14263
  config(en_default());
14264
14264
 
14265
14265
  // src/lib/input-coercion.ts
14266
+ var CoerceError = class extends Error {
14267
+ fieldName;
14268
+ bareMessage;
14269
+ constructor(fieldName, bareMessage) {
14270
+ super(`${fieldName}: ${bareMessage}`);
14271
+ this.name = "CoerceError";
14272
+ this.fieldName = fieldName;
14273
+ this.bareMessage = bareMessage;
14274
+ }
14275
+ };
14266
14276
  function unwrap(schema) {
14267
14277
  let current = schema;
14268
14278
  while (current instanceof external_exports.ZodOptional || current instanceof external_exports.ZodNullable || current instanceof external_exports.ZodDefault) {
@@ -14275,46 +14285,91 @@ function unwrap(schema) {
14275
14285
  function isPlainObject2(value) {
14276
14286
  return typeof value === "object" && value !== null && !Array.isArray(value);
14277
14287
  }
14278
- function coerceField(schema, value) {
14288
+ function describeJsonShape(parsed) {
14289
+ if (parsed === null) return "null";
14290
+ if (Array.isArray(parsed)) return "array";
14291
+ return typeof parsed;
14292
+ }
14293
+ function coerceFieldValue(schema, value, fieldName = "value") {
14279
14294
  if (value === null || value === void 0) return value;
14280
14295
  const inner = unwrap(schema);
14281
14296
  if (inner instanceof external_exports.ZodNumber) {
14282
- if (typeof value === "string" && value.trim() !== "") {
14297
+ if (typeof value === "number") return value;
14298
+ if (typeof value === "string") {
14299
+ if (value.trim() === "") return value;
14283
14300
  const n = Number(value);
14284
14301
  if (Number.isFinite(n)) return n;
14302
+ throw new CoerceError(
14303
+ fieldName,
14304
+ `expected number or numeric string, got ${JSON.stringify(value)}`
14305
+ );
14285
14306
  }
14286
14307
  return value;
14287
14308
  }
14288
14309
  if (inner instanceof external_exports.ZodBoolean) {
14310
+ if (typeof value === "boolean") return value;
14289
14311
  if (value === "true") return true;
14290
14312
  if (value === "false") return false;
14313
+ if (typeof value === "string") {
14314
+ throw new CoerceError(
14315
+ fieldName,
14316
+ `expected boolean or "true"/"false", got ${JSON.stringify(value)}`
14317
+ );
14318
+ }
14291
14319
  return value;
14292
14320
  }
14293
14321
  if (inner instanceof external_exports.ZodObject || inner instanceof external_exports.ZodRecord) {
14322
+ if (isPlainObject2(value)) return value;
14294
14323
  if (typeof value === "string") {
14324
+ let parsed;
14295
14325
  try {
14296
- const parsed = JSON.parse(value);
14297
- if (isPlainObject2(parsed)) return parsed;
14326
+ parsed = JSON.parse(value);
14298
14327
  } catch {
14328
+ throw new CoerceError(
14329
+ fieldName,
14330
+ `expected object or JSON-string of one, failed to parse: ${JSON.stringify(value)}`
14331
+ );
14299
14332
  }
14300
- return value;
14333
+ if (isPlainObject2(parsed)) return parsed;
14334
+ throw new CoerceError(
14335
+ fieldName,
14336
+ `expected object, parsed JSON resolved to ${describeJsonShape(parsed)}`
14337
+ );
14301
14338
  }
14302
14339
  return value;
14303
14340
  }
14304
14341
  return value;
14305
14342
  }
14306
- function coerceInput(schema, value) {
14307
- const inner = unwrap(schema);
14308
- if (!(inner instanceof external_exports.ZodObject)) return value;
14309
- if (!isPlainObject2(value)) return value;
14310
- const shape = inner.shape;
14311
- const out = { ...value };
14312
- for (const key of Object.keys(shape)) {
14313
- if (key in out) {
14314
- out[key] = coerceField(shape[key], out[key]);
14343
+ function wrapField(field, fieldName) {
14344
+ let inner = field;
14345
+ let isOptional = false;
14346
+ while (inner instanceof external_exports.ZodOptional || inner instanceof external_exports.ZodNullable || inner instanceof external_exports.ZodDefault) {
14347
+ if (inner instanceof external_exports.ZodOptional) isOptional = true;
14348
+ const next = inner.unwrap();
14349
+ if (!next) break;
14350
+ inner = next;
14351
+ }
14352
+ const wrapped = external_exports.preprocess((v, ctx) => {
14353
+ try {
14354
+ return coerceFieldValue(inner, v, fieldName);
14355
+ } catch (err) {
14356
+ if (err instanceof CoerceError) {
14357
+ ctx.addIssue({ code: "custom", message: err.bareMessage });
14358
+ return external_exports.NEVER;
14359
+ }
14360
+ throw err;
14315
14361
  }
14362
+ }, inner);
14363
+ return isOptional ? wrapped.optional() : wrapped;
14364
+ }
14365
+ function wrapSchemaWithCoercion(schema) {
14366
+ if (!(schema instanceof external_exports.ZodObject)) return schema;
14367
+ const shape = schema.shape;
14368
+ const newShape = {};
14369
+ for (const [key, field] of Object.entries(shape)) {
14370
+ newShape[key] = wrapField(field, key);
14316
14371
  }
14317
- return out;
14372
+ return external_exports.object(newShape);
14318
14373
  }
14319
14374
 
14320
14375
  // src/lib/tool-response.ts
@@ -14385,18 +14440,18 @@ function formatZodError(error48) {
14385
14440
  return { message, issues };
14386
14441
  }
14387
14442
  function registerTool(tool) {
14443
+ const coercingSchema = wrapSchemaWithCoercion(tool.inputSchema);
14388
14444
  return {
14389
14445
  name: tool.name,
14390
14446
  spec: {
14391
14447
  ...tool.title !== void 0 ? { title: tool.title } : {},
14392
14448
  description: tool.description,
14393
- inputSchema: tool.inputSchema,
14449
+ inputSchema: coercingSchema,
14394
14450
  ...tool.outputSchema !== void 0 ? { outputSchema: tool.outputSchema } : {},
14395
14451
  ...tool.annotations !== void 0 ? { annotations: tool.annotations } : {}
14396
14452
  },
14397
14453
  handler: async (args) => invokeTool(async () => {
14398
- const coerced = coerceInput(tool.inputSchema, args);
14399
- const result = tool.inputSchema.safeParse(coerced);
14454
+ const result = coercingSchema.safeParse(args);
14400
14455
  if (!result.success) {
14401
14456
  const { message, issues } = formatZodError(result.error);
14402
14457
  throw new ToolHandlerError("INVALID_PARAMS", message, { details: { issues } });