fastmcp 4.30.1 → 4.30.3

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.
Files changed (39) hide show
  1. package/dist/FastMCP.cjs +4 -4
  2. package/dist/FastMCP.d.cts +2 -2
  3. package/dist/FastMCP.d.ts +2 -2
  4. package/dist/FastMCP.js +3 -3
  5. package/dist/{OAuthProvider-C2Z93xC5.d.cts → OAuthProvider-BuBMMpsX.d.cts} +18 -2
  6. package/dist/{OAuthProvider-C2Z93xC5.d.ts → OAuthProvider-BuBMMpsX.d.ts} +18 -2
  7. package/dist/auth/index.cjs +2 -2
  8. package/dist/auth/index.d.cts +2 -2
  9. package/dist/auth/index.d.ts +2 -2
  10. package/dist/auth/index.js +1 -1
  11. package/dist/{chunk-CZGQ2WTQ.cjs → chunk-F7XD3S4L.cjs} +54 -7
  12. package/dist/chunk-F7XD3S4L.cjs.map +1 -0
  13. package/dist/{chunk-4JEDH2ON.cjs → chunk-M3SNOHIM.cjs} +156 -85
  14. package/dist/chunk-M3SNOHIM.cjs.map +1 -0
  15. package/dist/{chunk-FBDPX4H2.cjs → chunk-NYV5TK43.cjs} +125 -2
  16. package/dist/chunk-NYV5TK43.cjs.map +1 -0
  17. package/dist/{chunk-XPTUOWUT.js → chunk-P4ZFER5I.js} +50 -3
  18. package/dist/chunk-P4ZFER5I.js.map +1 -0
  19. package/dist/{chunk-5KA6SOWT.js → chunk-UEEX3RD5.js} +109 -38
  20. package/dist/chunk-UEEX3RD5.js.map +1 -0
  21. package/dist/{chunk-JCKJRUCE.js → chunk-YEXAT4PO.js} +125 -2
  22. package/dist/chunk-YEXAT4PO.js.map +1 -0
  23. package/dist/edge/index.cjs +4 -4
  24. package/dist/edge/index.js +1 -1
  25. package/dist/examples/custom-routes.cjs +4 -4
  26. package/dist/examples/custom-routes.js +3 -3
  27. package/dist/openapi/index.cjs +15 -12
  28. package/dist/openapi/index.cjs.map +1 -1
  29. package/dist/openapi/index.d.cts +4 -3
  30. package/dist/openapi/index.d.ts +4 -3
  31. package/dist/openapi/index.js +9 -6
  32. package/dist/openapi/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-4JEDH2ON.cjs.map +0 -1
  35. package/dist/chunk-5KA6SOWT.js.map +0 -1
  36. package/dist/chunk-CZGQ2WTQ.cjs.map +0 -1
  37. package/dist/chunk-FBDPX4H2.cjs.map +0 -1
  38. package/dist/chunk-JCKJRUCE.js.map +0 -1
  39. package/dist/chunk-XPTUOWUT.js.map +0 -1
@@ -95,9 +95,131 @@ function zodInputSchema(schema, target) {
95
95
  }
96
96
  return closed;
97
97
  }
98
+ function zodOutputSchema(schema, target) {
99
+ const jsonSchema = _zod.z.toJSONSchema(schema, {
100
+ io: "output",
101
+ target
102
+ });
103
+ return flattenClosedIntersections(jsonSchema);
104
+ }
105
+ function flattenClosedIntersections(node) {
106
+ const next = { ...node };
107
+ for (const keyword of ["allOf", "anyOf", "oneOf"]) {
108
+ const branches = next[keyword];
109
+ if (Array.isArray(branches)) {
110
+ next[keyword] = branches.map(
111
+ (branch) => isSchemaRecord(branch) ? flattenClosedIntersections(branch) : branch
112
+ );
113
+ }
114
+ }
115
+ for (const keyword of [
116
+ "$defs",
117
+ "definitions",
118
+ "patternProperties",
119
+ "properties"
120
+ ]) {
121
+ const children = next[keyword];
122
+ if (isSchemaRecord(children)) {
123
+ next[keyword] = Object.fromEntries(
124
+ Object.entries(children).map(
125
+ ([key, child]) => [
126
+ key,
127
+ isSchemaRecord(child) ? flattenClosedIntersections(child) : child
128
+ ]
129
+ )
130
+ );
131
+ }
132
+ }
133
+ for (const keyword of [
134
+ "additionalItems",
135
+ "additionalProperties",
136
+ "contains",
137
+ "else",
138
+ "if",
139
+ "items",
140
+ "not",
141
+ "prefixItems",
142
+ "propertyNames",
143
+ "then"
144
+ ]) {
145
+ const child = next[keyword];
146
+ if (Array.isArray(child)) {
147
+ next[keyword] = child.map(
148
+ (item) => isSchemaRecord(item) ? flattenClosedIntersections(item) : item
149
+ );
150
+ } else if (isSchemaRecord(child)) {
151
+ next[keyword] = flattenClosedIntersections(
152
+ child
153
+ );
154
+ }
155
+ }
156
+ return mergeClosedOperands(next);
157
+ }
158
+ function intersectSchema(left, right) {
159
+ if (JSON.stringify(left) === JSON.stringify(right)) return left;
160
+ if (isSchemaRecord(left) && isSchemaRecord(right)) {
161
+ return flattenClosedIntersections({
162
+ allOf: [left, right]
163
+ });
164
+ }
165
+ return { allOf: [left, right] };
166
+ }
98
167
  function isSchemaRecord(value) {
99
168
  return typeof value === "object" && value !== null && !Array.isArray(value);
100
169
  }
170
+ function mergeClosedOperands(node) {
171
+ const branches = node.allOf;
172
+ if (!Array.isArray(branches) || branches.length < 2)
173
+ return node;
174
+ for (const keyword of [
175
+ "additionalProperties",
176
+ "anyOf",
177
+ "if",
178
+ "oneOf",
179
+ "patternProperties",
180
+ "properties",
181
+ "required",
182
+ "$ref"
183
+ ]) {
184
+ if (keyword in node) return node;
185
+ }
186
+ const properties = {};
187
+ const required = [];
188
+ let closes = false;
189
+ for (const branch of branches) {
190
+ if (!isSchemaRecord(branch) || branch.type !== "object" || "$ref" in branch || "allOf" in branch || "anyOf" in branch || "if" in branch || "oneOf" in branch || branch.patternProperties !== void 0) {
191
+ return node;
192
+ }
193
+ const additionalProperties = branch.additionalProperties;
194
+ if (additionalProperties !== false && additionalProperties !== void 0) {
195
+ return node;
196
+ }
197
+ if (additionalProperties === false) closes = true;
198
+ const branchProperties = branch.properties;
199
+ if (branchProperties !== void 0 && !isSchemaRecord(branchProperties)) {
200
+ return node;
201
+ }
202
+ for (const [key, value] of Object.entries(
203
+ _nullishCoalesce(branchProperties, () => ( {}))
204
+ )) {
205
+ const existing = properties[key];
206
+ properties[key] = existing === void 0 ? value : intersectSchema(existing, value);
207
+ }
208
+ for (const key of Array.isArray(branch.required) ? branch.required : []) {
209
+ if (typeof key === "string" && !required.includes(key))
210
+ required.push(key);
211
+ }
212
+ }
213
+ const rest = { ...node };
214
+ delete rest.allOf;
215
+ return {
216
+ ...rest,
217
+ ...required.length > 0 ? { required } : {},
218
+ ...closes ? { additionalProperties: false } : {},
219
+ properties,
220
+ type: "object"
221
+ };
222
+ }
101
223
  function strictSchemaNode(schema, nested, operand, preserve = false) {
102
224
  const { $ref, additionalProperties, allOf, anyOf, oneOf, properties } = schema;
103
225
  const hasConditional = "if" in schema && schema.if !== void 0;
@@ -167,5 +289,6 @@ function strictSchemaNode(schema, nested, operand, preserve = false) {
167
289
 
168
290
 
169
291
 
170
- exports.objectRootSchema = objectRootSchema; exports.strictInputSchema = strictInputSchema; exports.zodInputSchema = zodInputSchema;
171
- //# sourceMappingURL=chunk-FBDPX4H2.cjs.map
292
+
293
+ exports.objectRootSchema = objectRootSchema; exports.strictInputSchema = strictInputSchema; exports.zodInputSchema = zodInputSchema; exports.zodOutputSchema = zodOutputSchema;
294
+ //# sourceMappingURL=chunk-NYV5TK43.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/fastmcp/fastmcp/dist/chunk-NYV5TK43.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,MAAA,EAAQ,MAAA,EAAQ,KAAK,CAAA;AACrD,EAAA,OAAO,OAAA,EAAS,OAAA,EAAS,gBAAA,CAAiB,MAAM,CAAA;AAClD;AASO,SAAS,cAAA,CACd,MAAA,EACA,MAAA,EACY;AACZ,EAAA,MAAM,WAAA,EAAa,MAAA,CAAE,YAAA,CAAa,MAAA,EAAQ;AAAA,IACxC,EAAA,EAAI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AAA;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;ADzKoD;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/fastmcp/fastmcp/dist/chunk-NYV5TK43.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\n/**\n * Converts Zod 4 tool output schemas by what a call returns (`io: \"output\"`),\n * then flattens closed object intersections, because Zod before 4.2 lists the\n * operands of `a.and(b)` as `allOf` branches that each appear closed\n * (`additionalProperties: false`). Every branch then rejects the properties of\n * the other, so the advertised schema cannot be satisfied and the SDK client\n * rejects the server's own structured content with\n * `data must NOT have additional properties`. Zod 4.2 and later flatten the\n * intersection into one closed object instead; this keeps the locked floor\n * (`zod`: `^4.1.13`) advertising what later versions would.\n *\n * Only operand lists made up entirely of plain object branches are flattened.\n * A branch that references a definition, composes further, or opens its\n * additional properties is left as Zod converted it.\n */\nexport function zodOutputSchema(\n schema: z.ZodType,\n target?: \"draft-7\",\n): JsonSchema {\n const jsonSchema = z.toJSONSchema(schema, {\n io: \"output\",\n target,\n }) as Record<string, unknown>;\n\n return flattenClosedIntersections(jsonSchema);\n}\n\n/** Merges the closed object operands of `allOf` into the object they describe. */\nfunction flattenClosedIntersections(node: Record<string, unknown>): JsonSchema {\n const next: Record<string, unknown> = { ...node };\n\n for (const keyword of [\"allOf\", \"anyOf\", \"oneOf\"] as const) {\n const branches = next[keyword];\n if (Array.isArray(branches)) {\n next[keyword] = branches.map((branch) =>\n isSchemaRecord(branch)\n ? flattenClosedIntersections(branch as Record<string, unknown>)\n : branch,\n );\n }\n }\n for (const keyword of [\n \"$defs\",\n \"definitions\",\n \"patternProperties\",\n \"properties\",\n ] as const) {\n const children = next[keyword];\n if (isSchemaRecord(children)) {\n next[keyword] = Object.fromEntries(\n Object.entries(children as Record<string, unknown>).map(\n ([key, child]) => [\n key,\n isSchemaRecord(child)\n ? flattenClosedIntersections(child as Record<string, unknown>)\n : child,\n ],\n ),\n );\n }\n }\n for (const keyword of [\n \"additionalItems\",\n \"additionalProperties\",\n \"contains\",\n \"else\",\n \"if\",\n \"items\",\n \"not\",\n \"prefixItems\",\n \"propertyNames\",\n \"then\",\n ] as const) {\n const child = next[keyword];\n if (Array.isArray(child)) {\n next[keyword] = child.map((item) =>\n isSchemaRecord(item)\n ? flattenClosedIntersections(item as Record<string, unknown>)\n : item,\n );\n } else if (isSchemaRecord(child)) {\n next[keyword] = flattenClosedIntersections(\n child as Record<string, unknown>,\n );\n }\n }\n\n return mergeClosedOperands(next);\n}\n\n/** Keeps both declarations of a property two operands share. */\nfunction intersectSchema(left: unknown, right: unknown): unknown {\n if (JSON.stringify(left) === JSON.stringify(right)) return left;\n if (isSchemaRecord(left) && isSchemaRecord(right)) {\n return flattenClosedIntersections({\n allOf: [left, right],\n } as Record<string, unknown>);\n }\n return { allOf: [left, right] };\n}\n\nfunction isSchemaRecord(value: unknown): value is JsonSchema {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction mergeClosedOperands(node: Record<string, unknown>): JsonSchema {\n const branches = node.allOf;\n if (!Array.isArray(branches) || branches.length < 2)\n return node as JsonSchema;\n // The node itself must describe nothing but the intersection, so that\n // moving the operands' declarations onto it preserves its meaning.\n for (const keyword of [\n \"additionalProperties\",\n \"anyOf\",\n \"if\",\n \"oneOf\",\n \"patternProperties\",\n \"properties\",\n \"required\",\n \"$ref\",\n ]) {\n if (keyword in node) return node as JsonSchema;\n }\n\n const properties: Record<string, unknown> = {};\n const required: string[] = [];\n let closes = false;\n for (const branch of branches) {\n if (\n !isSchemaRecord(branch) ||\n branch.type !== \"object\" ||\n \"$ref\" in branch ||\n \"allOf\" in branch ||\n \"anyOf\" in branch ||\n \"if\" in branch ||\n \"oneOf\" in branch ||\n branch.patternProperties !== undefined\n ) {\n return node as JsonSchema;\n }\n const additionalProperties = branch.additionalProperties;\n if (additionalProperties !== false && additionalProperties !== undefined) {\n return node as JsonSchema;\n }\n if (additionalProperties === false) closes = true;\n const branchProperties = branch.properties;\n if (branchProperties !== undefined && !isSchemaRecord(branchProperties)) {\n return node as JsonSchema;\n }\n for (const [key, value] of Object.entries(\n (branchProperties ?? {}) as Record<string, unknown>,\n )) {\n const existing = properties[key];\n properties[key] =\n existing === undefined ? value : intersectSchema(existing, value);\n }\n for (const key of Array.isArray(branch.required) ? branch.required : []) {\n if (typeof key === \"string\" && !required.includes(key))\n required.push(key);\n }\n }\n\n const rest: Record<string, unknown> = { ...node };\n delete rest.allOf;\n return {\n ...rest,\n ...(required.length > 0 ? { required } : {}),\n ...(closes ? { additionalProperties: false } : {}),\n properties,\n type: \"object\",\n } as JsonSchema;\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"]}
@@ -496,13 +496,16 @@ var ClaimsExtractor = class {
496
496
  // decision (see JWTClaims); a passthrough "scope" would otherwise overwrite the
497
497
  // scope embedded in the signed FastMCP JWT, diverging from the stored mapping.
498
498
  PROTECTED_CLAIMS = /* @__PURE__ */ new Set([
499
+ "__proto__",
499
500
  "aud",
500
501
  "client_id",
502
+ "constructor",
501
503
  "exp",
502
504
  "iat",
503
505
  "iss",
504
506
  "jti",
505
507
  "nbf",
508
+ "prototype",
506
509
  "scope",
507
510
  // Whether a proxy token is an access or a refresh token.
508
511
  "token_use"
@@ -544,6 +547,15 @@ var ClaimsExtractor = class {
544
547
  const filtered = this.filterClaims(payload);
545
548
  return this.applyPrefix(filtered);
546
549
  }
550
+ /**
551
+ * Filter proxy JWT claims down to custom claims only
552
+ */
553
+ extractProxyClaims(claims) {
554
+ const entries = Object.entries(claims).filter(
555
+ ([key]) => !this.PROTECTED_CLAIMS.has(key)
556
+ );
557
+ return entries.length > 0 ? Object.fromEntries(entries) : null;
558
+ }
547
559
  /**
548
560
  * Apply prefix to claim names (if configured)
549
561
  */
@@ -1838,6 +1850,19 @@ var OAuthProxy = class {
1838
1850
  await this.stateStore.saveTransaction(approvedTransaction);
1839
1851
  return this.redirectToUpstream(approvedTransaction);
1840
1852
  }
1853
+ /**
1854
+ * Load custom claims from a FastMCP JWT
1855
+ */
1856
+ async loadTokenClaims(fastmcpToken) {
1857
+ if (!this.jwtIssuer || !this.claimsExtractor || !await this.loadUpstreamTokens(fastmcpToken)) {
1858
+ return null;
1859
+ }
1860
+ const result = await this.jwtIssuer.verify(fastmcpToken);
1861
+ if (!result.valid || !result.claims) {
1862
+ return null;
1863
+ }
1864
+ return this.claimsExtractor.extractProxyClaims(result.claims);
1865
+ }
1841
1866
  /**
1842
1867
  * Load upstream tokens from a FastMCP JWT
1843
1868
  */
@@ -2121,6 +2146,7 @@ var OAuthProxy = class {
2121
2146
  throw new OAuthProxyError(errorCode, errorDescription);
2122
2147
  }
2123
2148
  const tokens = await this.parseTokenResponse(tokenResponse);
2149
+ await this.verifyUpstreamAccessToken(tokens.access_token, "access_denied");
2124
2150
  return {
2125
2151
  accessToken: tokens.access_token,
2126
2152
  expiresIn: tokens.expires_in ?? 0,
@@ -2312,6 +2338,7 @@ var OAuthProxy = class {
2312
2338
  throw new OAuthProxyError(errorCode, errorDescription);
2313
2339
  }
2314
2340
  const tokens = await this.parseTokenResponse(tokenResponse);
2341
+ await this.verifyUpstreamAccessToken(tokens.access_token, "invalid_grant");
2315
2342
  await this.savePassthroughRefreshBinding(
2316
2343
  tokens.refresh_token || request.refresh_token,
2317
2344
  {
@@ -2790,6 +2817,7 @@ var OAuthProxy = class {
2790
2817
  throw new OAuthProxyError(errorCode, errorDescription);
2791
2818
  }
2792
2819
  const tokens = await this.parseTokenResponse(tokenResponse);
2820
+ await this.verifyUpstreamAccessToken(tokens.access_token, "invalid_grant");
2793
2821
  return {
2794
2822
  accessToken: tokens.access_token,
2795
2823
  expiresIn: tokens.expires_in ?? 0,
@@ -2955,6 +2983,23 @@ var OAuthProxy = class {
2955
2983
  (pattern) => this.matchesPattern(uri, pattern, parsed)
2956
2984
  );
2957
2985
  }
2986
+ /**
2987
+ * Run the configured `tokenVerifier` over an access token the upstream has
2988
+ * just issued, before it is stored or handed to a client.
2989
+ *
2990
+ * RFC 6749 names the refusal differently at each endpoint: `access_denied`
2991
+ * for an authorization response (§4.1.2.1), `invalid_grant` for a token
2992
+ * response (§5.2).
2993
+ */
2994
+ async verifyUpstreamAccessToken(accessToken, errorCode) {
2995
+ const result = await this.config.tokenVerifier?.verify(accessToken);
2996
+ if (result && !result.valid) {
2997
+ throw new OAuthProxyError(
2998
+ errorCode,
2999
+ "Upstream access token failed verification"
3000
+ );
3001
+ }
3002
+ }
2958
3003
  };
2959
3004
  var isPublicClient = (client) => client.source === "cimd" || client.tokenEndpointAuthMethod === "none";
2960
3005
  var describeUnauthenticatedClient = (client) => {
@@ -3076,7 +3121,8 @@ var AuthProvider = class {
3076
3121
  if (!upstreamTokens) {
3077
3122
  return void 0;
3078
3123
  }
3079
- return this.createSession(upstreamTokens);
3124
+ const claims = await this.proxy.loadTokenClaims(token) ?? void 0;
3125
+ return this.createSession(upstreamTokens, claims);
3080
3126
  }
3081
3127
  /**
3082
3128
  * Get the OAuth configuration object for FastMCP ServerOptions.
@@ -3103,10 +3149,11 @@ var AuthProvider = class {
3103
3149
  * Create a session object from upstream tokens.
3104
3150
  * Override in subclasses to add provider-specific session data.
3105
3151
  */
3106
- createSession(upstreamTokens) {
3152
+ createSession(upstreamTokens, claims) {
3107
3153
  const issuedAt = new Date(upstreamTokens.issuedAt).getTime() || Date.now();
3108
3154
  return {
3109
3155
  accessToken: upstreamTokens.accessToken,
3156
+ ...claims && Object.keys(claims).length > 0 ? { claims } : {},
3110
3157
  expiresAt: upstreamTokens.expiresIn ? Math.floor(issuedAt / 1e3) + upstreamTokens.expiresIn : void 0,
3111
3158
  idToken: upstreamTokens.idToken,
3112
3159
  refreshToken: upstreamTokens.refreshToken,
@@ -3688,4 +3735,4 @@ export {
3688
3735
  DiskStore,
3689
3736
  JWKSVerifier
3690
3737
  };
3691
- //# sourceMappingURL=chunk-XPTUOWUT.js.map
3738
+ //# sourceMappingURL=chunk-P4ZFER5I.js.map