fastmcp 4.23.5 → 4.23.7

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.
@@ -1,4 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/strictInputSchema.ts
2
+ var _zod2 = require('zod');
2
3
  function strictInputSchema(schema, nested = false) {
3
4
  const { additionalProperties, properties } = schema;
4
5
  const keepsAdditionalProperties = Object.keys(_nullishCoalesce(properties, () => ( {}))).length === 0 && (typeof additionalProperties === "object" || additionalProperties === true || nested && additionalProperties === void 0 && !properties);
@@ -15,8 +16,21 @@ function strictInputSchema(schema, nested = false) {
15
16
  }
16
17
  };
17
18
  }
19
+ function zodInputSchema(schema, target) {
20
+ return _zod2.z.toJSONSchema(schema, {
21
+ io: "input",
22
+ override: ({ jsonSchema, zodSchema }) => {
23
+ const def = zodSchema._zod.def;
24
+ if (def.type === "object" && !def.catchall && jsonSchema.additionalProperties === void 0) {
25
+ jsonSchema.additionalProperties = false;
26
+ }
27
+ },
28
+ target
29
+ });
30
+ }
31
+
18
32
 
19
33
 
20
34
 
21
- exports.strictInputSchema = strictInputSchema;
22
- //# sourceMappingURL=chunk-O22SYZMC.cjs.map
35
+ exports.strictInputSchema = strictInputSchema; exports.zodInputSchema = zodInputSchema;
36
+ //# sourceMappingURL=chunk-MPFPOZ2H.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/chunk-MPFPOZ2H.cjs","../src/strictInputSchema.ts"],"names":[],"mappings":"AAAA;ACEA,2BAAkB;AAsBX,SAAS,iBAAA,CACd,MAAA,EACA,OAAA,EAAS,KAAA,EACG;AACZ,EAAA,MAAM,EAAE,oBAAA,EAAsB,WAAW,EAAA,EAAI,MAAA;AAC7C,EAAA,MAAM,0BAAA,EACJ,MAAA,CAAO,IAAA,kBAAK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AACF,uFAAC","file":"/home/runner/work/fastmcp/fastmcp/dist/chunk-MPFPOZ2H.cjs","sourcesContent":[null,"import type { JsonSchema } from \"xsschema\";\n\nimport { z } from \"zod\";\n\n/**\n * Closes tool input objects to undeclared keys, like xsschema's\n * `strictJsonSchema`, except for objects made only of additional properties.\n * Closing one of those advertises an object that accepts nothing but `{}`,\n * while the tool's own validation still takes any key, so it keeps whatever\n * `additionalProperties` it declared — or none:\n *\n * - a dictionary, whose `additionalProperties` is a schema (`z.record()`, an\n * OpenAPI map), keeps its value schema;\n * - a free-form object, which declares `additionalProperties: true`, or, as an\n * argument, is a bare `{ type: \"object\" }` (OpenAPI's usual spelling), stays\n * open.\n *\n * An object that declares an empty `properties`, or a bare one at the top of\n * the input, is still closed: that is how a schema says \"no keys\" —\n * `z.object({})`, or a tool without arguments.\n *\n * Shared by both runtimes, so a tool's advertised input schema does not depend\n * on whether it is served by `FastMCP` or `EdgeFastMCP`.\n */\nexport function strictInputSchema(\n schema: JsonSchema,\n nested = false,\n): JsonSchema {\n const { additionalProperties, properties } = schema;\n const keepsAdditionalProperties =\n Object.keys(properties ?? {}).length === 0 &&\n (typeof additionalProperties === \"object\" ||\n additionalProperties === true ||\n (nested && additionalProperties === undefined && !properties));\n\n return {\n ...schema,\n ...(keepsAdditionalProperties ? {} : { additionalProperties: false }),\n ...(properties && {\n properties: Object.fromEntries(\n Object.entries(properties).map(([key, value]) => [\n key,\n typeof value === \"object\" && value.type === \"object\"\n ? strictInputSchema(value, true)\n : value,\n ]),\n ),\n }),\n };\n}\n\n/**\n * Converts Zod 4 tool parameters by what a call may send (`io: \"input\"`), so a\n * transformed field advertises the type it parses and a defaulted one is\n * optional. Input-side conversion leaves a plain `z.object()` open, since it\n * strips undeclared keys rather than rejecting them; this closes it, as\n * output-side conversion did, at any depth — including inside arrays, unions\n * and record values, which `strictInputSchema` does not reach. Explicit\n * catchalls (`z.looseObject()`, `.catchall()`) keep what they declare.\n */\nexport function zodInputSchema(\n schema: z.ZodType,\n target?: \"draft-7\",\n): JsonSchema {\n return z.toJSONSchema(schema, {\n io: \"input\",\n override: ({ jsonSchema, zodSchema }) => {\n const def = zodSchema._zod.def;\n if (\n def.type === \"object\" &&\n !def.catchall &&\n jsonSchema.additionalProperties === undefined\n ) {\n jsonSchema.additionalProperties = false;\n }\n },\n target,\n }) as JsonSchema;\n}\n"]}