fastmcp 4.28.4 → 4.29.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/README.md +21 -0
- package/dist/FastMCP.cjs +4 -4
- package/dist/FastMCP.d.cts +4 -2
- package/dist/FastMCP.d.ts +4 -2
- package/dist/FastMCP.js +3 -3
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/{chunk-DPJW5QEO.cjs → chunk-5EEESM57.cjs} +64 -92
- package/dist/chunk-5EEESM57.cjs.map +1 -0
- package/dist/{chunk-OCCYKYIM.cjs → chunk-FBDPX4H2.cjs} +30 -3
- package/dist/chunk-FBDPX4H2.cjs.map +1 -0
- package/dist/{chunk-B2QUCZGV.js → chunk-JCKJRUCE.js} +30 -3
- package/dist/chunk-JCKJRUCE.js.map +1 -0
- package/dist/{chunk-UFPH23EN.js → chunk-RWPENEKV.js} +5 -1
- package/dist/{chunk-UFPH23EN.js.map → chunk-RWPENEKV.js.map} +1 -1
- package/dist/{chunk-7IQ5QHVZ.cjs → chunk-UHJQUSUX.cjs} +5 -1
- package/dist/chunk-UHJQUSUX.cjs.map +1 -0
- package/dist/{chunk-Q57EM4LH.js → chunk-VN5SZ6IE.js} +31 -59
- package/dist/chunk-VN5SZ6IE.js.map +1 -0
- package/dist/edge/index.cjs +15 -4
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.d.cts +4 -0
- package/dist/edge/index.d.ts +4 -0
- package/dist/edge/index.js +13 -2
- package/dist/edge/index.js.map +1 -1
- package/dist/examples/custom-routes.cjs +4 -4
- package/dist/examples/custom-routes.js +3 -3
- package/dist/openapi/index.cjs +145 -132
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.js +136 -123
- package/dist/openapi/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-7IQ5QHVZ.cjs.map +0 -1
- package/dist/chunk-B2QUCZGV.js.map +0 -1
- package/dist/chunk-DPJW5QEO.cjs.map +0 -1
- package/dist/chunk-OCCYKYIM.cjs.map +0 -1
- package/dist/chunk-Q57EM4LH.js.map +0 -1
|
@@ -98,7 +98,7 @@ function zodInputSchema(schema, target) {
|
|
|
98
98
|
function isSchemaRecord(value) {
|
|
99
99
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
100
100
|
}
|
|
101
|
-
function strictSchemaNode(schema, nested, operand) {
|
|
101
|
+
function strictSchemaNode(schema, nested, operand, preserve = false) {
|
|
102
102
|
const { $ref, additionalProperties, allOf, anyOf, oneOf, properties } = schema;
|
|
103
103
|
const hasConditional = "if" in schema && schema.if !== void 0;
|
|
104
104
|
const hasComposition = Boolean(
|
|
@@ -106,7 +106,7 @@ function strictSchemaNode(schema, nested, operand) {
|
|
|
106
106
|
);
|
|
107
107
|
const isObjectSchema = nested ? schema.type === "object" : schema.type === void 0 || schema.type === "object";
|
|
108
108
|
const keepsAdditionalProperties = Object.keys(_nullishCoalesce(properties, () => ( {}))).length === 0 && (typeof additionalProperties === "object" || additionalProperties === true || nested && additionalProperties === void 0 && !properties);
|
|
109
|
-
const closesNode = !operand && !hasComposition && isObjectSchema && !keepsAdditionalProperties;
|
|
109
|
+
const closesNode = !operand && !hasComposition && isObjectSchema && !keepsAdditionalProperties && (!preserve || additionalProperties === void 0);
|
|
110
110
|
const next = {
|
|
111
111
|
...schema,
|
|
112
112
|
...closesNode ? { additionalProperties: false } : {}
|
|
@@ -119,6 +119,33 @@ function strictSchemaNode(schema, nested, operand) {
|
|
|
119
119
|
])
|
|
120
120
|
);
|
|
121
121
|
}
|
|
122
|
+
for (const keyword of ["items", "additionalItems", "prefixItems"]) {
|
|
123
|
+
const child = schema[keyword];
|
|
124
|
+
if (Array.isArray(child)) {
|
|
125
|
+
next[keyword] = child.map(
|
|
126
|
+
(item) => isSchemaRecord(item) ? strictSchemaNode(item, true, false, true) : item
|
|
127
|
+
);
|
|
128
|
+
} else if (isSchemaRecord(child)) {
|
|
129
|
+
next[keyword] = strictSchemaNode(child, true, false, true);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const patternProperties = schema.patternProperties;
|
|
133
|
+
if (isSchemaRecord(patternProperties)) {
|
|
134
|
+
next.patternProperties = Object.fromEntries(
|
|
135
|
+
Object.entries(patternProperties).map(([key, value]) => [
|
|
136
|
+
key,
|
|
137
|
+
isSchemaRecord(value) ? strictSchemaNode(value, true, false, true) : value
|
|
138
|
+
])
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (isSchemaRecord(next.additionalProperties)) {
|
|
142
|
+
next.additionalProperties = strictSchemaNode(
|
|
143
|
+
next.additionalProperties,
|
|
144
|
+
true,
|
|
145
|
+
false,
|
|
146
|
+
true
|
|
147
|
+
);
|
|
148
|
+
}
|
|
122
149
|
for (const keyword of ["allOf", "anyOf", "oneOf"]) {
|
|
123
150
|
const branches = schema[keyword];
|
|
124
151
|
if (Array.isArray(branches)) {
|
|
@@ -141,4 +168,4 @@ function strictSchemaNode(schema, nested, operand) {
|
|
|
141
168
|
|
|
142
169
|
|
|
143
170
|
exports.objectRootSchema = objectRootSchema; exports.strictInputSchema = strictInputSchema; exports.zodInputSchema = zodInputSchema;
|
|
144
|
-
//# sourceMappingURL=chunk-
|
|
171
|
+
//# sourceMappingURL=chunk-FBDPX4H2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/chunk-FBDPX4H2.cjs","../src/strictInputSchema.ts"],"names":[],"mappings":"AAAA;ACEA,0BAAkB;AAUX,SAAS,gBAAA,CAAiB,MAAA,EAAgC;AAC/D,EAAA,OAAO,MAAA,CAAO,KAAA,IAAS,KAAA,EAAA,EAAY,EAAE,GAAG,MAAA,EAAQ,IAAA,EAAM,SAAS,EAAA,EAAI,MAAA;AACrE;AA8BO,SAAS,iBAAA,CACd,MAAA,EACA,OAAA,EAAS,KAAA,EACG;AACZ,EAAA,MAAM,OAAA,EAAS,gBAAA,CAAiB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A;AAIN,EAAA;AAWZ,EAAA;AAIoC,EAAA;AACjC,IAAA;AAC4C,IAAA;AACjD,EAAA;AAEgB,EAAA;AACW,IAAA;AACoB,MAAA;AACzC,QAAA;AACyC,QAAA;AAC1C,MAAA;AACH,IAAA;AACF,EAAA;AASgC,EAAA;AAC2B,IAAA;AAC/B,IAAA;AACF,MAAA;AACG,QAAA;AACzB,MAAA;AACgC,IAAA;AACc,MAAA;AAChD,IAAA;AACF,EAAA;AAGG,EAAA;AACoC,EAAA;AACL,IAAA;AACe,MAAA;AAC3C,QAAA;AAEqB,QAAA;AAEtB,MAAA;AACH,IAAA;AACF,EAAA;AAE+C,EAAA;AACjB,IAAA;AACrB,MAAA;AACL,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAEgD,EAAA;AACc,IAAA;AAC/B,IAAA;AACF,MAAA;AACE,QAAA;AAC3B,MAAA;AACF,IAAA;AACF,EAAA;AAEiD,EAAA;AACW,IAAA;AAC9B,IAAA;AACe,MAAA;AAC3C,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AD1HoD;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fastmcp/fastmcp/dist/chunk-FBDPX4H2.cjs","sourcesContent":[null,"import type { JsonSchema } from \"xsschema\";\n\nimport { z } from \"zod\";\n\n/**\n * Gives a tool's input or output schema the `type: \"object\"` MCP requires at\n * its root, unless it states a type of its own. A union of objects converts to\n * a bare `anyOf` or `oneOf`, and the SDK client rejects a whole `tools/list`\n * that contains one, so a single such tool would hide every other. Arguments\n * and structured content are always objects, so this only rules out values a\n * tool can never be sent or return.\n */\nexport function objectRootSchema(schema: JsonSchema): JsonSchema {\n return schema.type === undefined ? { ...schema, type: \"object\" } : schema;\n}\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 * A plain object that declares an empty `properties`, or a bare one at the\n * top of the input, is still closed: that is how a schema says \"no keys\" —\n * `z.object({})`, or a tool without arguments. An object with `allOf`,\n * `anyOf`, `oneOf`, `$ref`, or `if`, at the root or nested, keeps its own\n * `additionalProperties` as declared, as do the branches of a composition and\n * the `then` and `else` of a condition: `additionalProperties` only sees\n * adjacent properties, so adding it would reject keys declared by a branch,\n * reference target, or condition. The ordinary objects among their\n * `properties` are closed like any other.\n *\n * The root is given an object type (see `objectRootSchema`).\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 strict = strictSchemaNode(schema, nested, false);\n return nested ? strict : objectRootSchema(strict);\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. Close ordinary object occurrences after conversion, but leave\n * intersection operands open to each other's keys. Child values start a new\n * closure context; explicit catchalls, including .strict(), stay as declared.\n */\nexport function zodInputSchema(\n schema: z.ZodType,\n target?: \"draft-7\",\n): JsonSchema {\n const jsonSchema = z.toJSONSchema(schema, {\n io: \"input\",\n target,\n }) as Record<string, unknown>;\n const definitionsKey = target === \"draft-7\" ? \"definitions\" : \"$defs\";\n const definitions: Record<string, unknown> = {};\n const operands = new Map<string, string>();\n\n const closeObjects = (value: unknown, operand = false): unknown => {\n if (!value || typeof value !== \"object\") return value;\n const result = { ...(value as Record<string, unknown>) };\n\n if (\n operand &&\n typeof result.$ref === \"string\" &&\n (result.$ref === \"#\" || result.$ref.startsWith(\"#/\"))\n ) {\n const reference = result.$ref;\n let name = operands.get(reference);\n if (!name) {\n const path = decodeURIComponent(reference.slice(1)).split(\"/\").slice(1);\n const referenced = path.reduce<unknown>(\n (node, key) =>\n node && typeof node === \"object\"\n ? (node as Record<string, unknown>)[\n key.replace(/~1/g, \"/\").replace(/~0/g, \"~\")\n ]\n : undefined,\n jsonSchema,\n );\n if (referenced && typeof referenced === \"object\") {\n name = `__fastmcp_operand_${operands.size}`;\n const existing = jsonSchema[definitionsKey] as object | undefined;\n while (\n Object.hasOwn(existing ?? {}, name) ||\n Object.hasOwn(definitions, name)\n )\n name += \"_\";\n // Reserve the reference before descending, including through child values.\n operands.set(reference, name);\n const copy = { ...(referenced as Record<string, unknown>) };\n delete copy.$schema;\n delete copy.$defs;\n delete copy.definitions;\n definitions[name] = closeObjects(copy, true);\n }\n }\n if (name) result.$ref = `#/${definitionsKey}/${name}`;\n }\n\n if (\n !operand &&\n result.type === \"object\" &&\n result.properties !== undefined &&\n result.additionalProperties === undefined\n ) {\n result.additionalProperties = false;\n }\n\n for (const keyword of [\"allOf\", \"anyOf\", \"oneOf\"]) {\n const branches = result[keyword];\n if (Array.isArray(branches)) {\n // A single allOf branch is Zod's draft-7 reference wrapper, not\n // an intersection. Only intersections introduce a new exemption.\n result[keyword] = branches.map((branch) =>\n closeObjects(\n branch,\n operand || (keyword === \"allOf\" && branches.length > 1),\n ),\n );\n }\n }\n\n for (const keyword of [\n \"$defs\",\n \"definitions\",\n \"patternProperties\",\n \"properties\",\n ]) {\n const children = result[keyword];\n if (children && typeof children === \"object\") {\n result[keyword] = Object.fromEntries(\n Object.entries(children).map(([key, child]) => [\n key,\n closeObjects(child),\n ]),\n );\n }\n }\n for (const keyword of [\n \"additionalItems\",\n \"additionalProperties\",\n \"items\",\n \"prefixItems\",\n \"propertyNames\",\n ]) {\n const child = result[keyword];\n if (child !== undefined) {\n result[keyword] = Array.isArray(child)\n ? child.map((item) => closeObjects(item))\n : closeObjects(child);\n }\n }\n return result;\n };\n\n const closed = closeObjects(jsonSchema) as Record<string, unknown>;\n if (operands.size > 0) {\n closed[definitionsKey] = {\n ...(closed[definitionsKey] as Record<string, unknown>),\n ...definitions,\n };\n }\n return closed as JsonSchema;\n}\n\nfunction isSchemaRecord(value: unknown): value is JsonSchema {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction strictSchemaNode(\n schema: JsonSchema,\n nested: boolean,\n operand: boolean,\n preserve = false,\n): JsonSchema {\n const { $ref, additionalProperties, allOf, anyOf, oneOf, properties } =\n schema;\n const hasConditional = \"if\" in schema && schema.if !== undefined;\n const hasComposition = Boolean(\n $ref || allOf || anyOf || oneOf || hasConditional,\n );\n const isObjectSchema = nested\n ? schema.type === \"object\"\n : schema.type === undefined || schema.type === \"object\";\n\n const keepsAdditionalProperties =\n Object.keys(properties ?? {}).length === 0 &&\n (typeof additionalProperties === \"object\" ||\n additionalProperties === true ||\n (nested && additionalProperties === undefined && !properties));\n\n // Child-value positions keep an `additionalProperties` the node declares:\n // a value schema's openness is part of what the collection means, while a\n // property's own openness is normalized like the root's.\n const closesNode =\n !operand &&\n !hasComposition &&\n isObjectSchema &&\n !keepsAdditionalProperties &&\n (!preserve || additionalProperties === undefined);\n\n const next: Record<string, unknown> = {\n ...schema,\n ...(closesNode ? { additionalProperties: false } : {}),\n };\n\n if (properties) {\n next.properties = Object.fromEntries(\n Object.entries(properties).map(([key, value]) => [\n key,\n isSchemaRecord(value) ? strictSchemaNode(value, true, false) : value,\n ]),\n );\n }\n\n // Value positions hold ordinary object occurrences, so their nested objects\n // are closed like any property. Matching positions (`if`, `not`, `contains`,\n // `propertyNames`, `unevaluated*`) stay as declared: closing them would\n // change what the constraint matches. `$defs` and `definitions` are also\n // left alone: a definition may be referenced from a composition operand,\n // which must keep its own `additionalProperties` to accept keys declared by\n // sibling branches.\n for (const keyword of [\"items\", \"additionalItems\", \"prefixItems\"] as const) {\n const child = (schema as Record<string, unknown>)[keyword];\n if (Array.isArray(child)) {\n next[keyword] = child.map((item) =>\n isSchemaRecord(item) ? strictSchemaNode(item, true, false, true) : item,\n );\n } else if (isSchemaRecord(child)) {\n next[keyword] = strictSchemaNode(child, true, false, true);\n }\n }\n\n const patternProperties = (schema as Record<string, unknown>)\n .patternProperties;\n if (isSchemaRecord(patternProperties)) {\n next.patternProperties = Object.fromEntries(\n Object.entries(patternProperties).map(([key, value]) => [\n key,\n isSchemaRecord(value)\n ? strictSchemaNode(value, true, false, true)\n : value,\n ]),\n );\n }\n\n if (isSchemaRecord(next.additionalProperties)) {\n next.additionalProperties = strictSchemaNode(\n next.additionalProperties,\n true,\n false,\n true,\n );\n }\n\n for (const keyword of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n const branches = (schema as Record<string, unknown>)[keyword];\n if (Array.isArray(branches)) {\n next[keyword] = branches.map((branch) =>\n isSchemaRecord(branch) ? strictSchemaNode(branch, true, true) : branch,\n );\n }\n }\n\n for (const keyword of [\"else\", \"then\"] as const) {\n const branch = (schema as Record<string, unknown>)[keyword];\n if (isSchemaRecord(branch)) {\n next[keyword] = strictSchemaNode(branch, true, true);\n }\n }\n\n return next as JsonSchema;\n}\n"]}
|
|
@@ -98,7 +98,7 @@ function zodInputSchema(schema, target) {
|
|
|
98
98
|
function isSchemaRecord(value) {
|
|
99
99
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
100
100
|
}
|
|
101
|
-
function strictSchemaNode(schema, nested, operand) {
|
|
101
|
+
function strictSchemaNode(schema, nested, operand, preserve = false) {
|
|
102
102
|
const { $ref, additionalProperties, allOf, anyOf, oneOf, properties } = schema;
|
|
103
103
|
const hasConditional = "if" in schema && schema.if !== void 0;
|
|
104
104
|
const hasComposition = Boolean(
|
|
@@ -106,7 +106,7 @@ function strictSchemaNode(schema, nested, operand) {
|
|
|
106
106
|
);
|
|
107
107
|
const isObjectSchema = nested ? schema.type === "object" : schema.type === void 0 || schema.type === "object";
|
|
108
108
|
const keepsAdditionalProperties = Object.keys(properties ?? {}).length === 0 && (typeof additionalProperties === "object" || additionalProperties === true || nested && additionalProperties === void 0 && !properties);
|
|
109
|
-
const closesNode = !operand && !hasComposition && isObjectSchema && !keepsAdditionalProperties;
|
|
109
|
+
const closesNode = !operand && !hasComposition && isObjectSchema && !keepsAdditionalProperties && (!preserve || additionalProperties === void 0);
|
|
110
110
|
const next = {
|
|
111
111
|
...schema,
|
|
112
112
|
...closesNode ? { additionalProperties: false } : {}
|
|
@@ -119,6 +119,33 @@ function strictSchemaNode(schema, nested, operand) {
|
|
|
119
119
|
])
|
|
120
120
|
);
|
|
121
121
|
}
|
|
122
|
+
for (const keyword of ["items", "additionalItems", "prefixItems"]) {
|
|
123
|
+
const child = schema[keyword];
|
|
124
|
+
if (Array.isArray(child)) {
|
|
125
|
+
next[keyword] = child.map(
|
|
126
|
+
(item) => isSchemaRecord(item) ? strictSchemaNode(item, true, false, true) : item
|
|
127
|
+
);
|
|
128
|
+
} else if (isSchemaRecord(child)) {
|
|
129
|
+
next[keyword] = strictSchemaNode(child, true, false, true);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const patternProperties = schema.patternProperties;
|
|
133
|
+
if (isSchemaRecord(patternProperties)) {
|
|
134
|
+
next.patternProperties = Object.fromEntries(
|
|
135
|
+
Object.entries(patternProperties).map(([key, value]) => [
|
|
136
|
+
key,
|
|
137
|
+
isSchemaRecord(value) ? strictSchemaNode(value, true, false, true) : value
|
|
138
|
+
])
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (isSchemaRecord(next.additionalProperties)) {
|
|
142
|
+
next.additionalProperties = strictSchemaNode(
|
|
143
|
+
next.additionalProperties,
|
|
144
|
+
true,
|
|
145
|
+
false,
|
|
146
|
+
true
|
|
147
|
+
);
|
|
148
|
+
}
|
|
122
149
|
for (const keyword of ["allOf", "anyOf", "oneOf"]) {
|
|
123
150
|
const branches = schema[keyword];
|
|
124
151
|
if (Array.isArray(branches)) {
|
|
@@ -141,4 +168,4 @@ export {
|
|
|
141
168
|
strictInputSchema,
|
|
142
169
|
zodInputSchema
|
|
143
170
|
};
|
|
144
|
-
//# sourceMappingURL=chunk-
|
|
171
|
+
//# sourceMappingURL=chunk-JCKJRUCE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/strictInputSchema.ts"],"sourcesContent":["import type { JsonSchema } from \"xsschema\";\n\nimport { z } from \"zod\";\n\n/**\n * Gives a tool's input or output schema the `type: \"object\"` MCP requires at\n * its root, unless it states a type of its own. A union of objects converts to\n * a bare `anyOf` or `oneOf`, and the SDK client rejects a whole `tools/list`\n * that contains one, so a single such tool would hide every other. Arguments\n * and structured content are always objects, so this only rules out values a\n * tool can never be sent or return.\n */\nexport function objectRootSchema(schema: JsonSchema): JsonSchema {\n return schema.type === undefined ? { ...schema, type: \"object\" } : schema;\n}\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 * A plain object that declares an empty `properties`, or a bare one at the\n * top of the input, is still closed: that is how a schema says \"no keys\" —\n * `z.object({})`, or a tool without arguments. An object with `allOf`,\n * `anyOf`, `oneOf`, `$ref`, or `if`, at the root or nested, keeps its own\n * `additionalProperties` as declared, as do the branches of a composition and\n * the `then` and `else` of a condition: `additionalProperties` only sees\n * adjacent properties, so adding it would reject keys declared by a branch,\n * reference target, or condition. The ordinary objects among their\n * `properties` are closed like any other.\n *\n * The root is given an object type (see `objectRootSchema`).\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 strict = strictSchemaNode(schema, nested, false);\n return nested ? strict : objectRootSchema(strict);\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. Close ordinary object occurrences after conversion, but leave\n * intersection operands open to each other's keys. Child values start a new\n * closure context; explicit catchalls, including .strict(), stay as declared.\n */\nexport function zodInputSchema(\n schema: z.ZodType,\n target?: \"draft-7\",\n): JsonSchema {\n const jsonSchema = z.toJSONSchema(schema, {\n io: \"input\",\n target,\n }) as Record<string, unknown>;\n const definitionsKey = target === \"draft-7\" ? \"definitions\" : \"$defs\";\n const definitions: Record<string, unknown> = {};\n const operands = new Map<string, string>();\n\n const closeObjects = (value: unknown, operand = false): unknown => {\n if (!value || typeof value !== \"object\") return value;\n const result = { ...(value as Record<string, unknown>) };\n\n if (\n operand &&\n typeof result.$ref === \"string\" &&\n (result.$ref === \"#\" || result.$ref.startsWith(\"#/\"))\n ) {\n const reference = result.$ref;\n let name = operands.get(reference);\n if (!name) {\n const path = decodeURIComponent(reference.slice(1)).split(\"/\").slice(1);\n const referenced = path.reduce<unknown>(\n (node, key) =>\n node && typeof node === \"object\"\n ? (node as Record<string, unknown>)[\n key.replace(/~1/g, \"/\").replace(/~0/g, \"~\")\n ]\n : undefined,\n jsonSchema,\n );\n if (referenced && typeof referenced === \"object\") {\n name = `__fastmcp_operand_${operands.size}`;\n const existing = jsonSchema[definitionsKey] as object | undefined;\n while (\n Object.hasOwn(existing ?? {}, name) ||\n Object.hasOwn(definitions, name)\n )\n name += \"_\";\n // Reserve the reference before descending, including through child values.\n operands.set(reference, name);\n const copy = { ...(referenced as Record<string, unknown>) };\n delete copy.$schema;\n delete copy.$defs;\n delete copy.definitions;\n definitions[name] = closeObjects(copy, true);\n }\n }\n if (name) result.$ref = `#/${definitionsKey}/${name}`;\n }\n\n if (\n !operand &&\n result.type === \"object\" &&\n result.properties !== undefined &&\n result.additionalProperties === undefined\n ) {\n result.additionalProperties = false;\n }\n\n for (const keyword of [\"allOf\", \"anyOf\", \"oneOf\"]) {\n const branches = result[keyword];\n if (Array.isArray(branches)) {\n // A single allOf branch is Zod's draft-7 reference wrapper, not\n // an intersection. Only intersections introduce a new exemption.\n result[keyword] = branches.map((branch) =>\n closeObjects(\n branch,\n operand || (keyword === \"allOf\" && branches.length > 1),\n ),\n );\n }\n }\n\n for (const keyword of [\n \"$defs\",\n \"definitions\",\n \"patternProperties\",\n \"properties\",\n ]) {\n const children = result[keyword];\n if (children && typeof children === \"object\") {\n result[keyword] = Object.fromEntries(\n Object.entries(children).map(([key, child]) => [\n key,\n closeObjects(child),\n ]),\n );\n }\n }\n for (const keyword of [\n \"additionalItems\",\n \"additionalProperties\",\n \"items\",\n \"prefixItems\",\n \"propertyNames\",\n ]) {\n const child = result[keyword];\n if (child !== undefined) {\n result[keyword] = Array.isArray(child)\n ? child.map((item) => closeObjects(item))\n : closeObjects(child);\n }\n }\n return result;\n };\n\n const closed = closeObjects(jsonSchema) as Record<string, unknown>;\n if (operands.size > 0) {\n closed[definitionsKey] = {\n ...(closed[definitionsKey] as Record<string, unknown>),\n ...definitions,\n };\n }\n return closed as JsonSchema;\n}\n\nfunction isSchemaRecord(value: unknown): value is JsonSchema {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction strictSchemaNode(\n schema: JsonSchema,\n nested: boolean,\n operand: boolean,\n preserve = false,\n): JsonSchema {\n const { $ref, additionalProperties, allOf, anyOf, oneOf, properties } =\n schema;\n const hasConditional = \"if\" in schema && schema.if !== undefined;\n const hasComposition = Boolean(\n $ref || allOf || anyOf || oneOf || hasConditional,\n );\n const isObjectSchema = nested\n ? schema.type === \"object\"\n : schema.type === undefined || schema.type === \"object\";\n\n const keepsAdditionalProperties =\n Object.keys(properties ?? {}).length === 0 &&\n (typeof additionalProperties === \"object\" ||\n additionalProperties === true ||\n (nested && additionalProperties === undefined && !properties));\n\n // Child-value positions keep an `additionalProperties` the node declares:\n // a value schema's openness is part of what the collection means, while a\n // property's own openness is normalized like the root's.\n const closesNode =\n !operand &&\n !hasComposition &&\n isObjectSchema &&\n !keepsAdditionalProperties &&\n (!preserve || additionalProperties === undefined);\n\n const next: Record<string, unknown> = {\n ...schema,\n ...(closesNode ? { additionalProperties: false } : {}),\n };\n\n if (properties) {\n next.properties = Object.fromEntries(\n Object.entries(properties).map(([key, value]) => [\n key,\n isSchemaRecord(value) ? strictSchemaNode(value, true, false) : value,\n ]),\n );\n }\n\n // Value positions hold ordinary object occurrences, so their nested objects\n // are closed like any property. Matching positions (`if`, `not`, `contains`,\n // `propertyNames`, `unevaluated*`) stay as declared: closing them would\n // change what the constraint matches. `$defs` and `definitions` are also\n // left alone: a definition may be referenced from a composition operand,\n // which must keep its own `additionalProperties` to accept keys declared by\n // sibling branches.\n for (const keyword of [\"items\", \"additionalItems\", \"prefixItems\"] as const) {\n const child = (schema as Record<string, unknown>)[keyword];\n if (Array.isArray(child)) {\n next[keyword] = child.map((item) =>\n isSchemaRecord(item) ? strictSchemaNode(item, true, false, true) : item,\n );\n } else if (isSchemaRecord(child)) {\n next[keyword] = strictSchemaNode(child, true, false, true);\n }\n }\n\n const patternProperties = (schema as Record<string, unknown>)\n .patternProperties;\n if (isSchemaRecord(patternProperties)) {\n next.patternProperties = Object.fromEntries(\n Object.entries(patternProperties).map(([key, value]) => [\n key,\n isSchemaRecord(value)\n ? strictSchemaNode(value, true, false, true)\n : value,\n ]),\n );\n }\n\n if (isSchemaRecord(next.additionalProperties)) {\n next.additionalProperties = strictSchemaNode(\n next.additionalProperties,\n true,\n false,\n true,\n );\n }\n\n for (const keyword of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n const branches = (schema as Record<string, unknown>)[keyword];\n if (Array.isArray(branches)) {\n next[keyword] = branches.map((branch) =>\n isSchemaRecord(branch) ? strictSchemaNode(branch, true, true) : branch,\n );\n }\n }\n\n for (const keyword of [\"else\", \"then\"] as const) {\n const branch = (schema as Record<string, unknown>)[keyword];\n if (isSchem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-1149,6 +1149,7 @@ var JWTIssuer = class {
|
|
|
1149
1149
|
|
|
1150
1150
|
// src/auth/utils/pkce.ts
|
|
1151
1151
|
import { createHash, randomBytes as randomBytes2 } from "crypto";
|
|
1152
|
+
var CODE_VERIFIER = /^[A-Za-z0-9._~-]{43,128}$/;
|
|
1152
1153
|
var PKCEUtils = class _PKCEUtils {
|
|
1153
1154
|
/**
|
|
1154
1155
|
* Generate a code challenge from a verifier
|
|
@@ -1204,6 +1205,9 @@ var PKCEUtils = class _PKCEUtils {
|
|
|
1204
1205
|
if (!verifier || !challenge) {
|
|
1205
1206
|
return false;
|
|
1206
1207
|
}
|
|
1208
|
+
if (!CODE_VERIFIER.test(verifier)) {
|
|
1209
|
+
return false;
|
|
1210
|
+
}
|
|
1207
1211
|
if (method === "plain") {
|
|
1208
1212
|
return equalsConstantTime(verifier, challenge);
|
|
1209
1213
|
}
|
|
@@ -3634,4 +3638,4 @@ export {
|
|
|
3634
3638
|
DiskStore,
|
|
3635
3639
|
JWKSVerifier
|
|
3636
3640
|
};
|
|
3637
|
-
//# sourceMappingURL=chunk-
|
|
3641
|
+
//# sourceMappingURL=chunk-RWPENEKV.js.map
|