diff --git a/.changeset/widen-requested-schema-types.md b/.changeset/widen-requested-schema-types.md new file mode 100644 index 000000000..294adb04b --- /dev/null +++ b/.changeset/widen-requested-schema-types.md @@ -0,0 +1,5 @@ +--- +"@modelcontextprotocol/core": patch +--- + +fix: widen requestedSchema type to accept additional JSON Schema fields diff --git a/packages/core/src/types/types.ts b/packages/core/src/types/types.ts index 070ff0279..72b5ea2fc 100644 --- a/packages/core/src/types/types.ts +++ b/packages/core/src/types/types.ts @@ -1993,11 +1993,14 @@ export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.ex * A restricted subset of JSON Schema. * Only top-level properties are allowed, without nesting. */ - requestedSchema: z.object({ - type: z.literal('object'), - properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema), - required: z.array(z.string()).optional() - }) + requestedSchema: z + .object({ + $schema: z.string().optional(), + type: z.literal('object'), + properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema), + required: z.array(z.string()).optional() + }) + .passthrough() }); /** diff --git a/packages/core/test/spec.types.test.ts b/packages/core/test/spec.types.test.ts index 8ec29b096..c73b42a7a 100644 --- a/packages/core/test/spec.types.test.ts +++ b/packages/core/test/spec.types.test.ts @@ -53,6 +53,12 @@ type MakeUnknownsNotOptional = } : T; +// Targeted fix: in spec, requestedSchema needs index signature to match SDK's .passthrough() +// which allows additional JSON Schema fields like `additionalProperties` from Zod's .toJSONSchema() +type FixSpecRequestedSchema = T extends { requestedSchema: infer R } + ? Omit & { requestedSchema: R & { [x: string]: unknown } } + : T; + // Targeted fix: in spec, treat ClientCapabilities.elicitation?: object as Record type FixSpecClientCapabilities = T extends { elicitation?: object } ? Omit & { elicitation?: Record } @@ -160,11 +166,14 @@ const sdkTypeChecks = { sdk = spec; spec = sdk; }, - ElicitRequestParams: (sdk: SDKTypes.ElicitRequestParams, spec: SpecTypes.ElicitRequestParams) => { + ElicitRequestParams: ( + sdk: SDKTypes.ElicitRequestParams, + spec: FixSpecRequestedSchema | SpecTypes.ElicitRequestURLParams + ) => { sdk = spec; spec = sdk; }, - ElicitRequestFormParams: (sdk: SDKTypes.ElicitRequestFormParams, spec: SpecTypes.ElicitRequestFormParams) => { + ElicitRequestFormParams: (sdk: SDKTypes.ElicitRequestFormParams, spec: FixSpecRequestedSchema) => { sdk = spec; spec = sdk; },