fix(core): allow additional JSON Schema properties in elicitInput requestedSchema (#1768)
Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
This commit is contained in:
parent
0021561942
commit
866c08d364
3 changed files with 40 additions and 5 deletions
5
.changeset/zod-json-schema-compat.md
Normal file
5
.changeset/zod-json-schema-compat.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@modelcontextprotocol/core': patch
|
||||
---
|
||||
|
||||
Allow additional JSON Schema properties in elicitInput's requestedSchema type by adding .catchall(z.unknown()), matching the pattern used by inputSchema. This fixes type incompatibility when using Zod v4's .toJSONSchema() output which includes extra properties like $schema and additionalProperties.
|
||||
|
|
@ -1861,11 +1861,13 @@ 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({
|
||||
type: z.literal('object'),
|
||||
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
|
||||
required: z.array(z.string()).optional()
|
||||
})
|
||||
.catchall(z.unknown())
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
CreateMessageRequestSchema,
|
||||
CreateMessageResultSchema,
|
||||
CreateMessageResultWithToolsSchema,
|
||||
ElicitRequestFormParamsSchema,
|
||||
LATEST_PROTOCOL_VERSION,
|
||||
PromptMessageSchema,
|
||||
ResourceLinkSchema,
|
||||
|
|
@ -983,4 +984,31 @@ describe('Types', () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('ElicitRequestFormParamsSchema', () => {
|
||||
test('accepts requestedSchema with extra JSON Schema metadata keys', () => {
|
||||
// Mirrors what z.toJSONSchema() emits — includes $schema, additionalProperties, etc.
|
||||
// See https://github.com/modelcontextprotocol/typescript-sdk/issues/1362
|
||||
const params = {
|
||||
message: 'Please provide your name',
|
||||
requestedSchema: {
|
||||
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string' }
|
||||
},
|
||||
required: ['name'],
|
||||
additionalProperties: false
|
||||
}
|
||||
};
|
||||
|
||||
const result = ElicitRequestFormParamsSchema.safeParse(params);
|
||||
expect(result.success).toBe(true);
|
||||
if (result.success) {
|
||||
expect(result.data.requestedSchema.type).toBe('object');
|
||||
expect(result.data.requestedSchema.$schema).toBe('https://json-schema.org/draft/2020-12/schema');
|
||||
expect(result.data.requestedSchema.additionalProperties).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue